Skip to content

Commit 114cfee

Browse files
committed
New tests
1 parent 6109cbe commit 114cfee

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

src/webauthn/src/PublicKeyCredentialSource.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,10 @@ public function setOtherUI(?array $otherUI): self
186186
public static function createFromArray(array $data): self
187187
{
188188
$keys = array_keys(get_class_vars(self::class));
189-
unset($keys['otherUI']);
190189
foreach ($keys as $key) {
190+
if ('otherUI' === $key) {
191+
continue;
192+
}
191193
Assertion::keyExists($data, $key, sprintf('The parameter "%s" is missing', $key));
192194
}
193195
switch (true) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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

Comments
 (0)