Skip to content

Commit

Permalink
Test both challenge paths in get response
Browse files Browse the repository at this point in the history
  • Loading branch information
Firehed committed Aug 28, 2023
1 parent 75dc60c commit 96abf52
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions tests/GetResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
class GetResponseTest extends \PHPUnit\Framework\TestCase
{
// These hold the values which would be kept server-side.
private Challenge $challenge;
private CredentialInterface $credential;
private RelyingParty $rp;

Expand All @@ -32,13 +31,6 @@ public function setUp(): void

$this->rp = new RelyingParty('http://localhost:8888');

$this->challenge = new Challenge(BinaryString::fromBytes([
145, 94, 61, 93, 225, 209, 17, 150,
18, 48, 223, 38, 136, 44, 81, 173,
233, 248, 232, 46, 211, 200, 99, 52,
142, 111, 103, 233, 244, 188, 26, 108,
]));

$this->id = BinaryString::fromBytes([
116, 216, 28, 85, 64, 195, 24, 125,
129, 100, 47, 13, 163, 166, 205, 188,
Expand Down Expand Up @@ -102,7 +94,7 @@ public function testCDJTypeMismatchIsError(): void
);

$this->expectVerificationError('7.2.11');
$response->verify($this->challenge, $this->rp, $this->credential);
$response->verify($this->getChallenge(), $this->rp, $this->credential);
}

// 7.2.12
Expand All @@ -121,7 +113,7 @@ public function testCDJChallengeMismatchIsError(): void
);

$this->expectVerificationError('7.2.12');
$response->verify($this->challenge, $this->rp, $this->credential);
$response->verify($this->getChallenge(), $this->rp, $this->credential);
}

// 7.2.13
Expand All @@ -140,7 +132,7 @@ public function testCDJOriginMismatchIsError(): void
);

$this->expectVerificationError('7.2.13');
$response->verify($this->challenge, $this->rp, $this->credential);
$response->verify($this->getChallenge(), $this->rp, $this->credential);
}

// 7.2.15
Expand All @@ -156,7 +148,7 @@ public function testRelyingPartyIdMismatchIsError(): void
);

$this->expectVerificationError('7.2.15');
$response->verify($this->challenge, $rp, $this->credential);
$response->verify($this->getChallenge(), $rp, $this->credential);
}

// 7.2.16
Expand All @@ -178,7 +170,7 @@ public function testUserVerifiedNotPresentWhenRequiredIsError(): void
);

$this->expectVerificationError('7.2.17');
$response->verify($this->challenge, $this->rp, $this->credential, UserVerificationRequirement::Required);
$response->verify($this->getChallenge(), $this->rp, $this->credential, UserVerificationRequirement::Required);
}

// 7.2.20
Expand All @@ -192,7 +184,7 @@ public function testIncorrectSignatureIsError(): void
);

$this->expectVerificationError('7.2.20');
$response->verify($this->challenge, $this->rp, $this->credential);
$response->verify($this->getChallenge(), $this->rp, $this->credential);
}

public function testVerifyReturnsCredentialWithUpdatedCounter(): void
Expand All @@ -208,7 +200,7 @@ public function testVerifyReturnsCredentialWithUpdatedCounter(): void
signature: $this->signature,
);

$updatedCredential = $response->verify($this->challenge, $this->rp, $this->credential);
$updatedCredential = $response->verify($this->getChallenge(), $this->rp, $this->credential);
self::assertGreaterThan(
0,
$updatedCredential->getSignCount(),
Expand Down Expand Up @@ -243,7 +235,7 @@ public function testCredentialContainerWorks(): void
signature: $this->signature,
);

$credential = $response->verify($this->challenge, $this->rp, $container);
$credential = $response->verify($this->getChallenge(), $this->rp, $container);
self::assertSame($this->credential->getStorageId(), $credential->getStorageId());
}

Expand All @@ -259,7 +251,7 @@ public function testEmptyCredentialContainerFails(): void
);

$this->expectVerificationError('7.2.7');
$response->verify($this->challenge, $this->rp, $container);
$response->verify($this->getChallenge(), $this->rp, $container);
}

public function testCredentialContainerMissingUsedCredentialFails(): void
Expand All @@ -276,12 +268,22 @@ public function testCredentialContainerMissingUsedCredentialFails(): void
);

$this->expectVerificationError('7.2.7');
$response->verify($this->challenge, $this->rp, $container);
$response->verify($this->getChallenge(), $this->rp, $container);
}

private function expectVerificationError(string $section): void
{
$this->expectException(Errors\VerificationError::class);
// TODO: how to assert on $section
}

protected function getChallenge(): Challenge|ChallengeManagerInterface
{
return new Challenge(BinaryString::fromBytes([
145, 94, 61, 93, 225, 209, 17, 150,
18, 48, 223, 38, 136, 44, 81, 173,
233, 248, 232, 46, 211, 200, 99, 52,
142, 111, 103, 233, 244, 188, 26, 108,
]));
}
}

0 comments on commit 96abf52

Please sign in to comment.