Skip to content

Commit

Permalink
Fix PKUEntity encoding (#547)
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky authored Feb 5, 2024
1 parent c093293 commit 238adc8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/webauthn/src/PublicKeyCredentialUserEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Webauthn;

use ParagonIE\ConstantTime\Base64;
use ParagonIE\ConstantTime\Base64UrlSafe;
use Webauthn\Exception\InvalidDataException;
use function array_key_exists;
Expand Down Expand Up @@ -69,7 +68,7 @@ public static function createFromArray(array $json): self
$json,
'Invalid input. "displayName" is missing.'
);
$id = Base64::decode($json['id'], true);
$id = Base64UrlSafe::decodeNoPadding($json['id']);

return self::create($json['name'], $id, $json['displayName'], $json['icon'] ?? null);
}
Expand Down
19 changes: 18 additions & 1 deletion tests/library/Unit/EntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
final class EntityTest extends TestCase
{
#[Test]
public function anPublicKeyCredentialUserEntityCanBeCreatedAndValueAccessed(): void
public function aPublicKeyCredentialUserEntityCanBeCreatedAndValueAccessed(): void
{
$user = PublicKeyCredentialUserEntity::create('name', 'id', 'display_name', 'icon');

Expand All @@ -30,6 +30,23 @@ public function anPublicKeyCredentialUserEntityCanBeCreatedAndValueAccessed(): v
);
}

#[Test]
public function aPublicKeyCredentialUserEntityCanBeCreatedAEncodedAndDecoded(): void
{
$ue = new PublicKeyCredentialUserEntity('test test', "\0\1\2\xff", 'TEST TEST');
$ue2 = PublicKeyCredentialUserEntity::createFromString(json_encode($ue));

static::assertSame('test test', $ue2->name);
static::assertSame('TEST TEST', $ue2->displayName);
static::assertNull($ue2->icon);
static::assertSame("\0\1\2\xff", $ue2->id);
static::assertSame(json_encode($ue), json_encode($ue2, JSON_THROW_ON_ERROR));
static::assertSame(
'{"name":"test test","id":"AAEC_w","displayName":"TEST TEST"}',
json_encode($ue, JSON_THROW_ON_ERROR)
);
}

#[Test]
public function anPublicKeyCredentialRpEntityCanBeCreatedAndValueAccessed(): void
{
Expand Down

0 comments on commit 238adc8

Please sign in to comment.