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

Fix doctrine mapping & add smoketest that fails on invalid schema #170

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .docheader
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2019 SURFnet B.V.
* Copyright %regexp:\d{4}% SURFnet %regexp:(B.V.|bv)%
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
16 changes: 5 additions & 11 deletions .github/workflows/test-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,17 @@ on: [pull_request]
jobs:
run-qa-tests:
runs-on: ubuntu-latest
defaults:
run:
working-directory: /var/www/html/
container:
image: ghcr.io/openconext/openconext-basecontainers/php82-apache2-node20-composer2:latest
volumes:
- .:/var/www/html

timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Composer install
run: composer install
- name: Init environment
run: cd ci/docker && ./init.sh

- name: Build frontend assets
run: yarn && yarn encore production

- name: Run QA tests
run: composer check
run: |
cd ci/docker && docker compose exec -T webauthn bash -c 'composer check'
4 changes: 1 addition & 3 deletions ci/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
---

version: '3.7'

services:
haproxy:
image: ghcr.io/openconext/openconext-basecontainers/haproxy26:latest
Expand All @@ -14,7 +12,7 @@ services:
- "webauthn.dev.openconext.local"
webauthn:
stdin_open: true
image: ghcr.io/openconext/stepup-webauthn/stepup-webauthn:dev
image: ghcr.io/openconext/openconext-basecontainers/php82-apache2-node20-composer2:latest
volumes:
- ../../:/var/www/html
- ${PWD}/webauthn:/config
Expand Down
14 changes: 14 additions & 0 deletions ci/docker/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
echo "pulling the images"
docker compose pull
echo "starting the images"
docker compose up -d
echo "intialising the environment"
docker compose exec -T webauthn bash -c '
cp /var/www/html/config/openconext/parameters.yaml.dist /var/www/html/config/openconext/parameters.yaml && \
composer install --prefer-dist -n -o --no-scripts && \
./bin/console assets:install --verbose && \
./bin/console cache:clear && \
chown -R www-data:www-data /var/www/html/var/ && \
./bin/console doctrine:migrations:migrate --no-interaction
'
1 change: 1 addition & 0 deletions ci/docker/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## Don't use this docker setup in production this is solely for testing purposes!
6 changes: 6 additions & 0 deletions ci/qa/doctrine-schema-validate
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

cd $(dirname $0)/../../

printf "Doctrine schema validate\n"
./bin/console doctrine:schema:validate
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@
"@phpcpd",
"@phpmd",
"@phpstan",
"@unit-tests"
"@unit-tests",
"@doctrine-schema-validate"
],
"composer-validate": "./ci/qa/validate",
"docheader": "./ci/qa/docheader",
Expand All @@ -101,6 +102,7 @@
"phpstan": "./ci/qa/phpstan",
"phpstan-baseline": "./ci/qa/phpstan-update-baseline",
"unit-tests": "ci/qa/phpunit",
"doctrine-schema-validate": "ci/qa/doctrine-schema-validate",
"frontend-install": [
"yarn install"
],
Expand Down
2 changes: 1 addition & 1 deletion config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ doctrine:
dbal:
# configure these for your database server
driver: 'pdo_mysql'
server_version: '5.6'
server_version: '10.6.19-MariaDB'
charset: utf8mb4
default_table_options:
charset: utf8mb4
Expand Down
4 changes: 3 additions & 1 deletion config/services_test.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
parameters:
locale: nl_NL
database_url: sqlite:///%kernel.project_dir%/var/webauthn.db

services:
# default configuration for services in *this* file
Expand All @@ -14,6 +13,9 @@ services:
$supportEmail: '%support_email%'
$locales: '%locales%'
$userDisplayName: '%user_display_name%'
$jwtMdsBlobFileName: '%fido2_jwt_mds_blob_file_name%'
$jwtMdsRootCertFileName: '%fido2_jwt_mds_root_certificate_file_name%'
$mdsCacheDir: '%fido2_mds_cache_dir%'

# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
Expand Down
6 changes: 4 additions & 2 deletions src/Entity/PublicKeyCredentialSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ class PublicKeyCredentialSource extends BasePublicKeyCredentialSource
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type:"integer")]
private string $id;
private int $id;

/**
* Override the $uvInitialized field which we do not use, but needs
* Override the $backupEligible, $backupStatus and $uvInitialized fields which we do not use, but needs
* to be initialized. Needed to prevent read before written errors.
*/
public ?bool $backupEligible = null;
public ?bool $backupStatus = null;
public ?bool $uvInitialized = false;

public function __construct(
Expand Down
47 changes: 47 additions & 0 deletions src/Migrations/Version20250106150814.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/**
* Copyright 2024 SURFnet B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* @SuppressWarnings(PHPMD)
*/
final class Version20250106150814 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE public_key_credential_sources ADD backup_eligible TINYINT(1) DEFAULT NULL, ADD backup_status TINYINT(1) DEFAULT NULL, ADD uv_initialized TINYINT(1) DEFAULT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE public_key_credential_sources DROP backup_eligible, DROP backup_status, DROP uv_initialized');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/**
* Copyright 2024 SURFnet B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Test\Integration\Repository;

use Doctrine\ORM\EntityManager;
use Surfnet\Webauthn\Entity\PublicKeyCredentialSource;
use Surfnet\Webauthn\Entity\User;
use Surfnet\Webauthn\Repository\PublicKeyCredentialSourceRepository;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Uid\UuidV4;
use Webauthn\TrustPath\EmptyTrustPath;

class PublicKeyCredentialSourceRepositoryTest extends KernelTestCase
{
private ?EntityManager $entityManager;

protected function setUp(): void
{
$kernel = self::bootKernel();

$this->entityManager = $kernel->getContainer()
->get('doctrine')
->getManager();
}


protected function tearDown(): void
{
parent::tearDown();

$this->entityManager->close();
$this->entityManager = null;
}

public function testRepo()
{
/** @var PublicKeyCredentialSourceRepository $repo */
$repo = $this->entityManager->getRepository(PublicKeyCredentialSource::class);

$item = new PublicKeyCredentialSource(
'id',
'type',
['transports'],
'attestationType',
new EmptyTrustPath(),
UuidV4::v4(),
'credentialPublicKey',
'userHandle',
1,
'fmt'
);

$repo->saveCredentialSource($item);

$result = $repo->allForUser(new User('userHandle', 'foo', 'bar'));

$this->assertNotEmpty($result);
}

}
Loading