Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Credential entity and related tests #624

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<server name="SYMFONY_PHPUNIT_VERSION" value="10.1"/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0"/>
<env name="APP_DEBUG" value="true"/>
<env name="DATABASE_URL" value="sqlite:///%kernel.project_dir%/var/data.db"/>
<server name="KERNEL_CLASS" value="Webauthn\Tests\Bundle\Functional\AppKernel"/>
<ini name="memory_limit" value="-1"/>
</php>
Expand Down
10 changes: 0 additions & 10 deletions tests/symfony/config/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
parameters:
env(DATABASE_URL): ''

framework:
test: true
secret: 'test'
Expand Down Expand Up @@ -98,13 +95,6 @@ services:

doctrine:
dbal:
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci

url: '%env(resolve:DATABASE_URL)%'
orm:
enable_lazy_ghost_objects: true
Expand Down
19 changes: 19 additions & 0 deletions tests/symfony/functional/Entity/Credential.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Webauthn\Tests\Bundle\Functional\Entity;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Webauthn\PublicKeyCredentialSource;

#[ORM\Entity]
#[Orm\Table(name: 'credentials')]
class Credential extends PublicKeyCredentialSource
{
#[ORM\Id]
#[ORM\Column(type: Types::STRING, length: 10)]
#[ORM\GeneratedValue(strategy: 'NONE')]
public string $id;
}
105 changes: 105 additions & 0 deletions tests/symfony/functional/Entity/EntityTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

declare(strict_types=1);

namespace Webauthn\Tests\Bundle\Functional\Entity;

use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

/**
* @internal
*/
final class EntityTest extends KernelTestCase
{
#[Test]
#[DataProvider('expectedFields')]
public function theSchemaIsValid(string $name, string $type, null|bool $nullable): void
{
//Given
/** @var EntityManagerInterface $entityManager */
$entityManager = self::getContainer()->get(EntityManagerInterface::class);

//When
$classMetadata = $entityManager->getClassMetadata(Credential::class);
$fields = $classMetadata->fieldMappings;

//Then
static::assertArrayHasKey($name, $fields);
$field = $fields[$name];
static::assertSame($type, $field['type']);
static::assertSame($nullable, $field['nullable']);

}

public static function expectedFields(): iterable
{
yield [
'name' => 'publicKeyCredentialId',
'type' => 'base64',
'nullable' => null,
];
yield [
'name' => 'type',
'type' => 'string',
'nullable' => null,
];
yield [
'name' => 'transports',
'type' => 'array',
'nullable' => null,
];
yield [
'name' => 'attestationType',
'type' => 'string',
'nullable' => null,
];
yield [
'name' => 'trustPath',
'type' => 'trust_path',
'nullable' => null,
];
yield [
'name' => 'aaguid',
'type' => 'aaguid',
'nullable' => null,
];
yield [
'name' => 'credentialPublicKey',
'type' => 'base64',
'nullable' => null,
];
yield [
'name' => 'userHandle',
'type' => 'string',
'nullable' => null,
];
yield [
'name' => 'counter',
'type' => 'integer',
'nullable' => null,
];
yield [
'name' => 'otherUI',
'type' => 'array',
'nullable' => true,
];
yield [
'name' => 'backupEligible',
'type' => 'boolean',
'nullable' => true,
];
yield [
'name' => 'backupStatus',
'type' => 'boolean',
'nullable' => true,
];
yield [
'name' => 'uvInitialized',
'type' => 'boolean',
'nullable' => true,
];
}
}