diff --git a/tests/lib/Authentication/Login/CreateSessionTokenCommandTest.php b/tests/lib/Authentication/Login/CreateSessionTokenCommandTest.php index 049b6b1c94b..5a8a57fac03 100644 --- a/tests/lib/Authentication/Login/CreateSessionTokenCommandTest.php +++ b/tests/lib/Authentication/Login/CreateSessionTokenCommandTest.php @@ -1,40 +1,49 @@ config = $this->createMock(IConfig::class); $this->userSession = $this->createMock(Session::class); + $this->urlGenerator = $this->createMock(IURLGenerator::class); + $this->timeFactory = $this->createMock(ITimeFactory::class); $this->cmd = new CreateSessionTokenCommand( $this->config, - $this->userSession + $this->userSession, + $this->urlGenerator, + $this->timeFactory, ); } public function testProcess() { + // Just return the route name as path to not return an empty string + $this->urlGenerator->expects(self::once()) + ->method('linkToRoute') + ->willReturnArgument(0); $data = $this->getLoggedInLoginData(); $this->config->expects($this->once()) ->method('getSystemValueInt') @@ -53,7 +62,8 @@ class CreateSessionTokenCommandTest extends ALoginCommandTest { $this->username, $this->username, $this->password, - IToken::REMEMBER + IToken::REMEMBER, + null ); $this->userSession->expects($this->once()) ->method('updateTokens') @@ -68,6 +78,10 @@ class CreateSessionTokenCommandTest extends ALoginCommandTest { } public function testProcessDoNotRemember() { + // Just return the route name as path to not return an empty string + $this->urlGenerator->expects(self::once()) + ->method('linkToRoute') + ->willReturnArgument(0); $data = $this->getLoggedInLoginData(); $this->config->expects($this->once()) ->method('getSystemValueInt') @@ -86,7 +100,8 @@ class CreateSessionTokenCommandTest extends ALoginCommandTest { $this->username, $this->username, $this->password, - IToken::DO_NOT_REMEMBER + IToken::DO_NOT_REMEMBER, + null ); $this->userSession->expects($this->once()) ->method('updateTokens') @@ -100,4 +115,46 @@ class CreateSessionTokenCommandTest extends ALoginCommandTest { $this->assertTrue($result->isSuccess()); $this->assertFalse($data->isRememberLogin()); } + + public function testLoginFlowEphemeral(): void { + $this->redirectUrl = 'EPHEMERAL_ROUTE'; + $this->urlGenerator->expects(self::once()) + ->method('linkToRoute') + ->willReturn($this->redirectUrl); + $this->timeFactory->expects(self::once()) + ->method('getTime') + ->willReturn(1000); + + $data = $this->getLoggedInLoginDataWithRedirectUrl(); + $this->config->expects($this->once()) + ->method('getSystemValueInt') + ->with( + 'remember_login_cookie_lifetime', + 60 * 60 * 24 * 15 + ) + ->willReturn(100); + $this->user->expects($this->any()) + ->method('getUID') + ->willReturn($this->username); + $this->userSession->expects($this->once()) + ->method('createSessionToken') + ->with( + $this->request, + $this->username, + $this->username, + $this->password, + IToken::REMEMBER, + 1000 + 5 * 60 + ); + $this->userSession->expects($this->once()) + ->method('updateTokens') + ->with( + $this->username, + $this->password + ); + + $result = $this->cmd->process($data); + + $this->assertTrue($result->isSuccess()); + } }