Skip to content

Commit 4822cb8

Browse files
committed
Merge up
2 parents 679ab72 + 36bf60a commit 4822cb8

File tree

13 files changed

+264
-6
lines changed

13 files changed

+264
-6
lines changed

ecs.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,8 @@
9595
__DIR__ . '/performance',
9696
__DIR__ . '/src',
9797
__DIR__ . '/tests',
98+
__DIR__ . '/ecs.php',
99+
__DIR__ . '/rector.php',
100+
__DIR__ . '/monorepo-builder.php',
98101
]);
99102
};

src/Bundle/JoseFramework/Serializer/JWESerializer.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ public function __construct(
2626
$this->serializerManager = $serializerManager;
2727
}
2828

29+
public function getSupportedTypes(?string $format): array
30+
{
31+
return [
32+
JWE::class => class_exists(JWESerializerManager::class) && $this->formatSupported($format),
33+
];
34+
}
35+
2936
public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool
3037
{
3138
return $type === JWE::class

src/Bundle/JoseFramework/Serializer/JWSSerializer.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ public function __construct(
2626
$this->serializerManager = $serializerManager;
2727
}
2828

29+
public function getSupportedTypes(?string $format): array
30+
{
31+
return [
32+
JWS::class => class_exists(JWSSerializerManager::class) && $this->formatSupported($format),
33+
];
34+
}
35+
2936
public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool
3037
{
3138
return $type === JWS::class
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Jose\Component\Checker;
6+
7+
use function call_user_func;
8+
use InvalidArgumentException;
9+
use function is_callable;
10+
11+
/**
12+
* @see \Jose\Tests\Component\Checker\CallableCheckerTest
13+
*/
14+
final class CallableChecker implements ClaimChecker, HeaderChecker
15+
{
16+
/**
17+
* @param string $key The claim or header parameter name to check.
18+
* @param callable(mixed $value): bool $callable The callable function that will be invoked.
19+
*/
20+
public function __construct(
21+
private readonly string $key,
22+
private $callable,
23+
private readonly bool $protectedHeaderOnly = true
24+
) {
25+
if (! is_callable($this->callable)) { // @phpstan-ignore-line
26+
throw new InvalidArgumentException('The $callable argument must be a callable.');
27+
}
28+
}
29+
30+
public function checkClaim(mixed $value): void
31+
{
32+
if (call_user_func($this->callable, $value) !== true) {
33+
throw new InvalidClaimException(sprintf('The "%s" claim is invalid.', $this->key), $this->key, $value);
34+
}
35+
}
36+
37+
public function supportedClaim(): string
38+
{
39+
return $this->key;
40+
}
41+
42+
public function checkHeader(mixed $value): void
43+
{
44+
if (call_user_func($this->callable, $value) !== true) {
45+
throw new InvalidHeaderException(sprintf('The "%s" header is invalid.', $this->key), $this->key, $value);
46+
}
47+
}
48+
49+
public function supportedHeader(): string
50+
{
51+
return $this->key;
52+
}
53+
54+
public function protectedHeaderOnly(): bool
55+
{
56+
return $this->protectedHeaderOnly;
57+
}
58+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Jose\Component\Checker;
6+
7+
/**
8+
* @see \Jose\Tests\Component\Checker\IsEqualCheckerTest
9+
*/
10+
final class IsEqualChecker implements ClaimChecker, HeaderChecker
11+
{
12+
/**
13+
* @param string $key The claim or header parameter name to check.
14+
* @param mixed $value The expected value.
15+
* @param bool $protectedHeaderOnly [optional] Whether the header parameter MUST be protected.
16+
* This option has no effect for claim checkers.
17+
*/
18+
public function __construct(
19+
private readonly string $key,
20+
private readonly mixed $value,
21+
private readonly bool $protectedHeaderOnly = true
22+
) {
23+
}
24+
25+
public function checkClaim(mixed $value): void
26+
{
27+
if ($value !== $this->value) {
28+
throw new InvalidClaimException(sprintf('The "%s" claim is invalid.', $this->key), $this->key, $value);
29+
}
30+
}
31+
32+
public function supportedClaim(): string
33+
{
34+
return $this->key;
35+
}
36+
37+
public function checkHeader(mixed $value): void
38+
{
39+
if ($value !== $this->value) {
40+
throw new InvalidHeaderException(sprintf('The "%s" header is invalid.', $this->key), $this->key, $value);
41+
}
42+
}
43+
44+
public function supportedHeader(): string
45+
{
46+
return $this->key;
47+
}
48+
49+
public function protectedHeaderOnly(): bool
50+
{
51+
return $this->protectedHeaderOnly;
52+
}
53+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Jose\Tests\Component\Checker;
6+
7+
use InvalidArgumentException;
8+
use Jose\Component\Checker\CallableChecker;
9+
use Jose\Component\Checker\InvalidClaimException;
10+
use Jose\Component\Checker\InvalidHeaderException;
11+
use PHPUnit\Framework\Attributes\Test;
12+
use PHPUnit\Framework\TestCase;
13+
14+
/**
15+
* @internal
16+
*/
17+
final class CallableCheckerTest extends TestCase
18+
{
19+
#[Test]
20+
public function theCallableIsCallable(): void
21+
{
22+
$this->expectException(InvalidArgumentException::class);
23+
$this->expectExceptionMessage('The $callable argument must be a callable.');
24+
25+
new CallableChecker('foo', 'not_a_callable');
26+
}
27+
28+
#[Test]
29+
public function theCallableDoesNotReturnABoolean(): void
30+
{
31+
$this->expectException(InvalidClaimException::class);
32+
33+
$checker = new CallableChecker('foo', fn (mixed $value) => 1);
34+
$checker->checkClaim('baz');
35+
36+
$this->expectException(InvalidHeaderException::class);
37+
38+
$checker = new CallableChecker('foo', fn (mixed $value) => 0);
39+
$checker->checkHeader('baz');
40+
}
41+
42+
#[Test]
43+
public function theClaimIsInvalid(): void
44+
{
45+
$this->expectException(InvalidClaimException::class);
46+
47+
$checker = new CallableChecker('foo', fn (mixed $value) => $value === 'bar');
48+
$checker->checkClaim('baz');
49+
}
50+
51+
#[Test]
52+
public function theHeaderIsInvalid(): void
53+
{
54+
$this->expectException(InvalidHeaderException::class);
55+
56+
$checker = new CallableChecker('foo', fn (mixed $value) => $value === 'bar');
57+
$checker->checkHeader('baz');
58+
}
59+
60+
#[Test]
61+
public function theClaimIsSupported(): void
62+
{
63+
$checker = new CallableChecker('foo', fn (mixed $value) => $value === 'bar');
64+
$checker->checkClaim('bar');
65+
66+
static::assertSame('foo', $checker->supportedClaim());
67+
}
68+
69+
#[Test]
70+
public function theHeaderIsSupported(): void
71+
{
72+
$checker = new CallableChecker('foo', fn (mixed $value) => $value === 'bar');
73+
$checker->checkHeader('bar');
74+
75+
static::assertSame('foo', $checker->supportedHeader());
76+
}
77+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Jose\Tests\Component\Checker;
6+
7+
use Jose\Component\Checker\InvalidClaimException;
8+
use Jose\Component\Checker\InvalidHeaderException;
9+
use Jose\Component\Checker\IsEqualChecker;
10+
use PHPUnit\Framework\Attributes\Test;
11+
use PHPUnit\Framework\TestCase;
12+
13+
/**
14+
* @internal
15+
*/
16+
final class IsEqualCheckerTest extends TestCase
17+
{
18+
#[Test]
19+
public function theClaimIsInvalid(): void
20+
{
21+
$this->expectException(InvalidClaimException::class);
22+
23+
$checker = new IsEqualChecker('foo', 'bar');
24+
$checker->checkClaim('baz');
25+
}
26+
27+
#[Test]
28+
public function theHeaderIsInvalid(): void
29+
{
30+
$this->expectException(InvalidHeaderException::class);
31+
32+
$checker = new IsEqualChecker('foo', 'bar');
33+
$checker->checkHeader('baz');
34+
}
35+
36+
#[Test]
37+
public function theClaimIsSupported(): void
38+
{
39+
$checker = new IsEqualChecker('foo', 'bar');
40+
$checker->checkClaim('bar');
41+
static::assertSame('foo', $checker->supportedClaim());
42+
}
43+
44+
#[Test]
45+
public function theHeaderIsSupported(): void
46+
{
47+
$checker = new IsEqualChecker('foo', 'bar');
48+
$checker->checkHeader('bar');
49+
static::assertSame('foo', $checker->supportedHeader());
50+
}
51+
}

tests/Component/Encryption/EncrypterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
use InvalidArgumentException;
88
use Jose\Component\Core\JWK;
99
use Jose\Component\Core\JWKSet;
10+
use const JSON_THROW_ON_ERROR;
1011
use ParagonIE\ConstantTime\Base64UrlSafe;
1112
use PHPUnit\Framework\Attributes\Test;
12-
use const JSON_THROW_ON_ERROR;
1313

1414
/**
1515
* @internal
1616
*/
17-
final class EncrypterTest extends EncryptionTestCase
17+
final class EncrypterTestCase extends EncryptionTestCase
1818
{
1919
#[Test]
2020
public function encryptWithJWTInput(): void

tests/Component/KeyManagement/CertificateTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ public function certificateConversionPkcs8(): void
9393
]);
9494
}
9595

96-
#[DataProvider('dataLoadCertificate')]
9796
#[Test]
97+
#[DataProvider('dataLoadCertificate')]
9898
public function loadCertificate(string $file, array $expected_values): void
9999
{
100100
$result = KeyConverter::loadKeyFromCertificateFile($file);

tests/Component/Signature/JWSFlattenedTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PHPUnit\Framework\Attributes\Test;
88
use const JSON_THROW_ON_ERROR;
9+
use PHPUnit\Framework\Attributes\Test;
910

1011
/**
1112
* @internal

0 commit comments

Comments
 (0)