Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
More updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Firehed committed Oct 27, 2021
1 parent d13eb1b commit b0034c0
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions tests/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,17 +521,15 @@ public function testValidateLoginThrowsWhenChallengeDoesNotMatch(): void
public function testValidateLoginThrowsIfNoRegistrationMatchesKeyHandle(): void
{
// Change registration KH
$registration = (new Registration())
->setKeyHandle(fromBase64Web('some-other-key-handle'))
->setPublicKey($this->getDefaultPublicKey())
->setCounter(2)
;
$request = $this->getDefaultSignRequest();
$registration = $this->getDefaultRegistration([
'keyHandle' => 'some-other-key-handle',
]);
$challenge = $this->getDefaultLoginChallenge();
$response = $this->getDefaultLoginResponse();

$this->expectException(SecurityException::class);
$this->expectExceptionCode(SecurityException::KEY_HANDLE_UNRECOGNIZED);
$this->server->validateLogin($request, $response, [$registration]);
$this->server->validateLogin($challenge, $response, [$registration]);
}

/**
Expand Down Expand Up @@ -763,17 +761,25 @@ private function getDefaultLoginChallenge(): ChallengeProviderInterface
/**
* @param array{
* counter?: int,
* keyHandle?: string,
* } $overrides
*/
private function getDefaultRegistration(array $overrides = []): RegistrationInterface
{
$defaults = [
'counter' => 2,
'keyHandle' => fromBase64Web(self::ENCODED_KEY_HANDLE),
];
/**
* @var array{
* counter: int,
* keyHandle: string,
* } (phpstan/phpstan#5846)
*/
$data = array_merge($defaults, $overrides);
// From database attached to the authenticating user
return (new Registration())
->setKeyHandle(fromBase64Web(self::ENCODED_KEY_HANDLE))
->setKeyHandle($data['keyHandle'])
->setAttestationCertificate($this->getDefaultAttestationCertificate())
->setPublicKey($this->getDefaultPublicKey())
->setCounter($data['counter'])
Expand Down

0 comments on commit b0034c0

Please sign in to comment.