Browse Source

updated Config/Aauth, UserModel, LoginTest & UserTest

v3-dev
REJack 6 years ago
parent
commit
f5ea2a21ea
No known key found for this signature in database
GPG Key ID: 4A44B48700429F46
  1. 4
      application/Config/Aauth.php
  2. 4
      application/Models/Aauth/UserModel.php
  3. 2
      tests/Aauth/Libraries/Aauth/LoginTest.php
  4. 17
      tests/Aauth/Libraries/Aauth/UserTest.php

4
application/Config/Aauth.php

@ -72,10 +72,10 @@ class Aauth extends BaseConfig
|
| Additional valid chars for username. Non alphanumeric characters that are
| allowed by default
| (default: '[a-zA-Z0-9]{3,}')
| (default: '[a-zA-Z0-9]+')
*/
public $userVerification = false;
public $userRegexPattern = '[a-zA-Z0-9]{3,}\s';
public $userRegexPattern = '[a-zA-Z0-9]+';
/*
|--------------------------------------------------------------------------

4
application/Models/Aauth/UserModel.php

@ -95,7 +95,7 @@ class UserModel extends Model
$this->validationRules['email'] = 'required|if_exist|valid_email|is_unique[' . $this->table . '.email,id,{id}]';
$this->validationRules['password'] = 'required|if_exist|min_length[' . $this->config->passwordMin . ']|max_length[' . $this->config->passwordMax . ']';
$this->validationRules['username'] = 'if_exist|is_unique[' . $this->table . '.username,id,{id}]|regex_match[/' . $this->config->userRegexPattern . '/]';
$this->validationRules['username'] = 'if_exist|is_unique[' . $this->table . '.username,id,{id}]|min_length[3]|regex_match[/' . $this->config->userRegexPattern . '/]';
$this->validationMessages = [
'email' => [
@ -114,7 +114,7 @@ class UserModel extends Model
if ($this->config->loginUseUsername)
{
$this->validationRules['username'] = 'required|if_exist|is_unique[' . $this->table . '.username,id,{id}]|regex_match[/' . $this->config->userRegexPattern . '/]';
$this->validationRules['username'] = 'required|if_exist|is_unique[' . $this->table . '.username,id,{id}]|min_length[3]|regex_match[/' . $this->config->userRegexPattern . '/]';
$this->validationMessages['username']['required'] = lang('Aauth.requiredUsername');
}

2
tests/Aauth/Libraries/Aauth/LoginTest.php

@ -101,6 +101,7 @@ class LoginTest extends CIDatabaseTestCase
$userVariableModel = new UserVariableModel();
$userVariableModel->save(1, 'verification_code', '12345678', true);
$this->library->clearErrors();
$this->assertFalse($this->library->login('admin@example.com', 'password123456'));
$this->assertEquals(lang('Aauth.notVerified'), $this->library->getErrorsArray()[0]);
@ -109,7 +110,6 @@ class LoginTest extends CIDatabaseTestCase
$this->assertFalse($this->library->login('admin@example.com', 'password123456'));
$this->assertEquals(lang('Aauth.invalidUserBanned'), $this->library->getErrorsArray()[0]);
$this->library->clearErrors();
$this->assertFalse($this->library->login('admin@example.com', 'password1234567'));
$this->assertEquals(lang('Aauth.loginFailedAll'), $this->library->getErrorsArray()[0]);

17
tests/Aauth/Libraries/Aauth/UserTest.php

@ -65,13 +65,13 @@ class UserTest extends CIDatabaseTestCase
public function testUpdateUser()
{
$this->seeInDatabase($this->config->dbTableUserVariables, [
$this->seeInDatabase($this->config->dbTableUsers, [
'id' => 2,
'email' => 'user@example.com',
'username' => 'user',
]);
$this->library->updateUser(2, 'user1@example.com', 'password987654', 'user1');
$this->seeInDatabase($this->config->dbTableUserVariables, [
$this->seeInDatabase($this->config->dbTableUsers, [
'id' => 2,
'email' => 'user1@example.com',
'username' => 'user1',
@ -113,9 +113,9 @@ class UserTest extends CIDatabaseTestCase
public function testDeleteUser()
{
$this->seeNumRecords(2, $this->config->dbTableUsers);
$this->seeNumRecords(2, $this->config->dbTableUsers, []);
$this->library->deleteUser(2);
$this->seeNumRecords(1, $this->config->dbTableUsers);
$this->seeNumRecords(1, $this->config->dbTableUsers, []);
$this->assertFalse($this->library->deleteUser(99));
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]);
@ -143,7 +143,7 @@ class UserTest extends CIDatabaseTestCase
$session = $this->getInstance();
$this->library = new Aauth(NULL, $session);
$session->set('user', [
'id' => 1,
'id' => 1,
]);
$userIdNone = $this->library->getUser();
$this->assertEquals('admin', $userIdNone['username']);
@ -163,13 +163,12 @@ class UserTest extends CIDatabaseTestCase
$session = $this->getInstance();
$this->library = new Aauth(NULL, $session);
$session->set('user', [
'id' => 1,
'id' => 1,
]);
$userIdNone = $this->library->getUserId();
$this->assertEquals('1', $userIdNone);
$this->assertFalse($this->library->getUserId('none@example.com'));
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]);
}
public function testBanUser()
@ -226,11 +225,11 @@ class UserTest extends CIDatabaseTestCase
public function testIsBanned()
{
$this->assertFalse($this->library->isBanned(1));
$this->library->banUser(1);
$this->assertTrue($this->library->isBanned(1));
$this->assertFalse($this->library->isBanned(1));
$this->assertTrue($this->library->isBanned(99));
}
}

Loading…
Cancel
Save