Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Anonymous user type does not work correctly for LTI #414

Merged
merged 4 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -85,7 +87,7 @@ public function testAuthenticateUser(): void
'en-US'
)
),
$this->subject->authenticate($registration, 'userId#123456')
$this->subject->authenticate($registration, self::LOGIN_HINT)
);
}

Expand All @@ -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, '')
);
}

Expand Down
Loading