Skip to content

Commit

Permalink
move the auth_none class to the test framework, only enable it for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmunro committed May 25, 2017
1 parent 3e551e1 commit 09658c8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
26 changes: 0 additions & 26 deletions lib/auth.php
Expand Up @@ -44,32 +44,6 @@ abstract public function check_credentials($user, $pass);
public function save_auth_detail($session) {}
}

/**
* Used for testing
*/
class Hm_Auth_None extends Hm_Auth {

/**
* This is the method new auth mechs need to override.
* @param string $user username
* @param string $pass password
* @return bool true if the user is authenticated, false otherwise
*/
public function check_credentials($user, $pass) {
return true;
}

/*
* Create a new user
* @param string $user username
* @param string $pass password
* @return bool
*/
public function create($user, $pass) {
return true;
}
}

/**
* Authenticate against an included DB
*/
Expand Down
11 changes: 8 additions & 3 deletions lib/session_base.php
Expand Up @@ -332,19 +332,24 @@ public function secure_cookie($request, $name, $value, $lifetime=false, $path=''
*/
function setup_auth($config) {
$auth_type = $config->get('auth_type', false);
$auth_class = '';
if ($auth_type == 'dynamic' && !in_array('dynamic_login', $config->get_modules(), true)) {
Hm_Functions::cease('Invalid auth configuration');
}
if ($auth_type && $auth_type != 'dynamic' && $auth_type != 'custom') {
if ($auth_type && in_array($auth_type, array('DB', 'LDAP', 'IMAP', 'POP3'), true)) {
$auth_class = sprintf('Hm_Auth_%s', $auth_type);
}
elseif ($auth_type == 'custom') {
$auth_class = 'Custom_Auth';
}
if (!$auth_class) {
Hm_Functions::cease('Invalid auth configuration');
}
else {
$auth_class = 'Hm_Auth_None';
return $auth_class;
}
return $auth_class;
/* this special case is for unit testing */
return 'Hm_Auth_None';
}

/**
Expand Down
22 changes: 22 additions & 0 deletions tests/phpunit/stubs.php
Expand Up @@ -4,6 +4,28 @@ class Test_Uid_Cache {
use Hm_Uid_Cache;
}

class Hm_Auth_None extends Hm_Auth {
/**
* This is the method new auth mechs need to override.
* @param string $user username
* @param string $pass password
* @return bool true if the user is authenticated, false otherwise
*/
public function check_credentials($user, $pass) {
return true;
}

/*
* Create a new user
* @param string $user username
* @param string $pass password
* @return bool
*/
public function create($user, $pass) {
return true;
}
}

class Hm_Handler_test_mod extends Hm_Handler_Module {
public function process() {
$this->out('test', 'foo');
Expand Down

0 comments on commit 09658c8

Please sign in to comment.