|
8 | 8 |
|
9 | 9 | namespace ActiveCollab\Authentication\Test;
|
10 | 10 |
|
| 11 | +use ActiveCollab\Authentication\Authorizer\AuthorizerInterface; |
11 | 12 | use ActiveCollab\Authentication\Authorizer\LocalAuthorizer;
|
12 | 13 | use ActiveCollab\Authentication\Test\AuthenticatedUser\AuthenticatedUser;
|
13 | 14 | use ActiveCollab\Authentication\Test\AuthenticatedUser\Repository;
|
@@ -43,21 +44,48 @@ public function providerInvalidCredentials()
|
43 | 44 |
|
44 | 45 | /**
|
45 | 46 | * @param array $username
|
46 |
| - * @dataProvider providerInvalidUsername |
| 47 | + * @dataProvider providerInvalidAlphaNumUsername |
47 | 48 | * @expectedException \ActiveCollab\Authentication\Exception\InvalidAuthenticationRequestException
|
48 | 49 | * @expectedExceptionMessage Authentication request data not valid
|
49 | 50 | */
|
50 |
| - public function testInvalidUsernameThrowsException($username) |
| 51 | + public function testInvalidAlphaNumUsernameThrowsException($username) |
51 | 52 | {
|
52 |
| - $local_authorizer = new LocalAuthorizer(new Repository(), true); |
| 53 | + $local_authorizer = new LocalAuthorizer(new Repository(), AuthorizerInterface::USERNAME_FORMAT_ALPHANUM); |
53 | 54 |
|
54 | 55 | $local_authorizer->verifyCredentials([
|
55 | 56 | 'username' => $username,
|
56 | 57 | 'password' => 'Easy to remember, Hard to guess',
|
57 | 58 | ]);
|
58 | 59 | }
|
59 | 60 |
|
60 |
| - public function providerInvalidUsername() |
| 61 | + public function providerInvalidAlphaNumUsername() |
| 62 | + { |
| 63 | + return [ |
| 64 | + ['username' => null], |
| 65 | + ['username' => ''], |
| 66 | + ['username' => 'Invalid Username'], |
| 67 | + ['username' => 'not_a_username'], |
| 68 | + [ 'username' => '[email protected]'], |
| 69 | + ]; |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * @param array $username |
| 74 | + * @dataProvider providerInvalidEmailUsername |
| 75 | + * @expectedException \ActiveCollab\Authentication\Exception\InvalidAuthenticationRequestException |
| 76 | + * @expectedExceptionMessage Authentication request data not valid |
| 77 | + */ |
| 78 | + public function testInvalidEmailUsernameThrowsException($username) |
| 79 | + { |
| 80 | + $local_authorizer = new LocalAuthorizer(new Repository(), AuthorizerInterface::USERNAME_FORMAT_EMAIL); |
| 81 | + |
| 82 | + $local_authorizer->verifyCredentials([ |
| 83 | + 'username' => $username, |
| 84 | + 'password' => 'Easy to remember, Hard to guess', |
| 85 | + ]); |
| 86 | + } |
| 87 | + |
| 88 | + public function providerInvalidEmailUsername() |
61 | 89 | {
|
62 | 90 | return [
|
63 | 91 | ['username' => null],
|
@@ -116,11 +144,22 @@ public function testUserIsAuthenticated()
|
116 | 144 | $this->assertSame(1, $user->getId());
|
117 | 145 | }
|
118 | 146 |
|
| 147 | + public function testUserWithAlphanumUsernameIsAuthenticated() |
| 148 | + { |
| 149 | + $local_authorizer = new LocalAuthorizer(new Repository([ |
| 150 | + '[email protected]' => new AuthenticatedUser( 1, 'JohnDoe1983', 'John', 'password', true), |
| 151 | + ]), AuthorizerInterface::USERNAME_FORMAT_ALPHANUM); |
| 152 | + |
| 153 | + $user = $local_authorizer->verifyCredentials(['username' => 'JohnDoe1983', 'password' => 'password']); |
| 154 | + |
| 155 | + $this->assertSame(1, $user->getId()); |
| 156 | + } |
| 157 | + |
119 | 158 | public function testUserWithEmailUsernameIsAuthenticated()
|
120 | 159 | {
|
121 | 160 | $local_authorizer = new LocalAuthorizer(new Repository([
|
122 | 161 | '[email protected]' => new AuthenticatedUser( 1, '[email protected]', 'John', 'password', true),
|
123 |
| - ]), true); |
| 162 | + ]), AuthorizerInterface::USERNAME_FORMAT_EMAIL); |
124 | 163 |
|
125 | 164 | $user = $local_authorizer-> verifyCredentials([ 'username' => '[email protected]', 'password' => 'password']);
|
126 | 165 |
|
|
0 commit comments