@@ -41,6 +41,33 @@ public function providerInvalidCredentials()
41
41
];
42
42
}
43
43
44
+ /**
45
+ * @param array $username
46
+ * @dataProvider providerInvalidUsername
47
+ * @expectedException \ActiveCollab\Authentication\Exception\InvalidAuthenticationRequestException
48
+ * @expectedExceptionMessage Authentication request data not valid
49
+ */
50
+ public function testInvalidUsernameThrowsException ($ username )
51
+ {
52
+ $ local_authorizer = new LocalAuthorizer (new Repository (), true );
53
+
54
+ $ local_authorizer ->verifyCredentials ([
55
+ 'username ' => $ username ,
56
+ 'password ' => 'Easy to remember, Hard to guess ' ,
57
+ ]);
58
+ }
59
+
60
+ public function providerInvalidUsername ()
61
+ {
62
+ return [
63
+ ['username ' => null ],
64
+ ['username ' => '' ],
65
+ ['username ' => 'Invalid Username ' ],
66
+ ['username ' => 'Not a valid Username ' ],
67
+ ['username ' => 'not_a_username ' ],
68
+ ];
69
+ }
70
+
44
71
/**
45
72
* @expectedException \ActiveCollab\Authentication\Exception\UserNotFoundException
46
73
* @expectedExceptionMessage User not found
@@ -81,9 +108,20 @@ public function testUserCanNotAuthenticateThrowsException()
81
108
public function testUserIsAuthenticated ()
82
109
{
83
110
$ local_authorizer = new LocalAuthorizer (new Repository ([
84
- '[email protected] ' =>
new AuthenticatedUser (
1 ,
'[email protected] ' ,
'John ' ,
'password ' ,
true ),
111
+ '[email protected] ' =>
new AuthenticatedUser (
1 ,
'johndoe ' ,
'John ' ,
'password ' ,
true ),
85
112
]));
86
113
114
+ $ user = $ local_authorizer ->verifyCredentials (['username ' => 'johndoe ' , 'password ' => 'password ' ]);
115
+
116
+ $ this ->assertSame (1 , $ user ->getId ());
117
+ }
118
+
119
+ public function testUserWithEmailUsernameIsAuthenticated ()
120
+ {
121
+ $ local_authorizer = new LocalAuthorizer (new Repository ([
122
+ '[email protected] ' =>
new AuthenticatedUser (
1 ,
'[email protected] ' ,
'John ' ,
'password ' ,
true ),
123
+ ]), true );
124
+
87
125
$ user =
$ local_authorizer->
verifyCredentials ([
'username ' =>
'[email protected] ' ,
'password ' =>
'password ' ]);
88
126
89
127
$ this ->assertSame (1 , $ user ->getId ());
0 commit comments