@@ -85,6 +85,10 @@ public function testGenerateToken() {
8585 $ name = 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ' ;
8686 $ type = IToken::PERMANENT_TOKEN ;
8787
88+ $ this ->config ->method ('getSystemValueBool ' )
89+ ->willReturnMap ([
90+ ['auth.storeCryptedPassword ' , true , true ],
91+ ]);
8892 $ actual = $ this ->tokenProvider ->generateToken ($ token , $ uid , $ user , $ password , $ name , $ type , IToken::DO_NOT_REMEMBER );
8993
9094 $ this ->assertInstanceOf (PublicKeyToken::class, $ actual );
@@ -95,6 +99,48 @@ public function testGenerateToken() {
9599 $ this ->assertSame ($ password , $ this ->tokenProvider ->getPassword ($ actual , $ token ));
96100 }
97101
102+ public function testGenerateTokenNoPassword (): void {
103+ $ token = 'token ' ;
104+ $ uid = 'user ' ;
105+ $ user = 'User ' ;
106+ $ password = 'passme ' ;
107+ $ name = 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ' ;
108+ $ type = IToken::PERMANENT_TOKEN ;
109+ $ this ->config ->method ('getSystemValueBool ' )
110+ ->willReturnMap ([
111+ ['auth.storeCryptedPassword ' , true , false ],
112+ ]);
113+ $ this ->expectException (PasswordlessTokenException::class);
114+
115+ $ actual = $ this ->tokenProvider ->generateToken ($ token , $ uid , $ user , $ password , $ name , $ type , IToken::DO_NOT_REMEMBER );
116+
117+ $ this ->assertInstanceOf (PublicKeyToken::class, $ actual );
118+ $ this ->assertSame ($ uid , $ actual ->getUID ());
119+ $ this ->assertSame ($ user , $ actual ->getLoginName ());
120+ $ this ->assertSame ($ name , $ actual ->getName ());
121+ $ this ->assertSame (IToken::DO_NOT_REMEMBER , $ actual ->getRemember ());
122+ $ this ->tokenProvider ->getPassword ($ actual , $ token );
123+ }
124+
125+ public function testGenerateTokenLongPassword () {
126+ $ token = 'token ' ;
127+ $ uid = 'user ' ;
128+ $ user = 'User ' ;
129+ $ password = '' ;
130+ for ($ i = 0 ; $ i < 500 ; $ i ++) {
131+ $ password .= 'e ' ;
132+ }
133+ $ name = 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ' ;
134+ $ type = IToken::PERMANENT_TOKEN ;
135+ $ this ->config ->method ('getSystemValueBool ' )
136+ ->willReturnMap ([
137+ ['auth.storeCryptedPassword ' , true , true ],
138+ ]);
139+ $ this ->expectException (\RuntimeException::class);
140+
141+ $ actual = $ this ->tokenProvider ->generateToken ($ token , $ uid , $ user , $ password , $ name , $ type , IToken::DO_NOT_REMEMBER );
142+ }
143+
98144 public function testGenerateTokenInvalidName () {
99145 $ token = 'token ' ;
100146 $ uid = 'user ' ;
@@ -105,6 +151,10 @@ public function testGenerateTokenInvalidName() {
105151 . 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 '
106152 . 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ' ;
107153 $ type = IToken::PERMANENT_TOKEN ;
154+ $ this ->config ->method ('getSystemValueBool ' )
155+ ->willReturnMap ([
156+ ['auth.storeCryptedPassword ' , true , true ],
157+ ]);
108158
109159 $ actual = $ this ->tokenProvider ->generateToken ($ token , $ uid , $ user , $ password , $ name , $ type , IToken::DO_NOT_REMEMBER );
110160
@@ -122,6 +172,10 @@ public function testUpdateToken() {
122172 ->method ('updateActivity ' )
123173 ->with ($ tk , $ this ->time );
124174 $ tk ->setLastActivity ($ this ->time - 200 );
175+ $ this ->config ->method ('getSystemValueBool ' )
176+ ->willReturnMap ([
177+ ['auth.storeCryptedPassword ' , true , true ],
178+ ]);
125179
126180 $ this ->tokenProvider ->updateTokenActivity ($ tk );
127181
@@ -159,6 +213,10 @@ public function testGetPassword() {
159213 $ password = 'passme ' ;
160214 $ name = 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ' ;
161215 $ type = IToken::PERMANENT_TOKEN ;
216+ $ this ->config ->method ('getSystemValueBool ' )
217+ ->willReturnMap ([
218+ ['auth.storeCryptedPassword ' , true , true ],
219+ ]);
162220
163221 $ actual = $ this ->tokenProvider ->generateToken ($ token , $ uid , $ user , $ password , $ name , $ type , IToken::DO_NOT_REMEMBER );
164222
@@ -187,6 +245,10 @@ public function testGetPasswordInvalidToken() {
187245 $ name = 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ' ;
188246 $ type = IToken::PERMANENT_TOKEN ;
189247
248+ $ this ->config ->method ('getSystemValueBool ' )
249+ ->willReturnMap ([
250+ ['auth.storeCryptedPassword ' , true , true ],
251+ ]);
190252 $ actual = $ this ->tokenProvider ->generateToken ($ token , $ uid , $ user , $ password , $ name , $ type , IToken::DO_NOT_REMEMBER );
191253
192254 $ this ->tokenProvider ->getPassword ($ actual , 'wrongtoken ' );
@@ -199,6 +261,10 @@ public function testSetPassword() {
199261 $ password = 'passme ' ;
200262 $ name = 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ' ;
201263 $ type = IToken::PERMANENT_TOKEN ;
264+ $ this ->config ->method ('getSystemValueBool ' )
265+ ->willReturnMap ([
266+ ['auth.storeCryptedPassword ' , true , true ],
267+ ]);
202268
203269 $ actual = $ this ->tokenProvider ->generateToken ($ token , $ uid , $ user , $ password , $ name , $ type , IToken::DO_NOT_REMEMBER );
204270
@@ -303,14 +369,18 @@ public function testRenewSessionTokenWithoutPassword() {
303369 $ this ->tokenProvider ->renewSessionToken ('oldId ' , 'newId ' );
304370 }
305371
306- public function testRenewSessionTokenWithPassword () {
372+ public function testRenewSessionTokenWithPassword (): void {
307373 $ token = 'oldId ' ;
308374 $ uid = 'user ' ;
309375 $ user = 'User ' ;
310376 $ password = 'password ' ;
311377 $ name = 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ' ;
312378 $ type = IToken::PERMANENT_TOKEN ;
313379
380+ $ this ->config ->method ('getSystemValueBool ' )
381+ ->willReturnMap ([
382+ ['auth.storeCryptedPassword ' , true , true ],
383+ ]);
314384 $ oldToken = $ this ->tokenProvider ->generateToken ($ token , $ uid , $ user , $ password , $ name , $ type , IToken::DO_NOT_REMEMBER );
315385
316386 $ this ->mapper
@@ -321,7 +391,7 @@ public function testRenewSessionTokenWithPassword() {
321391 $ this ->mapper
322392 ->expects ($ this ->once ())
323393 ->method ('insert ' )
324- ->with ($ this ->callback (function (PublicKeyToken $ token ) use ($ user , $ uid , $ name ) {
394+ ->with ($ this ->callback (function (PublicKeyToken $ token ) use ($ user , $ uid , $ name ): bool {
325395 return $ token ->getUID () === $ uid &&
326396 $ token ->getLoginName () === $ user &&
327397 $ token ->getName () === $ name &&
@@ -333,14 +403,14 @@ public function testRenewSessionTokenWithPassword() {
333403 $ this ->mapper
334404 ->expects ($ this ->once ())
335405 ->method ('delete ' )
336- ->with ($ this ->callback (function ($ token ) use ($ oldToken ) {
406+ ->with ($ this ->callback (function ($ token ) use ($ oldToken ): bool {
337407 return $ token === $ oldToken ;
338408 }));
339409
340410 $ this ->tokenProvider ->renewSessionToken ('oldId ' , 'newId ' );
341411 }
342412
343- public function testGetToken () {
413+ public function testGetToken (): void {
344414 $ token = new PublicKeyToken ();
345415
346416 $ this ->config ->method ('getSystemValue ' )
@@ -443,6 +513,10 @@ public function testRotate() {
443513 $ name = 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ' ;
444514 $ type = IToken::PERMANENT_TOKEN ;
445515
516+ $ this ->config ->method ('getSystemValueBool ' )
517+ ->willReturnMap ([
518+ ['auth.storeCryptedPassword ' , true , true ],
519+ ]);
446520 $ actual = $ this ->tokenProvider ->generateToken ($ token , $ uid , $ user , $ password , $ name , $ type , IToken::DO_NOT_REMEMBER );
447521
448522 $ new = $ this ->tokenProvider ->rotate ($ actual , 'oldtoken ' , 'newtoken ' );
@@ -540,6 +614,10 @@ public function testUpdatePasswords() {
540614 'random2 ' ,
541615 IToken::PERMANENT_TOKEN ,
542616 IToken::REMEMBER );
617+ $ this ->config ->method ('getSystemValueBool ' )
618+ ->willReturnMap ([
619+ ['auth.storeCryptedPassword ' , true , true ],
620+ ]);
543621
544622 $ this ->mapper ->method ('hasExpiredTokens ' )
545623 ->with ($ uid )
0 commit comments