Skip to content
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: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ jobs:
- 'high'
- 'low'
php:
- '8.1'
- '8.2'
- '8.3'
- '8.4'
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
}
},
"require": {
"php": "^8.1",
"php": "^8.2",
"ext-gmp": "*",
"ext-hash": "*",
"ext-openssl": "*",
Expand All @@ -49,10 +49,10 @@
},
"require-dev": {
"mheap/phpunit-github-actions-printer": "^1.5",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/phpstan-strict-rules": "^2.0",
"phpunit/phpunit": "^9.6",
"phpstan/phpstan": "^2.0",
"phpunit/phpunit": "^11",
"squizlabs/php_codesniffer": "^3.5"
},
"scripts": {
Expand Down
14 changes: 6 additions & 8 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd"
bootstrap="tests/bootstrap.php"
executionOrder="depends,defects"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="false"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
failOnRisky="true"
failOnWarning="true"
verbose="true">
cacheDirectory=".phpunit.cache"
requireCoverageMetadata="true"
beStrictAboutCoverageMetadata="false">
<testsuites>
<testsuite name="default">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>

<coverage processUncoveredFiles="true">
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</source>
</phpunit>
53 changes: 27 additions & 26 deletions tests/ArrayBufferResponseParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,30 @@

namespace Firehed\WebAuthn;

/**
* @covers Firehed\WebAuthn\ArrayBufferResponseParser
*/
class ArrayBufferResponseParserTest extends \PHPUnit\Framework\TestCase
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use LogicException;

#[CoversClass(ArrayBufferResponseParser::class)]
class ArrayBufferResponseParserTest extends TestCase
{
/**
* Test the happy case for various known-good responses.
*
* @dataProvider goodVectors
*/
#[DataProvider('goodVectors')]
public function testParseCreateResponse(string $directory): void
{
$parser = new ArrayBufferResponseParser();
$registerResponse = $this->safeReadJsonFile("$directory/register.json");
$registerResponse = self::safeReadJsonFile("$directory/register.json");
$attestation = $parser->parseCreateResponse($registerResponse);

self::assertInstanceOf(CreateResponse::class, $attestation);
}

public function testParseCreateResponseWithTransports(): void
{
$response = $this->readFixture('touchid/register.json');
$response = self::readFixture('touchid/register.json');
$response['transports'] = ['internal', 'hybrid'];

$parser = new ArrayBufferResponseParser();
Expand All @@ -38,7 +40,7 @@ public function testParseCreateResponseWithTransports(): void

public function testParseCreateResponseWithInvalidTransports(): void
{
$response = $this->readFixture('touchid/register.json');
$response = self::readFixture('touchid/register.json');
$response['transports'] = ['invalid', 'usb'];

$parser = new ArrayBufferResponseParser();
Expand All @@ -49,9 +51,9 @@ public function testParseCreateResponseWithInvalidTransports(): void
}

/**
* @dataProvider badCreateResponses
* @param mixed[] $response
*/
#[DataProvider('badCreateResponses')]
public function testParseCreateResponseInputValidation(array $response): void
{
$parser = new ArrayBufferResponseParser();
Expand All @@ -60,9 +62,9 @@ public function testParseCreateResponseInputValidation(array $response): void
}

/**
* @dataProvider badGetResponses
* @param mixed[] $response
*/
#[DataProvider('badGetResponses')]
public function testParseGetResponseInputValidation(array $response): void
{
$parser = new ArrayBufferResponseParser();
Expand All @@ -73,7 +75,7 @@ public function testParseGetResponseInputValidation(array $response): void
public function testParseGetResponseHandlesEmptyUserHandle(): void
{
$parser = new ArrayBufferResponseParser();
$response = $this->readFixture('fido-u2f/login.json');
$response = self::readFixture('fido-u2f/login.json');
$assertion = $parser->parseGetResponse($response);

self::assertNull($assertion->getUserHandle());
Expand All @@ -82,7 +84,7 @@ public function testParseGetResponseHandlesEmptyUserHandle(): void
public function testParseGetResponseHandlesProvidedUserHandle(): void
{
$parser = new ArrayBufferResponseParser();
$response = $this->readFixture('touchid/login.json');
$response = self::readFixture('touchid/login.json');
$assertion = $parser->parseGetResponse($response);

self::assertSame('443945aa-8acc-4b84-f05f-ec8ef86e7c5d', $assertion->getUserHandle());
Expand All @@ -91,10 +93,10 @@ public function testParseGetResponseHandlesProvidedUserHandle(): void
/**
* @return array<mixed>[]
*/
public function badCreateResponses(): array
public static function badCreateResponses(): array
{
$makeVector = function (array $overrides): array {
$response = $this->readFixture('fido-u2f/register.json');
$response = self::readFixture('fido-u2f/register.json');
foreach ($overrides as $key => $value) {
if ($value === null) {
unset($response[$key]);
Expand All @@ -121,10 +123,10 @@ public function badCreateResponses(): array
/**
* @return array<mixed>[]
*/
public function badGetResponses(): array
public static function badGetResponses(): array
{
$makeVector = function (array $overrides): array {
$response = $this->readFixture('fido-u2f/login.json');
$response = self::readFixture('fido-u2f/login.json');
foreach ($overrides as $key => $value) {
if ($value === null) {
unset($response[$key]);
Expand Down Expand Up @@ -153,13 +155,12 @@ public function badGetResponses(): array

/**
* Test the happy case for various known-good responses.
*
* @dataProvider goodVectors
*/
#[DataProvider('goodVectors')]
public function testParseGetResponse(string $directory): void
{
$parser = new ArrayBufferResponseParser();
$loginResponse = $this->safeReadJsonFile("$directory/login.json");
$loginResponse = self::safeReadJsonFile("$directory/login.json");
$assertion = $parser->parseGetResponse($loginResponse);

self::assertInstanceOf(GetResponse::class, $assertion);
Expand All @@ -168,7 +169,7 @@ public function testParseGetResponse(string $directory): void
/**
* @return array{string}[]
*/
public function goodVectors(): array
public static function goodVectors(): array
{
$paths = glob(__DIR__ . '/fixtures/ArrayBuffer/*');
assert($paths !== false);
Expand All @@ -183,14 +184,14 @@ public function goodVectors(): array
/**
* @return mixed[]
*/
private function safeReadJsonFile(string $path): array
private static function safeReadJsonFile(string $path): array
{
if (!file_exists($path)) {
throw new \LogicException("$path is missing");
throw new LogicException("$path is missing");
}
$contents = file_get_contents($path);
if ($contents === false) {
throw new \LogicException("$path could not be read");
throw new LogicException("$path could not be read");
}
$data = json_decode($contents, true, flags: JSON_THROW_ON_ERROR);
assert(is_array($data));
Expand All @@ -200,8 +201,8 @@ private function safeReadJsonFile(string $path): array
/**
* @return mixed[]
*/
private function readFixture(string $relativePath): array
private static function readFixture(string $relativePath): array
{
return $this->safeReadJsonFile(__DIR__ . '/fixtures/ArrayBuffer/' . $relativePath);
return self::safeReadJsonFile(__DIR__ . '/fixtures/ArrayBuffer/' . $relativePath);
}
}
8 changes: 4 additions & 4 deletions tests/Attestations/AttestationObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Firehed\WebAuthn\Attestations;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Firehed\WebAuthn\BinaryString;

/**
* @covers Firehed\WebAuthn\Attestations\AttestationObject
*/
class AttestationObjectTest extends \PHPUnit\Framework\TestCase
#[CoversClass(AttestationObject::class)]
class AttestationObjectTest extends TestCase
{
public function testParsingCBOR(): void
{
Expand Down
14 changes: 8 additions & 6 deletions tests/AuthenticatorDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

namespace Firehed\WebAuthn;

/**
* @covers Firehed\WebAuthn\AuthenticatorData
*/
class AuthenticatorDataTest extends \PHPUnit\Framework\TestCase
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Throwable;

#[CoversClass(AuthenticatorData::class)]
class AuthenticatorDataTest extends TestCase
{
public function testParseAssertion(): void
{
Expand All @@ -31,7 +33,7 @@ public function testParseAssertion(): void
try {
$_ = $ad->getAttestedCredentialData();
self::fail('AuthData does not include an attested credential');
} catch (\Throwable) {
} catch (Throwable) {
}
}

Expand Down Expand Up @@ -95,7 +97,7 @@ public function testParseAssertionWithNoFlags(): void
try {
$_ = $ad->getAttestedCredentialData();
self::fail('AuthData does not include an attested credential');
} catch (\Throwable) {
} catch (Throwable) {
}
}
}
15 changes: 7 additions & 8 deletions tests/BinaryStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

namespace Firehed\WebAuthn;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use OutOfBoundsException;

/**
* @covers Firehed\WebAuthn\BinaryString
*/
class BinaryStringTest extends \PHPUnit\Framework\TestCase
#[CoversClass(BinaryString::class)]
class BinaryStringTest extends TestCase
{
private BinaryString $default;

Expand All @@ -33,9 +34,7 @@ public function testBinaryIsMasked(): void
}
}

/**
* @dataProvider equality
*/
#[DataProvider('equality')]
public function testEquals(BinaryString $lhs, BinaryString $rhs, bool $shouldMatch): void
{
self::assertSame($shouldMatch, $lhs->equals($rhs), 'lhs<->rhs');
Expand Down Expand Up @@ -108,7 +107,7 @@ public function testBase64UrlDecode(): void
/**
* @return array{BinaryString, BinaryString, bool}[]
*/
public function equality(): array
public static function equality(): array
{
return [
[new BinaryString('abc123'), new BinaryString('abc123'), true],
Expand Down
9 changes: 5 additions & 4 deletions tests/COSEKeyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

namespace Firehed\WebAuthn;

/**
* @covers Firehed\WebAuthn\COSEKey
*/
class COSEKeyTest extends \PHPUnit\Framework\TestCase
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

#[CoversClass(COSEKey::class)]
class COSEKeyTest extends TestCase
{
public function testKeyParsing(): void
{
Expand Down
9 changes: 5 additions & 4 deletions tests/ChallengeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

namespace Firehed\WebAuthn;

/**
* @covers Firehed\WebAuthn\Challenge
*/
class ChallengeTest extends \PHPUnit\Framework\TestCase
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

#[CoversClass(Challenge::class)]
class ChallengeTest extends TestCase
{
use ChallengeInterfaceTestTrait;

Expand Down
Loading
Loading