diff --git a/models/classes/Platform/Service/Oidc/Lti1p3UserAuthenticator.php b/models/classes/Platform/Service/Oidc/Lti1p3UserAuthenticator.php index a1d64061..642f4a37 100644 --- a/models/classes/Platform/Service/Oidc/Lti1p3UserAuthenticator.php +++ b/models/classes/Platform/Service/Oidc/Lti1p3UserAuthenticator.php @@ -50,8 +50,13 @@ public function authenticate( /** * @throws ErrorException */ - private function getUserIdentity(string $userId): UserIdentity + private function getUserIdentity(string $userId): ?UserIdentity { + // anonymous user without login data + if ($userId === '') { + return null; + } + $user = $this->getUserService() ->getUser($userId); diff --git a/test/unit/models/classes/Platform/Service/Oidc/Lti1p3UserAuthenticatorTest.php b/test/unit/models/classes/Platform/Service/Oidc/Lti1p3UserAuthenticatorTest.php index fab18695..e86c3dfc 100644 --- a/test/unit/models/classes/Platform/Service/Oidc/Lti1p3UserAuthenticatorTest.php +++ b/test/unit/models/classes/Platform/Service/Oidc/Lti1p3UserAuthenticatorTest.php @@ -37,8 +37,10 @@ class Lti1p3UserAuthenticatorTest extends TestCase { use ServiceManagerMockTrait; + private const LOGIN_HINT = 'userId#123456'; + /** @var Lti1p3UserAuthenticator */ - private $subject; + private Lti1p3UserAuthenticator $subject; /** @var UserService|MockObject */ private $userService; @@ -85,7 +87,7 @@ public function testAuthenticateUser(): void 'en-US' ) ), - $this->subject->authenticate($registration, 'userId#123456') + $this->subject->authenticate($registration, self::LOGIN_HINT) ); } @@ -104,12 +106,32 @@ public function testAnonymousOrGuestUser(): void new UserAuthenticationResult( true, new UserIdentity( - 'userId#123456', + self::LOGIN_HINT, '', '' ) ), - $this->subject->authenticate($registration, 'userId#123456') + $this->subject->authenticate($registration, self::LOGIN_HINT) + ); + } + + public function testAnonymousWithoutLoginHintData(): void + { + $this->expectAnonymousUser( + [ + 'role' + ] + ); + + /** @var RegistrationInterface|MockObject $registration */ + $registration = $this->createMock(RegistrationInterface::class); + + $this->assertEquals( + new UserAuthenticationResult( + true, + null + ), + $this->subject->authenticate($registration, '') ); }