|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/* |
| 6 | + * The MIT License (MIT) |
| 7 | + * |
| 8 | + * Copyright (c) 2014-2020 Spomky-Labs |
| 9 | + * |
| 10 | + * This software may be modified and distributed under the terms |
| 11 | + * of the MIT license. See the LICENSE file for details. |
| 12 | + */ |
| 13 | + |
| 14 | +namespace Webauthn\Tests\Unit; |
| 15 | + |
| 16 | +use PHPUnit\Framework\TestCase; |
| 17 | +use Ramsey\Uuid\Uuid; |
| 18 | +use function Safe\json_decode; |
| 19 | +use Webauthn\PublicKeyCredentialSource; |
| 20 | +use Webauthn\TrustPath\EmptyTrustPath; |
| 21 | + |
| 22 | +/** |
| 23 | + * @group unit |
| 24 | + * @group Fido2 |
| 25 | + * |
| 26 | + * @covers \Webauthn\TokenBinding\TokenBinding |
| 27 | + * |
| 28 | + * @internal |
| 29 | + */ |
| 30 | +class PublicKeyCredentialSourceTest extends TestCase |
| 31 | +{ |
| 32 | + /** |
| 33 | + * @test |
| 34 | + */ |
| 35 | + public function backwardCompatibilityIsEnsured(): void |
| 36 | + { |
| 37 | + $data = '{"publicKeyCredentialId":"cHVibGljS2V5Q3JlZGVudGlhbElk","type":"type","transports":["transport1","transport2"],"attestationType":"attestationType","trustPath":{"type":"Webauthn\\\\TrustPath\\\\EmptyTrustPath"},"aaguid":"014c0f17-f86f-4586-9914-2779922ba877","credentialPublicKey":"cHVibGljS2V5","userHandle":"dXNlckhhbmRsZQ","counter":123456789}'; |
| 38 | + $json = json_decode($data, true); |
| 39 | + $source = PublicKeyCredentialSource::createFromArray($json); |
| 40 | + |
| 41 | + static::assertEquals('publicKeyCredentialId', $source->getPublicKeyCredentialId()); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @test |
| 46 | + */ |
| 47 | + public function objectSerialization(): void |
| 48 | + { |
| 49 | + $tokenBinding = new PublicKeyCredentialSource( |
| 50 | + 'publicKeyCredentialId', |
| 51 | + 'type', |
| 52 | + ['transport1', 'transport2'], |
| 53 | + 'attestationType', |
| 54 | + EmptyTrustPath::createFromArray([]), |
| 55 | + Uuid::fromString('02ffd35d-7f0c-46b5-9eae-851ee4807b25'), |
| 56 | + 'publicKey', |
| 57 | + 'userHandle', |
| 58 | + 123456789 |
| 59 | + ); |
| 60 | + |
| 61 | + static::assertEquals('{"publicKeyCredentialId":"cHVibGljS2V5Q3JlZGVudGlhbElk","type":"type","transports":["transport1","transport2"],"attestationType":"attestationType","trustPath":{"type":"Webauthn\\\\TrustPath\\\\EmptyTrustPath"},"aaguid":"02ffd35d-7f0c-46b5-9eae-851ee4807b25","credentialPublicKey":"cHVibGljS2V5","userHandle":"dXNlckhhbmRsZQ","counter":123456789,"otherUI":null}', json_encode($tokenBinding, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_SLASHES)); |
| 62 | + } |
| 63 | +} |
0 commit comments