@@ -479,6 +479,56 @@ public function testLogClientInNoTokenPasswordNo2fa() {
479479 $ userSession ->logClientIn ('john ' , 'doe ' , $ request , $ this ->throttler );
480480 }
481481
482+ public function testTryTokenLoginNoHeaderNoSessionCookie (): void {
483+ $ request = $ this ->createMock (IRequest::class);
484+ $ this ->config ->expects (self ::once ())
485+ ->method ('getSystemValueString ' )
486+ ->with ('instanceid ' )
487+ ->willReturn ('abc123 ' );
488+ $ request ->method ('getHeader ' )->with ('Authorization ' )->willReturn ('' );
489+ $ request ->method ('getCookie ' )->with ('abc123 ' )->willReturn (null );
490+ $ this ->tokenProvider ->expects (self ::never ())
491+ ->method ('getToken ' );
492+
493+ $ loginResult = $ this ->userSession ->tryTokenLogin ($ request );
494+
495+ self ::assertFalse ($ loginResult );
496+ }
497+
498+ public function testTryTokenLoginAuthorizationHeaderTokenNotFound (): void {
499+ $ request = $ this ->createMock (IRequest::class);
500+ $ request ->method ('getHeader ' )->with ('Authorization ' )->willReturn ('Bearer abcde-12345 ' );
501+ $ this ->tokenProvider ->expects (self ::once ())
502+ ->method ('getToken ' )
503+ ->with ('abcde-12345 ' )
504+ ->willThrowException (new InvalidTokenException ());
505+
506+ $ loginResult = $ this ->userSession ->tryTokenLogin ($ request );
507+
508+ self ::assertFalse ($ loginResult );
509+ }
510+
511+ public function testTryTokenLoginSessionIdTokenNotFound (): void {
512+ $ request = $ this ->createMock (IRequest::class);
513+ $ this ->config ->expects (self ::once ())
514+ ->method ('getSystemValueString ' )
515+ ->with ('instanceid ' )
516+ ->willReturn ('abc123 ' );
517+ $ request ->method ('getHeader ' )->with ('Authorization ' )->willReturn ('' );
518+ $ request ->method ('getCookie ' )->with ('abc123 ' )->willReturn ('abcde12345 ' );
519+ $ this ->session ->expects (self ::once ())
520+ ->method ('getId ' )
521+ ->willReturn ('abcde12345 ' );
522+ $ this ->tokenProvider ->expects (self ::once ())
523+ ->method ('getToken ' )
524+ ->with ('abcde12345 ' )
525+ ->willThrowException (new InvalidTokenException ());
526+
527+ $ loginResult = $ this ->userSession ->tryTokenLogin ($ request );
528+
529+ self ::assertFalse ($ loginResult );
530+ }
531+
482532 public function testRememberLoginValidToken () {
483533 $ session = $ this ->getMockBuilder (Memory::class)->setConstructorArgs (['' ])->getMock ();
484534 $ managerMethods = get_class_methods (Manager::class);
0 commit comments