12 changed files with 132 additions and 320 deletions
@ -40,45 +40,32 @@ class UserModelTest extends CIDatabaseTestCase
|
||||
$this->assertTrue(strtotime("-5 seconds") < strtotime($user['last_activity']) && strtotime("+5 seconds") > strtotime($user['last_activity'])); |
||||
} |
||||
|
||||
public function testUpdateBannedTrue() |
||||
public function testUpdateBanned() |
||||
{ |
||||
$this->assertFalse($this->model->isBanned(1)); |
||||
|
||||
$this->model->updateBanned(1, TRUE); |
||||
$this->assertTrue($this->model->isBanned(1)); |
||||
} |
||||
|
||||
public function testUpdateBannedFalse() |
||||
{ |
||||
$this->model->updateBanned(1, FALSE); |
||||
$this->assertFalse($this->model->isBanned(1)); |
||||
} |
||||
|
||||
public function testExistsByIdTrue() |
||||
public function testExistsById() |
||||
{ |
||||
$this->assertTrue($this->model->existsById(1)); |
||||
} |
||||
|
||||
public function testExistsByIdFalse() |
||||
{ |
||||
$this->assertFalse($this->model->existsById(0)); |
||||
} |
||||
|
||||
public function testExistsByEmailTrue() |
||||
public function testExistsByEmail() |
||||
{ |
||||
$this->assertTrue($this->model->existsByEmail("[email protected]")); |
||||
} |
||||
|
||||
public function testExistsByEmailFalse() |
||||
{ |
||||
$this->assertFalse($this->model->existsByEmail("")); |
||||
} |
||||
|
||||
public function testExistsByUsernameTrue() |
||||
public function testExistsByUsername() |
||||
{ |
||||
$this->assertTrue($this->model->existsByUsername("admin")); |
||||
} |
||||
|
||||
public function testExistsByUsernameFalse() |
||||
{ |
||||
$this->assertFalse($this->model->existsByUsername("")); |
||||
} |
||||
|
||||
@ -88,10 +75,7 @@ class UserModelTest extends CIDatabaseTestCase
|
||||
$this->model->update(1, ['id' => 1, 'password' => 'password123456']); |
||||
$userNew = $this->model->asArray()->find(1); |
||||
$this->assertTrue($userOld['password'] != $userNew['password'] && $userNew['password'] != 'password123456'); |
||||
} |
||||
|
||||
public function testHashPasswordNotSet() |
||||
{ |
||||
$userOld = $this->model->asArray()->find(1); |
||||
$this->model->update(1, ['id' => 1, 'username' => 'admin']); |
||||
$userNew = $this->model->asArray()->find(1); |
||||
|
@ -25,25 +25,25 @@ class LoginTest extends CIDatabaseTestCase
|
||||
|
||||
protected $namespace = 'App'; |
||||
|
||||
public function setUp() |
||||
{ |
||||
parent::setUp(); |
||||
public function setUp() |
||||
{ |
||||
parent::setUp(); |
||||
|
||||
Services::injectMock('response', new MockResponse(new App())); |
||||
$this->response = service('response'); |
||||
$this->library = new Aauth(null, true); |
||||
$_COOKIE = []; |
||||
$_SESSION = []; |
||||
} |
||||
Services::injectMock('response', new MockResponse(new App())); |
||||
$this->response = service('response'); |
||||
$this->library = new Aauth(null, true); |
||||
$_COOKIE = []; |
||||
$_SESSION = []; |
||||
} |
||||
|
||||
public function tearDown() |
||||
{ |
||||
public function tearDown() |
||||
{ |
||||
|
||||
} |
||||
} |
||||
|
||||
protected function getInstance($options=[]) |
||||
{ |
||||
$defaults = [ |
||||
protected function getInstance($options=[]) |
||||
{ |
||||
$defaults = [ |
||||
'sessionDriver' => 'CodeIgniter\Session\Handlers\FileHandler', |
||||
'sessionCookieName' => 'ci_session', |
||||
'sessionExpiration' => 7200, |
||||
@ -55,145 +55,93 @@ class LoginTest extends CIDatabaseTestCase
|
||||
'cookiePrefix' => '', |
||||
'cookiePath' => '/', |
||||
'cookieSecure' => false, |
||||
]; |
||||
]; |
||||
|
||||
$config = (object)$defaults; |
||||
$config = (object)$defaults; |
||||
|
||||
$session = new MockSession(new FileHandler($config, Services::request()->getIPAddress()), $config); |
||||
$session->setLogger(new TestLogger(new Logger())); |
||||
$session->start(); |
||||
$session = new MockSession(new FileHandler($config, Services::request()->getIPAddress()), $config); |
||||
$session->setLogger(new TestLogger(new Logger())); |
||||
$session->start(); |
||||
|
||||
return $session; |
||||
} |
||||
return $session; |
||||
} |
||||
|
||||
//-------------------------------------------------------------------- |
||||
|
||||
public function testLoginEmailTrue() |
||||
{ |
||||
$session = $this->getInstance(); |
||||
$this->library = new Aauth(null, $session); |
||||
$this->assertTrue($this->library->login('[email protected]', 'password123456')); |
||||
} |
||||
|
||||
public function testLoginFalseEmailFailedEmail() |
||||
{ |
||||
$session = $this->getInstance(); |
||||
$this->library = new Aauth(null, $session); |
||||
$this->assertFalse($this->library->login('adminaexample.com', 'password123456')); |
||||
$this->assertEquals(lang('Aauth.loginFailedEmail'), $this->library->getErrorsArray()[0]); |
||||
} |
||||
|
||||
public function testLoginFalseEmailFailedPassword() |
||||
{ |
||||
$session = $this->getInstance(); |
||||
$this->library = new Aauth(null, $session); |
||||
$this->assertFalse($this->library->login('[email protected]', 'passwor')); |
||||
$this->assertEquals(lang('Aauth.loginFailedEmail'), $this->library->getErrorsArray()[0]); |
||||
} |
||||
|
||||
public function testLoginFalseEmailNotFound() |
||||
{ |
||||
$session = $this->getInstance(); |
||||
$this->library = new Aauth(null, $session); |
||||
$this->assertFalse($this->library->login('[email protected]', 'password123456')); |
||||
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]); |
||||
} |
||||
|
||||
public function testLoginUsernameTrue() |
||||
{ |
||||
$session = $this->getInstance(); |
||||
$config = new AauthConfig(); |
||||
$config->loginUseUsername = true; |
||||
$this->library = new Aauth($config, $session); |
||||
$this->assertTrue($this->library->login('admin', 'password123456')); |
||||
} |
||||
|
||||
public function testLoginFalseUsernameFailedPassword() |
||||
{ |
||||
$session = $this->getInstance(); |
||||
$config = new AauthConfig(); |
||||
$config->loginUseUsername = true; |
||||
$this->library = new Aauth($config, $session); |
||||
$this->assertFalse($this->library->login('admin', 'passwor')); |
||||
$this->assertEquals(lang('Aauth.loginFailedUsername'), $this->library->getErrorsArray()[0]); |
||||
} |
||||
|
||||
public function testLoginFalseUsernameNotFound() |
||||
{ |
||||
$session = $this->getInstance(); |
||||
$config = new AauthConfig(); |
||||
$config->loginUseUsername = true; |
||||
$this->library = new Aauth($config, $session); |
||||
$this->assertFalse($this->library->login('user99', 'password123456')); |
||||
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]); |
||||
$config->loginUseUsername = false; |
||||
} |
||||
|
||||
public function testLoginFalseNotVerified() |
||||
{ |
||||
$session = $this->getInstance(); |
||||
$this->library = new Aauth(null, $session); |
||||
$userVariableModel = new UserVariableModel(); |
||||
$userVariableModel->save(1, 'verification_code', '12345678', true); |
||||
$this->assertFalse($this->library->login('[email protected]', 'password123456')); |
||||
$this->assertEquals(lang('Aauth.notVerified'), $this->library->getErrorsArray()[0]); |
||||
} |
||||
|
||||
public function testLoginFalseBanned() |
||||
{ |
||||
$session = $this->getInstance(); |
||||
$this->library = new Aauth(null, $session); |
||||
$this->library->banUser(1); |
||||
$this->assertFalse($this->library->login('[email protected]', 'password123456')); |
||||
$this->assertEquals(lang('Aauth.invalidUserBanned'), $this->library->getErrorsArray()[0]); |
||||
} |
||||
|
||||
public function testLoginFalse() |
||||
{ |
||||
$session = $this->getInstance(); |
||||
$this->library = new Aauth(null, $session); |
||||
$this->assertFalse($this->library->login('[email protected]', 'password1234567')); |
||||
$this->assertEquals(lang('Aauth.loginFailedAll'), $this->library->getErrorsArray()[0]); |
||||
} |
||||
|
||||
public function testLoginFalseLoginAttemptsExceeded() |
||||
{ |
||||
$session = $this->getInstance(); |
||||
$this->library = new Aauth(null, $session); |
||||
$this->library->login('[email protected]', 'password123456'); |
||||
$this->library->login('[email protected]', 'password123456'); |
||||
$this->library->login('[email protected]', 'password123456'); |
||||
$this->library->login('[email protected]', 'password123456'); |
||||
$this->library->login('[email protected]', 'password123456'); |
||||
$this->library->login('[email protected]', 'password123456'); |
||||
$this->library->login('[email protected]', 'password123456'); |
||||
$this->library->login('[email protected]', 'password123456'); |
||||
$this->library->login('[email protected]', 'password123456'); |
||||
$this->library->clearErrors(); |
||||
$this->assertFalse($this->library->login('[email protected]', 'password123456')); |
||||
$this->assertEquals(lang('Aauth.loginAttemptsExceeded'), $this->library->getErrorsArray()[0]); |
||||
} |
||||
public function testLogin() |
||||
{ |
||||
$session = $this->getInstance(); |
||||
$config = new AauthConfig(); |
||||
$config->loginUseUsername = true; |
||||
|
||||
$this->library = new Aauth($config, $session); |
||||
$this->assertTrue($this->library->login('admin', 'password123456')); |
||||
|
||||
$this->assertFalse($this->library->login('admin', 'passwor')); |
||||
$this->assertEquals(lang('Aauth.loginFailedUsername'), $this->library->getErrorsArray()[0]); |
||||
|
||||
$this->library->clearErrors(); |
||||
$this->assertFalse($this->library->login('user99', 'password123456')); |
||||
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]); |
||||
// $config->loginUseUsername = false; |
||||
|
||||
$this->library = new Aauth(null, $session); |
||||
$this->assertTrue($this->library->login('[email protected]', 'password123456')); |
||||
|
||||
$this->assertFalse($this->library->login('adminaexample.com', 'password123456')); |
||||
$this->assertEquals(lang('Aauth.loginFailedEmail'), $this->library->getErrorsArray()[0]); |
||||
|
||||
$this->library->clearErrors(); |
||||
$this->assertFalse($this->library->login('[email protected]', 'passwor')); |
||||
$this->assertEquals(lang('Aauth.loginFailedEmail'), $this->library->getErrorsArray()[0]); |
||||
|
||||
$this->library->clearErrors(); |
||||
$this->assertFalse($this->library->login('[email protected]', 'password123456')); |
||||
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]); |
||||
|
||||
$userVariableModel = new UserVariableModel(); |
||||
$userVariableModel->save(1, 'verification_code', '12345678', true); |
||||
$this->assertFalse($this->library->login('[email protected]', 'password123456')); |
||||
$this->assertEquals(lang('Aauth.notVerified'), $this->library->getErrorsArray()[0]); |
||||
|
||||
$this->library->banUser(1); |
||||
$this->library->clearErrors(); |
||||
$this->assertFalse($this->library->login('[email protected]', 'password123456')); |
||||
$this->assertEquals(lang('Aauth.invalidUserBanned'), $this->library->getErrorsArray()[0]); |
||||
|
||||
|
||||
$this->library->clearErrors(); |
||||
$this->assertFalse($this->library->login('[email protected]', 'password1234567')); |
||||
$this->assertEquals(lang('Aauth.loginFailedAll'), $this->library->getErrorsArray()[0]); |
||||
|
||||
$this->library->login('[email protected]', 'password123456'); |
||||
$this->library->login('[email protected]', 'password123456'); |
||||
$this->library->login('[email protected]', 'password123456'); |
||||
$this->library->clearErrors(); |
||||
$this->assertFalse($this->library->login('[email protected]', 'password123456')); |
||||
$this->assertEquals(lang('Aauth.loginAttemptsExceeded'), $this->library->getErrorsArray()[0]); |
||||
} |
||||
|
||||
public function testIsLoggedIn() |
||||
{ |
||||
$session = $this->getInstance(); |
||||
$this->library = new Aauth(null, $session); |
||||
$session = $this->getInstance(); |
||||
$this->library = new Aauth(null, $session); |
||||
$session->set('user', [ |
||||
'loggedIn' => true, |
||||
]); |
||||
$this->assertTrue($this->library->isLoggedIn()); |
||||
'loggedIn' => true, |
||||
]); |
||||
$this->assertTrue($this->library->isLoggedIn()); |
||||
} |
||||
|
||||
public function testLogout() |
||||
{ |
||||
$session = $this->getInstance(); |
||||
$this->library = new Aauth(null, $session); |
||||
$session = $this->getInstance(); |
||||
$this->library = new Aauth(null, $session); |
||||
$session->set('user', [ |
||||
'loggedIn' => true, |
||||
]); |
||||
$this->assertTrue($this->library->isLoggedIn()); |
||||
$this->library->logout(); |
||||
$this->library = new Aauth(null, $session); |
||||
$this->assertFalse($this->library->isLoggedIn()); |
||||
'loggedIn' => true, |
||||
]); |
||||
$this->assertTrue($this->library->isLoggedIn()); |
||||
$this->library->logout(); |
||||
$this->library = new Aauth(null, $session); |
||||
$this->assertFalse($this->library->isLoggedIn()); |
||||
} |
||||
} |
||||
|
@ -63,66 +63,50 @@ class UserTest extends CIDatabaseTestCase
|
||||
|
||||
//-------------------------------------------------------------------- |
||||
|
||||
public function testUpdateUserTrue() |
||||
public function testUpdateUser() |
||||
{ |
||||
$this->seeInDatabase($this->config->dbTableUserVariables, [ |
||||
'user_id' => 2, |
||||
'id' => 2, |
||||
'email' => '[email protected]', |
||||
'username' => 'user', |
||||
]); |
||||
$this->library->updateUser(2, '[email protected]', 'password987654', 'user1'); |
||||
$this->seeInDatabase($this->config->dbTableUserVariables, [ |
||||
'user_id' => 2, |
||||
'id' => 2, |
||||
'email' => '[email protected]', |
||||
'username' => 'user1', |
||||
]); |
||||
$this->assertEquals(lang('Aauth.infoUpdateSuccess'), $this->library->getInfosArray()[0]); |
||||
} |
||||
|
||||
public function testUpdateUserFalseEmailExists() |
||||
{ |
||||
$this->library->clearInfos(); |
||||
$this->assertFalse($this->library->updateUser(2, '[email protected]', null, null)); |
||||
$this->assertEquals(lang('Aauth.existsAlreadyEmail'), $this->library->getErrorsArray()[0]); |
||||
} |
||||
|
||||
public function testUpdateUserFalseEmailInvalid() |
||||
{ |
||||
$this->library->clearErrors(); |
||||
$this->assertFalse($this->library->updateUser(2, 'adminexample.com', null, null)); |
||||
$this->assertEquals(lang('Aauth.invalidEmail'), $this->library->getErrorsArray()[0]); |
||||
} |
||||
|
||||
public function testUpdateUserFalsePasswordMin() |
||||
{ |
||||
$this->library->clearErrors(); |
||||
$this->assertFalse($this->library->updateUser(2, null, 'pass', null)); |
||||
$this->assertEquals(lang('Aauth.invalidPassword'), $this->library->getErrorsArray()[0]); |
||||
} |
||||
|
||||
public function testUpdateUserFalsePasswordMax() |
||||
{ |
||||
$this->library->clearErrors(); |
||||
$this->assertFalse($this->library->updateUser(2, null, 'password12345678901011121314151617', null)); |
||||
$this->assertEquals(lang('Aauth.invalidPassword'), $this->library->getErrorsArray()[0]); |
||||
} |
||||
|
||||
public function testUpdateUserFalseUsernameExists() |
||||
{ |
||||
$this->library->clearErrors(); |
||||
$this->assertFalse($this->library->updateUser(2, null, null, 'admin')); |
||||
$this->assertEquals(lang('Aauth.existsAlreadyUsername'), $this->library->getErrorsArray()[0]); |
||||
} |
||||
|
||||
public function testUpdateUserFalseUsernameInvalid() |
||||
{ |
||||
$this->library->clearErrors(); |
||||
$this->assertFalse($this->library->updateUser(2, null, null, 'user+')); |
||||
$this->assertEquals(lang('Aauth.invalidUsername'), $this->library->getErrorsArray()[0]); |
||||
} |
||||
|
||||
public function testUpdateUserFalseEmpty() |
||||
{ |
||||
$this->library->clearErrors(); |
||||
$this->assertFalse($this->library->updateUser(2)); |
||||
$this->assertCount(0, $this->library->getErrorsArray()); |
||||
} |
||||
|
||||
public function testUpdateUserFalseUserNotFound() |
||||
{ |
||||
$this->library->clearErrors(); |
||||
$this->assertFalse($this->library->updateUser(99)); |
||||
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]); |
||||
} |
||||
@ -132,10 +116,7 @@ class UserTest extends CIDatabaseTestCase
|
||||
$this->seeNumRecords(2, $this->config->dbTableUsers); |
||||
$this->library->deleteUser(2); |
||||
$this->seeNumRecords(1, $this->config->dbTableUsers); |
||||
} |
||||
|
||||
public function testDeleteUserFalseUserNotFound() |
||||
{ |
||||
$this->assertFalse($this->library->deleteUser(99)); |
||||
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]); |
||||
} |
||||
@ -146,25 +127,19 @@ class UserTest extends CIDatabaseTestCase
|
||||
$this->assertCount(2, $users); |
||||
$this->assertEquals('admin', $users[0]['username']); |
||||
$this->assertEquals('user', $users[1]['username']); |
||||
} |
||||
|
||||
public function testListUsersOrderBy() |
||||
{ |
||||
$usersOrderBy = $this->library->listUsers(0, 0, null, 'id DESC'); |
||||
$this->assertEquals('user', $usersOrderBy[0]['username']); |
||||
$this->assertEquals('admin', $usersOrderBy[1]['username']); |
||||
} |
||||
|
||||
public function testGetUserByUserId() |
||||
public function testGetUser() |
||||
{ |
||||
$user = $this->library->getUser(1); |
||||
$this->assertEquals('1', $user['id']); |
||||
$this->assertEquals('admin', $user['username']); |
||||
$this->assertEquals('[email protected]', $user['email']); |
||||
} |
||||
|
||||
public function testGetUserBySession() |
||||
{ |
||||
$session = $this->getInstance(); |
||||
$this->library = new Aauth(NULL, $session); |
||||
$session->set('user', [ |
||||
@ -172,28 +147,19 @@ class UserTest extends CIDatabaseTestCase
|
||||
]); |
||||
$userIdNone = $this->library->getUser(); |
||||
$this->assertEquals('admin', $userIdNone['username']); |
||||
} |
||||
|
||||
public function testGetUserWithVariables() |
||||
{ |
||||
$userVar = $this->library->getUser(1, true); |
||||
$this->assertInternalType('array', $userVar['variables']); |
||||
} |
||||
|
||||
public function testGetUserFalseUserNotFound() |
||||
{ |
||||
$this->assertFalse($this->library->getUser(99)); |
||||
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]); |
||||
} |
||||
|
||||
public function testGetUserIdByEmail() |
||||
public function testGetUserId() |
||||
{ |
||||
$userIdEmail = $this->library->getUserId('[email protected]'); |
||||
$this->assertEquals('1', $userIdEmail); |
||||
} |
||||
|
||||
public function testGetUserIdBySession() |
||||
{ |
||||
$session = $this->getInstance(); |
||||
$this->library = new Aauth(NULL, $session); |
||||
$session->set('user', [ |
||||
@ -201,10 +167,7 @@ class UserTest extends CIDatabaseTestCase
|
||||
]); |
||||
$userIdNone = $this->library->getUserId(); |
||||
$this->assertEquals('1', $userIdNone); |
||||
} |
||||
|
||||
public function testGetUserIdFalseUserNotFound() |
||||
{ |
||||
$this->assertFalse($this->library->getUserId('[email protected]')); |
||||
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]); |
||||
} |
||||
@ -220,9 +183,7 @@ class UserTest extends CIDatabaseTestCase
|
||||
'id' => 1, |
||||
'banned' => 1, |
||||
]); |
||||
} |
||||
public function testBanUserFalseUserNotFound() |
||||
{ |
||||
|
||||
$this->assertFalse($this->library->banUser(99)); |
||||
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]); |
||||
} |
||||
@ -239,9 +200,7 @@ class UserTest extends CIDatabaseTestCase
|
||||
'id' => 1, |
||||
'banned' => 0, |
||||
]); |
||||
} |
||||
public function testUnbanUserFalseUserNotFound() |
||||
{ |
||||
|
||||
$this->assertFalse($this->library->unbanUser(99)); |
||||
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]); |
||||
} |
||||
@ -265,20 +224,13 @@ class UserTest extends CIDatabaseTestCase
|
||||
]); |
||||
} |
||||
|
||||
public function testIsBannedTrue() |
||||
public function testIsBanned() |
||||
{ |
||||
$this->library->banUser(1); |
||||
$this->assertTrue($this->library->isBanned(1)); |
||||
} |
||||
|
||||
public function testIsBannedFalse() |
||||
{ |
||||
$this->assertFalse($this->library->isBanned(1)); |
||||
} |
||||
|
||||
public function testIsBannedFalseUserNotFound() |
||||
{ |
||||
$this->assertFalse($this->library->isBanned(99)); |
||||
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]); |
||||
$this->assertTrue($this->library->isBanned(99)); |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue