|
1 | 1 | <?php |
2 | 2 |
|
3 | 3 | use Laravel\Passkeys\Support\WebAuthn; |
| 4 | +use Webauthn\AuthenticatorSelectionCriteria; |
4 | 5 | use Webauthn\PublicKeyCredentialCreationOptions; |
5 | 6 | use Webauthn\PublicKeyCredentialRequestOptions; |
6 | 7 | use Webauthn\PublicKeyCredentialRpEntity; |
|
30 | 31 | expect($restored->user->displayName)->toBe('Test User'); |
31 | 32 | }); |
32 | 33 |
|
| 34 | +it('serializes browser arrays without null values', function (): void { |
| 35 | + $options = PublicKeyCredentialCreationOptions::create( |
| 36 | + rp: PublicKeyCredentialRpEntity::create(name: 'Test App', id: 'localhost'), |
| 37 | + user: PublicKeyCredentialUserEntity::create( |
| 38 | + name: 'test@example.com', |
| 39 | + id: 'user-id-123', |
| 40 | + displayName: 'Test User', |
| 41 | + ), |
| 42 | + challenge: random_bytes(32), |
| 43 | + authenticatorSelection: AuthenticatorSelectionCriteria::create( |
| 44 | + authenticatorAttachment: AuthenticatorSelectionCriteria::AUTHENTICATOR_ATTACHMENT_NO_PREFERENCE, |
| 45 | + residentKey: AuthenticatorSelectionCriteria::RESIDENT_KEY_REQUIREMENT_REQUIRED, |
| 46 | + ), |
| 47 | + excludeCredentials: [], |
| 48 | + ); |
| 49 | + |
| 50 | + $array = WebAuthn::toBrowserArray($options); |
| 51 | + |
| 52 | + expect($array)->not->toHaveKey('attestation'); |
| 53 | + expect($array)->toHaveKey('excludeCredentials', []); |
| 54 | + expect($array['authenticatorSelection']) |
| 55 | + ->not->toHaveKey('authenticatorAttachment') |
| 56 | + ->toHaveKey('residentKey', 'required'); |
| 57 | +}); |
| 58 | + |
33 | 59 | it('serializes and deserializes verification options', function (): void { |
34 | 60 | $options = PublicKeyCredentialRequestOptions::create( |
35 | 61 | challenge: random_bytes(32), |
|
0 commit comments