|
4 | 4 |
|
5 | 5 | namespace Webauthn\Tests\Unit;
|
6 | 6 |
|
| 7 | +use PHPUnit\Framework\Attributes\DataProvider; |
7 | 8 | use PHPUnit\Framework\Attributes\Test;
|
8 | 9 | use Symfony\Component\Serializer\Encoder\JsonEncode;
|
9 | 10 | use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
|
|
13 | 14 | use Webauthn\PublicKeyCredentialRpEntity;
|
14 | 15 | use Webauthn\PublicKeyCredentialUserEntity;
|
15 | 16 | use Webauthn\Tests\AbstractTestCase;
|
| 17 | +use Webauthn\TrustPath\CertificateTrustPath; |
| 18 | +use Webauthn\TrustPath\EmptyTrustPath; |
| 19 | +use Webauthn\TrustPath\TrustPath; |
16 | 20 | use const JSON_THROW_ON_ERROR;
|
17 | 21 |
|
18 | 22 | /**
|
19 | 23 | * @internal
|
20 | 24 | */
|
21 | 25 | final class SerializerTest extends AbstractTestCase
|
22 | 26 | {
|
| 27 | + public static function provideTrustPath(): iterable |
| 28 | + { |
| 29 | + yield [ |
| 30 | + CertificateTrustPath::create(['X509_KEY_1', 'X509_KEY_2', 'X509_KEY_3']), |
| 31 | + '{"x5c":["X509_KEY_1","X509_KEY_2","X509_KEY_3"]}', |
| 32 | + ]; |
| 33 | + yield [EmptyTrustPath::create(), '[]']; |
| 34 | + } |
| 35 | + |
| 36 | + #[Test] |
| 37 | + #[DataProvider('provideTrustPath')] |
| 38 | + public function theTrustPathCanBeSerialized(TrustPath $trustPath, string $expected): void |
| 39 | + { |
| 40 | + //When |
| 41 | + $json = $this->getSerializer() |
| 42 | + ->serialize( |
| 43 | + $trustPath, |
| 44 | + 'json', |
| 45 | + [ |
| 46 | + JsonEncode::OPTIONS => JSON_THROW_ON_ERROR, |
| 47 | + AbstractObjectNormalizer::SKIP_NULL_VALUES => true, |
| 48 | + AbstractObjectNormalizer::SKIP_UNINITIALIZED_VALUES => true, |
| 49 | + ], |
| 50 | + ); |
| 51 | + |
| 52 | + //Then |
| 53 | + static::assertJsonStringEqualsJsonString($expected, $json); |
| 54 | + } |
| 55 | + |
| 56 | + #[Test] |
| 57 | + #[DataProvider('provideTrustPath')] |
| 58 | + public function theTrustPathCanBeDeserialized(TrustPath $trustPath, string $expected): void |
| 59 | + { |
| 60 | + //When |
| 61 | + $deserialized = $this->getSerializer() |
| 62 | + ->deserialize( |
| 63 | + $expected, |
| 64 | + TrustPath::class, |
| 65 | + 'json', |
| 66 | + [ |
| 67 | + AbstractObjectNormalizer::SKIP_NULL_VALUES => true, |
| 68 | + AbstractObjectNormalizer::SKIP_UNINITIALIZED_VALUES => true, |
| 69 | + ], |
| 70 | + ); |
| 71 | + |
| 72 | + //Then |
| 73 | + static::assertEquals($trustPath, $deserialized); |
| 74 | + } |
| 75 | + |
23 | 76 | #[Test]
|
24 | 77 | public function theCredentialCanBeDeserialized(): void
|
25 | 78 | {
|
|
0 commit comments