@@ -56,7 +56,7 @@ public function it_prepares_assertion_with_challenge()
5656
5757 $ this ->assertInstanceOf (PublicKeyCredentialRequestOptions::class, $ options );
5858 $ this ->assertNotNull (session ('webauthn.challenge ' ));
59- $ this ->assertEquals (32 , strlen (session ('webauthn.challenge ' )));
59+ $ this ->assertEquals (32 , strlen (base64_decode ( session ('webauthn.challenge ' ) )));
6060 $ this ->assertEquals (PublicKeyCredentialRequestOptions::USER_VERIFICATION_REQUIREMENT_REQUIRED , $ options ->userVerification );
6161 }
6262
@@ -84,11 +84,11 @@ public function it_stores_challenge_in_session()
8484 // Challenge should be stored in session for later verification
8585 $ storedChallenge = session ('webauthn.challenge ' );
8686 $ this ->assertNotNull ($ storedChallenge );
87- $ this ->assertEquals (32 , strlen ($ storedChallenge ));
87+ $ this ->assertEquals (32 , strlen (base64_decode ( $ storedChallenge) ));
8888
8989 // The challenge in the options should be the same binary value
9090 // (base64url encoding happens during serialization, not in the object)
91- $ this ->assertEquals ($ storedChallenge , $ options ->challenge );
91+ $ this ->assertEquals (base64_decode ( $ storedChallenge) , $ options ->challenge );
9292 }
9393
9494 #[Test]
@@ -180,7 +180,7 @@ public function it_validates_assertion_successfully()
180180
181181 $ credentials = ['id ' => 'credential-id ' , 'rawId ' => 'raw-id ' , 'response ' => [], 'type ' => 'public-key ' ];
182182 $ challenge = random_bytes (32 );
183- session ()->put ('webauthn.challenge ' , $ challenge );
183+ session ()->put ('webauthn.challenge ' , base64_encode ( $ challenge) );
184184
185185 // Create real objects
186186 $ publicKeyCredential = new PublicKeyCredential (
@@ -219,6 +219,7 @@ public function it_validates_assertion_successfully()
219219 $ this ->mockAssertionValidator
220220 ->shouldReceive ('check ' )
221221 ->once ()
222+ ->withArgs (fn ($ credential , $ response , $ options ) => $ options ->challenge === $ challenge )
222223 ->andReturn ($ updatedCredentialSource );
223224
224225 $ result = $ this ->webauthn ->validateAssertion ($ mockUser , $ credentials );
@@ -234,7 +235,6 @@ public function it_throws_exception_when_no_matching_passkey()
234235 $ user ->save ();
235236
236237 $ credentials = ['id ' => 'credential-id ' , 'rawId ' => 'raw-id ' , 'response ' => [], 'type ' => 'public-key ' ];
237- session ()->put ('webauthn.challenge ' , random_bytes (32 ));
238238
239239 $ publicKeyCredential = new PublicKeyCredential (
240240 'public-key ' ,
0 commit comments