From da5f1cc631bab97302b3e71df5d0f0ba7ca0d63e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Fri, 20 Nov 2020 21:55:47 +0100 Subject: [PATCH 1/3] Rename method that returns the algorithm ID --- src/Signer.php | 2 +- src/Signer/Ecdsa/Sha256.php | 2 +- src/Signer/Ecdsa/Sha384.php | 2 +- src/Signer/Ecdsa/Sha512.php | 2 +- src/Signer/Hmac/Sha256.php | 2 +- src/Signer/Hmac/Sha384.php | 2 +- src/Signer/Hmac/Sha512.php | 2 +- src/Signer/None.php | 2 +- src/Signer/Rsa/Sha256.php | 2 +- src/Signer/Rsa/Sha384.php | 2 +- src/Signer/Rsa/Sha512.php | 2 +- src/Token/Builder.php | 2 +- src/Validation/Constraint/SignedWith.php | 2 +- test/unit/Signer/Ecdsa/Sha256Test.php | 6 +++--- test/unit/Signer/Ecdsa/Sha384Test.php | 6 +++--- test/unit/Signer/Ecdsa/Sha512Test.php | 6 +++--- test/unit/Signer/EcdsaTest.php | 2 +- test/unit/Signer/Hmac/Sha256Test.php | 6 +++--- test/unit/Signer/Hmac/Sha384Test.php | 6 +++--- test/unit/Signer/Hmac/Sha512Test.php | 6 +++--- test/unit/Signer/HmacTest.php | 2 +- test/unit/Signer/NoneTest.php | 6 +++--- test/unit/Signer/Rsa/Sha256Test.php | 6 +++--- test/unit/Signer/Rsa/Sha384Test.php | 6 +++--- test/unit/Signer/Rsa/Sha512Test.php | 6 +++--- test/unit/Signer/RsaTest.php | 2 +- test/unit/Token/BuilderTest.php | 2 +- test/unit/Validation/Constraint/SignedWithTest.php | 2 +- 28 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/Signer.php b/src/Signer.php index d018f844..71e9296b 100644 --- a/src/Signer.php +++ b/src/Signer.php @@ -13,7 +13,7 @@ interface Signer /** * Returns the algorithm id */ - public function getAlgorithmId(): string; + public function algorithmId(): string; /** * Creates a hash for the given payload diff --git a/src/Signer/Ecdsa/Sha256.php b/src/Signer/Ecdsa/Sha256.php index 46622e1c..3d0e32a4 100644 --- a/src/Signer/Ecdsa/Sha256.php +++ b/src/Signer/Ecdsa/Sha256.php @@ -9,7 +9,7 @@ final class Sha256 extends Ecdsa { - public function getAlgorithmId(): string + public function algorithmId(): string { return 'ES256'; } diff --git a/src/Signer/Ecdsa/Sha384.php b/src/Signer/Ecdsa/Sha384.php index b5315beb..3dd806c1 100644 --- a/src/Signer/Ecdsa/Sha384.php +++ b/src/Signer/Ecdsa/Sha384.php @@ -9,7 +9,7 @@ final class Sha384 extends Ecdsa { - public function getAlgorithmId(): string + public function algorithmId(): string { return 'ES384'; } diff --git a/src/Signer/Ecdsa/Sha512.php b/src/Signer/Ecdsa/Sha512.php index 7ff198b2..15af6190 100644 --- a/src/Signer/Ecdsa/Sha512.php +++ b/src/Signer/Ecdsa/Sha512.php @@ -9,7 +9,7 @@ final class Sha512 extends Ecdsa { - public function getAlgorithmId(): string + public function algorithmId(): string { return 'ES512'; } diff --git a/src/Signer/Hmac/Sha256.php b/src/Signer/Hmac/Sha256.php index bb593793..759dc590 100644 --- a/src/Signer/Hmac/Sha256.php +++ b/src/Signer/Hmac/Sha256.php @@ -7,7 +7,7 @@ final class Sha256 extends Hmac { - public function getAlgorithmId(): string + public function algorithmId(): string { return 'HS256'; } diff --git a/src/Signer/Hmac/Sha384.php b/src/Signer/Hmac/Sha384.php index 5809a0b2..36cd8735 100644 --- a/src/Signer/Hmac/Sha384.php +++ b/src/Signer/Hmac/Sha384.php @@ -7,7 +7,7 @@ final class Sha384 extends Hmac { - public function getAlgorithmId(): string + public function algorithmId(): string { return 'HS384'; } diff --git a/src/Signer/Hmac/Sha512.php b/src/Signer/Hmac/Sha512.php index af490081..12f121c9 100644 --- a/src/Signer/Hmac/Sha512.php +++ b/src/Signer/Hmac/Sha512.php @@ -7,7 +7,7 @@ final class Sha512 extends Hmac { - public function getAlgorithmId(): string + public function algorithmId(): string { return 'HS512'; } diff --git a/src/Signer/None.php b/src/Signer/None.php index 8cd7cfa3..4e6ecb17 100644 --- a/src/Signer/None.php +++ b/src/Signer/None.php @@ -7,7 +7,7 @@ final class None implements Signer { - public function getAlgorithmId(): string + public function algorithmId(): string { return 'none'; } diff --git a/src/Signer/Rsa/Sha256.php b/src/Signer/Rsa/Sha256.php index cb26bbf7..d7878e95 100644 --- a/src/Signer/Rsa/Sha256.php +++ b/src/Signer/Rsa/Sha256.php @@ -9,7 +9,7 @@ final class Sha256 extends Rsa { - public function getAlgorithmId(): string + public function algorithmId(): string { return 'RS256'; } diff --git a/src/Signer/Rsa/Sha384.php b/src/Signer/Rsa/Sha384.php index 255711f0..99fa4701 100644 --- a/src/Signer/Rsa/Sha384.php +++ b/src/Signer/Rsa/Sha384.php @@ -9,7 +9,7 @@ final class Sha384 extends Rsa { - public function getAlgorithmId(): string + public function algorithmId(): string { return 'RS384'; } diff --git a/src/Signer/Rsa/Sha512.php b/src/Signer/Rsa/Sha512.php index d3ea087f..c2f0c48c 100644 --- a/src/Signer/Rsa/Sha512.php +++ b/src/Signer/Rsa/Sha512.php @@ -9,7 +9,7 @@ final class Sha512 extends Rsa { - public function getAlgorithmId(): string + public function algorithmId(): string { return 'RS512'; } diff --git a/src/Token/Builder.php b/src/Token/Builder.php index 2c6c2bf3..61e3d153 100644 --- a/src/Token/Builder.php +++ b/src/Token/Builder.php @@ -111,7 +111,7 @@ private function encode(array $items): string public function getToken(Signer $signer, Key $key): Plain { $headers = $this->headers; - $headers['alg'] = $signer->getAlgorithmId(); + $headers['alg'] = $signer->algorithmId(); $encodedHeaders = $this->encode($headers); $encodedClaims = $this->encode($this->claimFormatter->formatClaims($this->claims)); diff --git a/src/Validation/Constraint/SignedWith.php b/src/Validation/Constraint/SignedWith.php index 8c0a2aca..56acb2ef 100644 --- a/src/Validation/Constraint/SignedWith.php +++ b/src/Validation/Constraint/SignedWith.php @@ -25,7 +25,7 @@ public function assert(Token $token): void throw new ConstraintViolation('You should pass a plain token'); } - if ($token->headers()->get('alg') !== $this->signer->getAlgorithmId()) { + if ($token->headers()->get('alg') !== $this->signer->algorithmId()) { throw new ConstraintViolation('Token signer mismatch'); } diff --git a/test/unit/Signer/Ecdsa/Sha256Test.php b/test/unit/Signer/Ecdsa/Sha256Test.php index 1404866d..d4758c4f 100644 --- a/test/unit/Signer/Ecdsa/Sha256Test.php +++ b/test/unit/Signer/Ecdsa/Sha256Test.php @@ -28,13 +28,13 @@ public function createShouldReturnAValidInstance(): void /** * @test * - * @covers ::getAlgorithmId + * @covers ::algorithmId * * @uses \Lcobucci\JWT\Signer\Ecdsa */ - public function getAlgorithmIdMustBeCorrect(): void + public function algorithmIdMustBeCorrect(): void { - self::assertSame('ES256', $this->getSigner()->getAlgorithmId()); + self::assertSame('ES256', $this->getSigner()->algorithmId()); } /** diff --git a/test/unit/Signer/Ecdsa/Sha384Test.php b/test/unit/Signer/Ecdsa/Sha384Test.php index bbab90a1..cf8fc0ea 100644 --- a/test/unit/Signer/Ecdsa/Sha384Test.php +++ b/test/unit/Signer/Ecdsa/Sha384Test.php @@ -28,13 +28,13 @@ public function createShouldReturnAValidInstance(): void /** * @test * - * @covers ::getAlgorithmId + * @covers ::algorithmId * * @uses \Lcobucci\JWT\Signer\Ecdsa */ - public function getAlgorithmIdMustBeCorrect(): void + public function algorithmIdMustBeCorrect(): void { - self::assertSame('ES384', $this->getSigner()->getAlgorithmId()); + self::assertSame('ES384', $this->getSigner()->algorithmId()); } /** diff --git a/test/unit/Signer/Ecdsa/Sha512Test.php b/test/unit/Signer/Ecdsa/Sha512Test.php index 5b3521c5..325d4cb2 100644 --- a/test/unit/Signer/Ecdsa/Sha512Test.php +++ b/test/unit/Signer/Ecdsa/Sha512Test.php @@ -28,13 +28,13 @@ public function createShouldReturnAValidInstance(): void /** * @test * - * @covers ::getAlgorithmId + * @covers ::algorithmId * * @uses \Lcobucci\JWT\Signer\Ecdsa */ - public function getAlgorithmIdMustBeCorrect(): void + public function algorithmIdMustBeCorrect(): void { - self::assertSame('ES512', $this->getSigner()->getAlgorithmId()); + self::assertSame('ES512', $this->getSigner()->algorithmId()); } /** diff --git a/test/unit/Signer/EcdsaTest.php b/test/unit/Signer/EcdsaTest.php index f230c8bc..9a3f2659 100644 --- a/test/unit/Signer/EcdsaTest.php +++ b/test/unit/Signer/EcdsaTest.php @@ -37,7 +37,7 @@ private function getSigner(): Ecdsa $signer->method('getAlgorithm') ->willReturn(OPENSSL_ALGO_SHA256); - $signer->method('getAlgorithmId') + $signer->method('algorithmId') ->willReturn('ES256'); $signer->method('getKeyLength') diff --git a/test/unit/Signer/Hmac/Sha256Test.php b/test/unit/Signer/Hmac/Sha256Test.php index cbb95138..e75f92a4 100644 --- a/test/unit/Signer/Hmac/Sha256Test.php +++ b/test/unit/Signer/Hmac/Sha256Test.php @@ -11,13 +11,13 @@ final class Sha256Test extends TestCase /** * @test * - * @covers ::getAlgorithmId + * @covers ::algorithmId */ - public function getAlgorithmIdMustBeCorrect(): void + public function algorithmIdMustBeCorrect(): void { $signer = new Sha256(); - self::assertEquals('HS256', $signer->getAlgorithmId()); + self::assertEquals('HS256', $signer->algorithmId()); } /** diff --git a/test/unit/Signer/Hmac/Sha384Test.php b/test/unit/Signer/Hmac/Sha384Test.php index 31065acc..bc9079f0 100644 --- a/test/unit/Signer/Hmac/Sha384Test.php +++ b/test/unit/Signer/Hmac/Sha384Test.php @@ -11,13 +11,13 @@ final class Sha384Test extends TestCase /** * @test * - * @covers ::getAlgorithmId + * @covers ::algorithmId */ - public function getAlgorithmIdMustBeCorrect(): void + public function algorithmIdMustBeCorrect(): void { $signer = new Sha384(); - self::assertEquals('HS384', $signer->getAlgorithmId()); + self::assertEquals('HS384', $signer->algorithmId()); } /** diff --git a/test/unit/Signer/Hmac/Sha512Test.php b/test/unit/Signer/Hmac/Sha512Test.php index 6219cb80..12ccd690 100644 --- a/test/unit/Signer/Hmac/Sha512Test.php +++ b/test/unit/Signer/Hmac/Sha512Test.php @@ -11,13 +11,13 @@ final class Sha512Test extends TestCase /** * @test * - * @covers ::getAlgorithmId + * @covers ::algorithmId */ - public function getAlgorithmIdMustBeCorrect(): void + public function algorithmIdMustBeCorrect(): void { $signer = new Sha512(); - self::assertEquals('HS512', $signer->getAlgorithmId()); + self::assertEquals('HS512', $signer->algorithmId()); } /** diff --git a/test/unit/Signer/HmacTest.php b/test/unit/Signer/HmacTest.php index c286707e..1395fd44 100644 --- a/test/unit/Signer/HmacTest.php +++ b/test/unit/Signer/HmacTest.php @@ -21,7 +21,7 @@ public function initializeDependencies(): void $this->signer = $this->getMockForAbstractClass(Hmac::class); $this->signer->expects(self::any()) - ->method('getAlgorithmId') + ->method('algorithmId') ->willReturn('TEST123'); $this->signer->expects(self::any()) diff --git a/test/unit/Signer/NoneTest.php b/test/unit/Signer/NoneTest.php index c38028d0..05e6c71d 100644 --- a/test/unit/Signer/NoneTest.php +++ b/test/unit/Signer/NoneTest.php @@ -12,13 +12,13 @@ final class NoneTest extends TestCase /** * @test * - * @covers ::getAlgorithmId + * @covers ::algorithmId */ - public function getAlgorithmIdMustBeCorrect(): void + public function algorithmIdMustBeCorrect(): void { $signer = new None(); - self::assertEquals('none', $signer->getAlgorithmId()); + self::assertEquals('none', $signer->algorithmId()); } /** diff --git a/test/unit/Signer/Rsa/Sha256Test.php b/test/unit/Signer/Rsa/Sha256Test.php index 92ad5f86..61cebff6 100644 --- a/test/unit/Signer/Rsa/Sha256Test.php +++ b/test/unit/Signer/Rsa/Sha256Test.php @@ -13,13 +13,13 @@ final class Sha256Test extends TestCase /** * @test * - * @covers ::getAlgorithmId + * @covers ::algorithmId */ - public function getAlgorithmIdMustBeCorrect(): void + public function algorithmIdMustBeCorrect(): void { $signer = new Sha256(); - self::assertEquals('RS256', $signer->getAlgorithmId()); + self::assertEquals('RS256', $signer->algorithmId()); } /** diff --git a/test/unit/Signer/Rsa/Sha384Test.php b/test/unit/Signer/Rsa/Sha384Test.php index 1f678479..e6297a0f 100644 --- a/test/unit/Signer/Rsa/Sha384Test.php +++ b/test/unit/Signer/Rsa/Sha384Test.php @@ -13,13 +13,13 @@ final class Sha384Test extends TestCase /** * @test * - * @covers ::getAlgorithmId + * @covers ::algorithmId */ - public function getAlgorithmIdMustBeCorrect(): void + public function algorithmIdMustBeCorrect(): void { $signer = new Sha384(); - self::assertEquals('RS384', $signer->getAlgorithmId()); + self::assertEquals('RS384', $signer->algorithmId()); } /** diff --git a/test/unit/Signer/Rsa/Sha512Test.php b/test/unit/Signer/Rsa/Sha512Test.php index 276d3703..57ca8c98 100644 --- a/test/unit/Signer/Rsa/Sha512Test.php +++ b/test/unit/Signer/Rsa/Sha512Test.php @@ -13,13 +13,13 @@ final class Sha512Test extends TestCase /** * @test * - * @covers ::getAlgorithmId + * @covers ::algorithmId */ - public function getAlgorithmIdMustBeCorrect(): void + public function algorithmIdMustBeCorrect(): void { $signer = new Sha512(); - self::assertEquals('RS512', $signer->getAlgorithmId()); + self::assertEquals('RS512', $signer->algorithmId()); } /** diff --git a/test/unit/Signer/RsaTest.php b/test/unit/Signer/RsaTest.php index 9c73e96f..0605a907 100644 --- a/test/unit/Signer/RsaTest.php +++ b/test/unit/Signer/RsaTest.php @@ -179,7 +179,7 @@ private function getSigner(): Rsa $signer->method('getAlgorithm') ->willReturn(OPENSSL_ALGO_SHA256); - $signer->method('getAlgorithmId') + $signer->method('algorithmId') ->willReturn('RS256'); return $signer; diff --git a/test/unit/Token/BuilderTest.php b/test/unit/Token/BuilderTest.php index c1282019..31ba8b9f 100644 --- a/test/unit/Token/BuilderTest.php +++ b/test/unit/Token/BuilderTest.php @@ -29,7 +29,7 @@ public function initializeDependencies(): void { $this->encoder = $this->createMock(Encoder::class); $this->signer = $this->createMock(Signer::class); - $this->signer->method('getAlgorithmId')->willReturn('RS256'); + $this->signer->method('algorithmId')->willReturn('RS256'); } /** diff --git a/test/unit/Validation/Constraint/SignedWithTest.php b/test/unit/Validation/Constraint/SignedWithTest.php index 867aaa79..a045142d 100644 --- a/test/unit/Validation/Constraint/SignedWithTest.php +++ b/test/unit/Validation/Constraint/SignedWithTest.php @@ -21,7 +21,7 @@ final class SignedWithTest extends ConstraintTestCase public function createDependencies(): void { $this->signer = $this->createMock(Signer::class); - $this->signer->method('getAlgorithmId')->willReturn('RS256'); + $this->signer->method('algorithmId')->willReturn('RS256'); $this->key = Signer\Key\InMemory::plainText('123'); $this->signature = new Signature('1234', '5678'); From 9a93f66f78cb20b3bc81ac236418470a7e50f616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Fri, 20 Nov 2020 22:02:25 +0100 Subject: [PATCH 2/3] Rename signer getters --- src/Signer/Ecdsa.php | 8 ++++---- src/Signer/Ecdsa/Sha256.php | 4 ++-- src/Signer/Ecdsa/Sha384.php | 4 ++-- src/Signer/Ecdsa/Sha512.php | 4 ++-- src/Signer/Hmac.php | 4 ++-- src/Signer/Hmac/Sha256.php | 2 +- src/Signer/Hmac/Sha384.php | 2 +- src/Signer/Hmac/Sha512.php | 2 +- src/Signer/OpenSSL.php | 10 +++++----- src/Signer/Rsa.php | 2 +- src/Signer/Rsa/Sha256.php | 2 +- src/Signer/Rsa/Sha384.php | 2 +- src/Signer/Rsa/Sha512.php | 2 +- test/unit/Signer/Ecdsa/Sha256Test.php | 12 ++++++------ test/unit/Signer/Ecdsa/Sha384Test.php | 12 ++++++------ test/unit/Signer/Ecdsa/Sha512Test.php | 12 ++++++------ test/unit/Signer/EcdsaTest.php | 12 ++++++------ test/unit/Signer/Hmac/Sha256Test.php | 6 +++--- test/unit/Signer/Hmac/Sha384Test.php | 6 +++--- test/unit/Signer/Hmac/Sha512Test.php | 6 +++--- test/unit/Signer/HmacTest.php | 2 +- test/unit/Signer/Rsa/Sha256Test.php | 6 +++--- test/unit/Signer/Rsa/Sha384Test.php | 6 +++--- test/unit/Signer/Rsa/Sha512Test.php | 6 +++--- test/unit/Signer/RsaTest.php | 10 +++++----- 25 files changed, 72 insertions(+), 72 deletions(-) diff --git a/src/Signer/Ecdsa.php b/src/Signer/Ecdsa.php index 0498d816..f8ada157 100644 --- a/src/Signer/Ecdsa.php +++ b/src/Signer/Ecdsa.php @@ -26,20 +26,20 @@ final public function sign(string $payload, Key $key): string { return $this->converter->fromAsn1( $this->createSignature($key->contents(), $key->passphrase(), $payload), - $this->getKeyLength() + $this->keyLength() ); } final public function verify(string $expected, string $payload, Key $key): bool { return $this->verifySignature( - $this->converter->toAsn1($expected, $this->getKeyLength()), + $this->converter->toAsn1($expected, $this->keyLength()), $payload, $key->contents() ); } - final public function getKeyType(): int + final public function keyType(): int { return OPENSSL_KEYTYPE_EC; } @@ -49,5 +49,5 @@ final public function getKeyType(): int * * @internal */ - abstract public function getKeyLength(): int; + abstract public function keyLength(): int; } diff --git a/src/Signer/Ecdsa/Sha256.php b/src/Signer/Ecdsa/Sha256.php index 3d0e32a4..36f6ec12 100644 --- a/src/Signer/Ecdsa/Sha256.php +++ b/src/Signer/Ecdsa/Sha256.php @@ -14,12 +14,12 @@ public function algorithmId(): string return 'ES256'; } - public function getAlgorithm(): int + public function algorithm(): int { return OPENSSL_ALGO_SHA256; } - public function getKeyLength(): int + public function keyLength(): int { return 64; } diff --git a/src/Signer/Ecdsa/Sha384.php b/src/Signer/Ecdsa/Sha384.php index 3dd806c1..d3c5dbce 100644 --- a/src/Signer/Ecdsa/Sha384.php +++ b/src/Signer/Ecdsa/Sha384.php @@ -14,12 +14,12 @@ public function algorithmId(): string return 'ES384'; } - public function getAlgorithm(): int + public function algorithm(): int { return OPENSSL_ALGO_SHA384; } - public function getKeyLength(): int + public function keyLength(): int { return 96; } diff --git a/src/Signer/Ecdsa/Sha512.php b/src/Signer/Ecdsa/Sha512.php index 15af6190..1495d13b 100644 --- a/src/Signer/Ecdsa/Sha512.php +++ b/src/Signer/Ecdsa/Sha512.php @@ -14,12 +14,12 @@ public function algorithmId(): string return 'ES512'; } - public function getAlgorithm(): int + public function algorithm(): int { return OPENSSL_ALGO_SHA512; } - public function getKeyLength(): int + public function keyLength(): int { return 132; } diff --git a/src/Signer/Hmac.php b/src/Signer/Hmac.php index ecc8cfd7..05b46bcb 100644 --- a/src/Signer/Hmac.php +++ b/src/Signer/Hmac.php @@ -12,7 +12,7 @@ abstract class Hmac implements Signer { final public function sign(string $payload, Key $key): string { - return hash_hmac($this->getAlgorithm(), $payload, $key->contents(), true); + return hash_hmac($this->algorithm(), $payload, $key->contents(), true); } final public function verify(string $expected, string $payload, Key $key): bool @@ -20,5 +20,5 @@ final public function verify(string $expected, string $payload, Key $key): bool return hash_equals($expected, $this->sign($payload, $key)); } - abstract public function getAlgorithm(): string; + abstract public function algorithm(): string; } diff --git a/src/Signer/Hmac/Sha256.php b/src/Signer/Hmac/Sha256.php index 759dc590..4be692e5 100644 --- a/src/Signer/Hmac/Sha256.php +++ b/src/Signer/Hmac/Sha256.php @@ -12,7 +12,7 @@ public function algorithmId(): string return 'HS256'; } - public function getAlgorithm(): string + public function algorithm(): string { return 'sha256'; } diff --git a/src/Signer/Hmac/Sha384.php b/src/Signer/Hmac/Sha384.php index 36cd8735..4cf044ee 100644 --- a/src/Signer/Hmac/Sha384.php +++ b/src/Signer/Hmac/Sha384.php @@ -12,7 +12,7 @@ public function algorithmId(): string return 'HS384'; } - public function getAlgorithm(): string + public function algorithm(): string { return 'sha384'; } diff --git a/src/Signer/Hmac/Sha512.php b/src/Signer/Hmac/Sha512.php index 12f121c9..b9ff72c2 100644 --- a/src/Signer/Hmac/Sha512.php +++ b/src/Signer/Hmac/Sha512.php @@ -12,7 +12,7 @@ public function algorithmId(): string return 'HS512'; } - public function getAlgorithm(): string + public function algorithm(): string { return 'sha512'; } diff --git a/src/Signer/OpenSSL.php b/src/Signer/OpenSSL.php index 1d361231..b030e75a 100644 --- a/src/Signer/OpenSSL.php +++ b/src/Signer/OpenSSL.php @@ -35,7 +35,7 @@ final protected function createSignature( try { $signature = ''; - if (! openssl_sign($payload, $signature, $key, $this->getAlgorithm())) { + if (! openssl_sign($payload, $signature, $key, $this->algorithm())) { $error = openssl_error_string(); assert(is_string($error)); @@ -68,7 +68,7 @@ final protected function verifySignature( string $pem ): bool { $key = $this->getPublicKey($pem); - $result = openssl_verify($payload, $expected, $key, $this->getAlgorithm()); + $result = openssl_verify($payload, $expected, $key, $this->algorithm()); $this->freeKey($key); return $result === 1; @@ -106,7 +106,7 @@ private function validateKey($key): void $details = openssl_pkey_get_details($key); assert(is_array($details)); - if (! array_key_exists('key', $details) || $details['type'] !== $this->getKeyType()) { + if (! array_key_exists('key', $details) || $details['type'] !== $this->keyType()) { throw InvalidKeyProvided::incompatibleKey(); } } @@ -126,12 +126,12 @@ private function freeKey($key): void * * @internal */ - abstract public function getKeyType(): int; + abstract public function keyType(): int; /** * Returns which algorithm to be used to create/verify the signature (using OpenSSL constants) * * @internal */ - abstract public function getAlgorithm(): int; + abstract public function algorithm(): int; } diff --git a/src/Signer/Rsa.php b/src/Signer/Rsa.php index 16862e7d..ff54dd32 100644 --- a/src/Signer/Rsa.php +++ b/src/Signer/Rsa.php @@ -17,7 +17,7 @@ final public function verify(string $expected, string $payload, Key $key): bool return $this->verifySignature($expected, $payload, $key->contents()); } - final public function getKeyType(): int + final public function keyType(): int { return OPENSSL_KEYTYPE_RSA; } diff --git a/src/Signer/Rsa/Sha256.php b/src/Signer/Rsa/Sha256.php index d7878e95..9e56c70f 100644 --- a/src/Signer/Rsa/Sha256.php +++ b/src/Signer/Rsa/Sha256.php @@ -14,7 +14,7 @@ public function algorithmId(): string return 'RS256'; } - public function getAlgorithm(): int + public function algorithm(): int { return OPENSSL_ALGO_SHA256; } diff --git a/src/Signer/Rsa/Sha384.php b/src/Signer/Rsa/Sha384.php index 99fa4701..99ff3698 100644 --- a/src/Signer/Rsa/Sha384.php +++ b/src/Signer/Rsa/Sha384.php @@ -14,7 +14,7 @@ public function algorithmId(): string return 'RS384'; } - public function getAlgorithm(): int + public function algorithm(): int { return OPENSSL_ALGO_SHA384; } diff --git a/src/Signer/Rsa/Sha512.php b/src/Signer/Rsa/Sha512.php index c2f0c48c..1ddd1930 100644 --- a/src/Signer/Rsa/Sha512.php +++ b/src/Signer/Rsa/Sha512.php @@ -14,7 +14,7 @@ public function algorithmId(): string return 'RS512'; } - public function getAlgorithm(): int + public function algorithm(): int { return OPENSSL_ALGO_SHA512; } diff --git a/test/unit/Signer/Ecdsa/Sha256Test.php b/test/unit/Signer/Ecdsa/Sha256Test.php index d4758c4f..72c5b5d1 100644 --- a/test/unit/Signer/Ecdsa/Sha256Test.php +++ b/test/unit/Signer/Ecdsa/Sha256Test.php @@ -40,25 +40,25 @@ public function algorithmIdMustBeCorrect(): void /** * @test * - * @covers ::getAlgorithm + * @covers ::algorithm * * @uses \Lcobucci\JWT\Signer\Ecdsa */ - public function getAlgorithmMustBeCorrect(): void + public function algorithmMustBeCorrect(): void { - self::assertSame(OPENSSL_ALGO_SHA256, $this->getSigner()->getAlgorithm()); + self::assertSame(OPENSSL_ALGO_SHA256, $this->getSigner()->algorithm()); } /** * @test * - * @covers ::getKeyLength + * @covers ::keyLength * * @uses \Lcobucci\JWT\Signer\Ecdsa */ - public function getKeyLengthMustBeCorrect(): void + public function keyLengthMustBeCorrect(): void { - self::assertSame(64, $this->getSigner()->getKeyLength()); + self::assertSame(64, $this->getSigner()->keyLength()); } private function getSigner(): Sha256 diff --git a/test/unit/Signer/Ecdsa/Sha384Test.php b/test/unit/Signer/Ecdsa/Sha384Test.php index cf8fc0ea..43cc100b 100644 --- a/test/unit/Signer/Ecdsa/Sha384Test.php +++ b/test/unit/Signer/Ecdsa/Sha384Test.php @@ -40,25 +40,25 @@ public function algorithmIdMustBeCorrect(): void /** * @test * - * @covers ::getAlgorithm + * @covers ::algorithm * * @uses \Lcobucci\JWT\Signer\Ecdsa */ - public function getAlgorithmMustBeCorrect(): void + public function algorithmMustBeCorrect(): void { - self::assertSame(OPENSSL_ALGO_SHA384, $this->getSigner()->getAlgorithm()); + self::assertSame(OPENSSL_ALGO_SHA384, $this->getSigner()->algorithm()); } /** * @test * - * @covers ::getKeyLength + * @covers ::keyLength * * @uses \Lcobucci\JWT\Signer\Ecdsa */ - public function getKeyLengthMustBeCorrect(): void + public function keyLengthMustBeCorrect(): void { - self::assertSame(96, $this->getSigner()->getKeyLength()); + self::assertSame(96, $this->getSigner()->keyLength()); } private function getSigner(): Sha384 diff --git a/test/unit/Signer/Ecdsa/Sha512Test.php b/test/unit/Signer/Ecdsa/Sha512Test.php index 325d4cb2..87bb000a 100644 --- a/test/unit/Signer/Ecdsa/Sha512Test.php +++ b/test/unit/Signer/Ecdsa/Sha512Test.php @@ -40,25 +40,25 @@ public function algorithmIdMustBeCorrect(): void /** * @test * - * @covers ::getAlgorithm + * @covers ::algorithm * * @uses \Lcobucci\JWT\Signer\Ecdsa */ - public function getAlgorithmMustBeCorrect(): void + public function algorithmMustBeCorrect(): void { - self::assertSame(OPENSSL_ALGO_SHA512, $this->getSigner()->getAlgorithm()); + self::assertSame(OPENSSL_ALGO_SHA512, $this->getSigner()->algorithm()); } /** * @test * - * @covers ::getKeyLength + * @covers ::keyLength * * @uses \Lcobucci\JWT\Signer\Ecdsa */ - public function getKeyLengthMustBeCorrect(): void + public function keyLengthMustBeCorrect(): void { - self::assertSame(132, $this->getSigner()->getKeyLength()); + self::assertSame(132, $this->getSigner()->keyLength()); } private function getSigner(): Sha512 diff --git a/test/unit/Signer/EcdsaTest.php b/test/unit/Signer/EcdsaTest.php index 9a3f2659..4354ec07 100644 --- a/test/unit/Signer/EcdsaTest.php +++ b/test/unit/Signer/EcdsaTest.php @@ -34,13 +34,13 @@ private function getSigner(): Ecdsa { $signer = $this->getMockForAbstractClass(Ecdsa::class, [$this->pointsManipulator]); - $signer->method('getAlgorithm') + $signer->method('algorithm') ->willReturn(OPENSSL_ALGO_SHA256); $signer->method('algorithmId') ->willReturn('ES256'); - $signer->method('getKeyLength') + $signer->method('keyLength') ->willReturn(64); return $signer; @@ -50,7 +50,7 @@ private function getSigner(): Ecdsa * @test * * @covers ::sign - * @covers ::getKeyType + * @covers ::keyType * @covers \Lcobucci\JWT\Signer\Ecdsa\MultibyteStringConverter * @covers \Lcobucci\JWT\Signer\OpenSSL * @@ -71,7 +71,7 @@ public function signShouldReturnTheAHashBasedOnTheOpenSslSignature(): void 1, openssl_verify( $payload, - $this->pointsManipulator->toAsn1($signature, $signer->getKeyLength()), + $this->pointsManipulator->toAsn1($signature, $signer->keyLength()), $publicKey, OPENSSL_ALGO_SHA256 ) @@ -82,7 +82,7 @@ public function signShouldReturnTheAHashBasedOnTheOpenSslSignature(): void * @test * * @covers ::verify - * @covers ::getKeyType + * @covers ::keyType * @covers \Lcobucci\JWT\Signer\Ecdsa\MultibyteStringConverter * @covers \Lcobucci\JWT\Signer\OpenSSL * @@ -102,7 +102,7 @@ public function verifyShouldDelegateToEcdsaSignerUsingPublicKey(): void self::assertTrue( $signer->verify( - $this->pointsManipulator->fromAsn1($signature, $signer->getKeyLength()), + $this->pointsManipulator->fromAsn1($signature, $signer->keyLength()), $payload, self::$ecdsaKeys['public1'] ) diff --git a/test/unit/Signer/Hmac/Sha256Test.php b/test/unit/Signer/Hmac/Sha256Test.php index e75f92a4..7abb9eeb 100644 --- a/test/unit/Signer/Hmac/Sha256Test.php +++ b/test/unit/Signer/Hmac/Sha256Test.php @@ -23,12 +23,12 @@ public function algorithmIdMustBeCorrect(): void /** * @test * - * @covers ::getAlgorithm + * @covers ::algorithm */ - public function getAlgorithmMustBeCorrect(): void + public function algorithmMustBeCorrect(): void { $signer = new Sha256(); - self::assertEquals('sha256', $signer->getAlgorithm()); + self::assertEquals('sha256', $signer->algorithm()); } } diff --git a/test/unit/Signer/Hmac/Sha384Test.php b/test/unit/Signer/Hmac/Sha384Test.php index bc9079f0..d585f717 100644 --- a/test/unit/Signer/Hmac/Sha384Test.php +++ b/test/unit/Signer/Hmac/Sha384Test.php @@ -23,12 +23,12 @@ public function algorithmIdMustBeCorrect(): void /** * @test * - * @covers ::getAlgorithm + * @covers ::algorithm */ - public function getAlgorithmMustBeCorrect(): void + public function algorithmMustBeCorrect(): void { $signer = new Sha384(); - self::assertEquals('sha384', $signer->getAlgorithm()); + self::assertEquals('sha384', $signer->algorithm()); } } diff --git a/test/unit/Signer/Hmac/Sha512Test.php b/test/unit/Signer/Hmac/Sha512Test.php index 12ccd690..099642a3 100644 --- a/test/unit/Signer/Hmac/Sha512Test.php +++ b/test/unit/Signer/Hmac/Sha512Test.php @@ -23,12 +23,12 @@ public function algorithmIdMustBeCorrect(): void /** * @test * - * @covers ::getAlgorithm + * @covers ::algorithm */ - public function getAlgorithmMustBeCorrect(): void + public function algorithmMustBeCorrect(): void { $signer = new Sha512(); - self::assertEquals('sha512', $signer->getAlgorithm()); + self::assertEquals('sha512', $signer->algorithm()); } } diff --git a/test/unit/Signer/HmacTest.php b/test/unit/Signer/HmacTest.php index 1395fd44..e77600b8 100644 --- a/test/unit/Signer/HmacTest.php +++ b/test/unit/Signer/HmacTest.php @@ -25,7 +25,7 @@ public function initializeDependencies(): void ->willReturn('TEST123'); $this->signer->expects(self::any()) - ->method('getAlgorithm') + ->method('algorithm') ->willReturn('sha256'); } diff --git a/test/unit/Signer/Rsa/Sha256Test.php b/test/unit/Signer/Rsa/Sha256Test.php index 61cebff6..78911ad4 100644 --- a/test/unit/Signer/Rsa/Sha256Test.php +++ b/test/unit/Signer/Rsa/Sha256Test.php @@ -25,12 +25,12 @@ public function algorithmIdMustBeCorrect(): void /** * @test * - * @covers ::getAlgorithm + * @covers ::algorithm */ - public function getAlgorithmMustBeCorrect(): void + public function algorithmMustBeCorrect(): void { $signer = new Sha256(); - self::assertEquals(OPENSSL_ALGO_SHA256, $signer->getAlgorithm()); + self::assertEquals(OPENSSL_ALGO_SHA256, $signer->algorithm()); } } diff --git a/test/unit/Signer/Rsa/Sha384Test.php b/test/unit/Signer/Rsa/Sha384Test.php index e6297a0f..41ea82be 100644 --- a/test/unit/Signer/Rsa/Sha384Test.php +++ b/test/unit/Signer/Rsa/Sha384Test.php @@ -25,12 +25,12 @@ public function algorithmIdMustBeCorrect(): void /** * @test * - * @covers ::getAlgorithm + * @covers ::algorithm */ - public function getAlgorithmMustBeCorrect(): void + public function algorithmMustBeCorrect(): void { $signer = new Sha384(); - self::assertEquals(OPENSSL_ALGO_SHA384, $signer->getAlgorithm()); + self::assertEquals(OPENSSL_ALGO_SHA384, $signer->algorithm()); } } diff --git a/test/unit/Signer/Rsa/Sha512Test.php b/test/unit/Signer/Rsa/Sha512Test.php index 57ca8c98..76594576 100644 --- a/test/unit/Signer/Rsa/Sha512Test.php +++ b/test/unit/Signer/Rsa/Sha512Test.php @@ -25,12 +25,12 @@ public function algorithmIdMustBeCorrect(): void /** * @test * - * @covers ::getAlgorithm + * @covers ::algorithm */ - public function getAlgorithmMustBeCorrect(): void + public function algorithmMustBeCorrect(): void { $signer = new Sha512(); - self::assertEquals(OPENSSL_ALGO_SHA512, $signer->getAlgorithm()); + self::assertEquals(OPENSSL_ALGO_SHA512, $signer->algorithm()); } } diff --git a/test/unit/Signer/RsaTest.php b/test/unit/Signer/RsaTest.php index 0605a907..9909b11c 100644 --- a/test/unit/Signer/RsaTest.php +++ b/test/unit/Signer/RsaTest.php @@ -26,7 +26,7 @@ final class RsaTest extends TestCase * @test * * @covers ::sign - * @covers ::getKeyType + * @covers ::keyType * @covers \Lcobucci\JWT\Signer\OpenSSL * * @uses \Lcobucci\JWT\Signer\Key\LocalFileReference @@ -48,7 +48,7 @@ public function signShouldReturnAValidOpensslSignature(): void * @test * * @covers ::sign - * @covers ::getKeyType + * @covers ::keyType * @covers \Lcobucci\JWT\Signer\OpenSSL * @covers \Lcobucci\JWT\Signer\CannotSignPayload * @@ -95,7 +95,7 @@ public function signShouldRaiseAnExceptionWhenKeyIsNotParseable(): void * @test * * @covers ::sign - * @covers ::getKeyType + * @covers ::keyType * @covers \Lcobucci\JWT\Signer\OpenSSL * @covers \Lcobucci\JWT\Signer\InvalidKeyProvided * @@ -115,7 +115,7 @@ public function signShouldRaiseAnExceptionWhenKeyTypeIsNotRsa(): void * @test * * @covers ::verify - * @covers ::getKeyType + * @covers ::keyType * @covers \Lcobucci\JWT\Signer\OpenSSL * * @uses \Lcobucci\JWT\Signer\Key\LocalFileReference @@ -176,7 +176,7 @@ private function getSigner(): Rsa { $signer = $this->getMockForAbstractClass(Rsa::class); - $signer->method('getAlgorithm') + $signer->method('algorithm') ->willReturn(OPENSSL_ALGO_SHA256); $signer->method('algorithmId') From aad6449fdaa09db542c5fed6f719f3f746b01524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Fri, 20 Nov 2020 22:07:32 +0100 Subject: [PATCH 3/3] Rename getters in configuration object --- docs/configuration.md | 14 +-- docs/extending-the-library.md | 2 +- docs/issuing-tokens.md | 8 +- docs/parsing-tokens.md | 2 +- docs/validating-tokens.md | 12 +-- src/Configuration.php | 14 +-- test/functional/ES512TokenTest.php | 30 +++--- test/functional/EcdsaTokenTest.php | 42 ++++---- test/functional/HmacTokenTest.php | 24 ++--- .../MaliciousTamperingPreventionTest.php | 12 +-- test/functional/RsaTokenTest.php | 36 +++---- test/functional/UnsignedTokenTest.php | 12 +-- test/unit/ConfigurationTest.php | 100 +++++++++--------- 13 files changed, 154 insertions(+), 154 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 519f0a19..cd9f82be 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -125,10 +125,10 @@ Once you've made all the necessary configuration you can pass the configuration These are the available getters: -* `Lcobucci\JWT\Configuration#createBuilder()`: retrieves the token builder (always creating a new instance) -* `Lcobucci\JWT\Configuration#getParser()`: retrieves the token parser -* `Lcobucci\JWT\Configuration#getSigner()`: retrieves the signer -* `Lcobucci\JWT\Configuration#getSigningKey()`: retrieves the key for signature creation -* `Lcobucci\JWT\Configuration#getVerificationKey()`: retrieves the key for signature verification -* `Lcobucci\JWT\Configuration#getValidator()`: retrieves the token validator -* `Lcobucci\JWT\Configuration#getValidationConstraints()`: retrieves the default set of validation constraints +* `Lcobucci\JWT\Configuration#builder()`: retrieves the token builder (always creating a new instance) +* `Lcobucci\JWT\Configuration#parser()`: retrieves the token parser +* `Lcobucci\JWT\Configuration#signer()`: retrieves the signer +* `Lcobucci\JWT\Configuration#signingKey()`: retrieves the key for signature creation +* `Lcobucci\JWT\Configuration#verificationKey()`: retrieves the key for signature verification +* `Lcobucci\JWT\Configuration#validator()`: retrieves the token validator +* `Lcobucci\JWT\Configuration#validationConstraints()`: retrieves the default set of validation constraints diff --git a/docs/extending-the-library.md b/docs/extending-the-library.md index 71fde6ac..b19a6a89 100644 --- a/docs/extending-the-library.md +++ b/docs/extending-the-library.md @@ -74,7 +74,7 @@ final class UnixTimestampDates implements ClaimsFormatter $config = $container->get(Configuration::class); assert($config instanceof Configuration); -$config->createBuilder(new UnixTimestampDates()); +$config->builder(new UnixTimestampDates()); ``` The class `Lcobucci\JWT\Encoding\ChainedFormatter` allows for users to combine multiple formatters. diff --git a/docs/issuing-tokens.md b/docs/issuing-tokens.md index aaa8a0f5..ac242b5c 100644 --- a/docs/issuing-tokens.md +++ b/docs/issuing-tokens.md @@ -13,7 +13,7 @@ $config = $container->get(Configuration::class); assert($config instanceof Configuration); $now = new DateTimeImmutable(); -$token = $config->createBuilder() +$token = $config->builder() // Configures the issuer (iss claim) ->issuedBy('http://example.com') // Configures the audience (aud claim) @@ -31,7 +31,7 @@ $token = $config->createBuilder() // Configures a new header, called "foo" ->withHeader('foo', 'bar') // Builds a new token - ->getToken($config->getSigner(), $config->getSigningKey()); + ->getToken($config->signer(), $config->signingKey()); ``` Once you've created a token, you're able to retrieve its data and convert it to its string representation: @@ -42,11 +42,11 @@ use Lcobucci\JWT\Configuration; $config = $container->get(Configuration::class); assert($config instanceof Configuration); -$token = $config->createBuilder() +$token = $config->builder() ->issuedBy('http://example.com') ->withClaim('uid', 1) ->withHeader('foo', 'bar') - ->getToken($config->getSigner(), $config->getSigningKey()); + ->getToken($config->signer(), $config->signingKey()); $token->headers(); // Retrieves the token headers $token->claims(); // Retrieves the token claims diff --git a/docs/parsing-tokens.md b/docs/parsing-tokens.md index 4440c8fc..55cafe30 100644 --- a/docs/parsing-tokens.md +++ b/docs/parsing-tokens.md @@ -13,7 +13,7 @@ use Lcobucci\JWT\Token\Plain; $config = $container->get(Configuration::class); assert($config instanceof Configuration); -$token = $config->getParser()->parse( +$token = $config->parser()->parse( 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.' . 'eyJzdWIiOiIxMjM0NTY3ODkwIn0.' . '2gSBz9EOsQRN9I-3iSxJoFt7NtgV6Rm0IL6a8CAwl3Q' diff --git a/docs/validating-tokens.md b/docs/validating-tokens.md index b4b3f866..69c5b86b 100644 --- a/docs/validating-tokens.md +++ b/docs/validating-tokens.md @@ -21,13 +21,13 @@ use Lcobucci\JWT\Validation\RequiredConstraintsViolated; $token = $container->get(Configuration::class); assert($config instanceof Configuration); -$token = $config->getParser()->parse('...'); +$token = $config->parser()->parse('...'); assert($token instanceof Plain); -$constraints = $config->getValidationConstraints(); +$constraints = $config->validationConstraints(); try { - $config->getValidator()->assert($token, ...$constraints); + $config->validator()->assert($token, ...$constraints); } catch (RequiredConstraintsViolated $e) { // list of constraints violation exceptions: var_dump($e->violations()); @@ -48,12 +48,12 @@ use Lcobucci\JWT\Token\Plain; $token = $container->get(Configuration::class); assert($config instanceof Configuration); -$token = $config->getParser()->parse('...'); +$token = $config->parser()->parse('...'); assert($token instanceof Plain); -$constraints = $config->getValidationConstraints(); +$constraints = $config->validationConstraints(); -if (! $config->getValidator()->validate($token, ...$constraints)) { +if (! $config->validator()->validate($token, ...$constraints)) { throw new RuntimeException('No way!'); } ``` diff --git a/src/Configuration.php b/src/Configuration.php index 82ef1743..8da1c8af 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -101,12 +101,12 @@ public function setBuilderFactory(callable $builderFactory): void $this->builderFactory = Closure::fromCallable($builderFactory); } - public function createBuilder(?ClaimsFormatter $claimFormatter = null): Builder + public function builder(?ClaimsFormatter $claimFormatter = null): Builder { return ($this->builderFactory)($claimFormatter ?? ChainedFormatter::default()); } - public function getParser(): Parser + public function parser(): Parser { return $this->parser; } @@ -116,22 +116,22 @@ public function setParser(Parser $parser): void $this->parser = $parser; } - public function getSigner(): Signer + public function signer(): Signer { return $this->signer; } - public function getSigningKey(): Key + public function signingKey(): Key { return $this->signingKey; } - public function getVerificationKey(): Key + public function verificationKey(): Key { return $this->verificationKey; } - public function getValidator(): Validator + public function validator(): Validator { return $this->validator; } @@ -142,7 +142,7 @@ public function setValidator(Validator $validator): void } /** @return Constraint[] */ - public function getValidationConstraints(): array + public function validationConstraints(): array { return $this->validationConstraints; } diff --git a/test/functional/ES512TokenTest.php b/test/functional/ES512TokenTest.php index 4f52f051..2d921218 100644 --- a/test/functional/ES512TokenTest.php +++ b/test/functional/ES512TokenTest.php @@ -58,7 +58,7 @@ public function createConfiguration(): void /** @test */ public function builderShouldRaiseExceptionWhenKeyIsInvalid(): void { - $builder = $this->config->createBuilder(); + $builder = $this->config->builder(); $this->expectException(InvalidKeyProvided::class); $this->expectExceptionMessage('It was not possible to parse your key, reason:'); @@ -67,13 +67,13 @@ public function builderShouldRaiseExceptionWhenKeyIsInvalid(): void ->permittedFor('http://client.abc.com') ->issuedBy('http://api.abc.com') ->withClaim('user', ['name' => 'testing', 'email' => 'testing@abc.com']) - ->getToken($this->config->getSigner(), InMemory::plainText('testing')); + ->getToken($this->config->signer(), InMemory::plainText('testing')); } /** @test */ public function builderShouldRaiseExceptionWhenKeyIsNotEcdsaCompatible(): void { - $builder = $this->config->createBuilder(); + $builder = $this->config->builder(); $this->expectException(InvalidKeyProvided::class); $this->expectExceptionMessage('This key is not compatible with this signer'); @@ -82,14 +82,14 @@ public function builderShouldRaiseExceptionWhenKeyIsNotEcdsaCompatible(): void ->permittedFor('http://client.abc.com') ->issuedBy('http://api.abc.com') ->withClaim('user', ['name' => 'testing', 'email' => 'testing@abc.com']) - ->getToken($this->config->getSigner(), static::$rsaKeys['private']); + ->getToken($this->config->signer(), static::$rsaKeys['private']); } /** @test */ public function builderCanGenerateAToken(): Token { $user = ['name' => 'testing', 'email' => 'testing@abc.com']; - $builder = $this->config->createBuilder(); + $builder = $this->config->builder(); $token = $builder->identifiedBy('1') ->permittedFor('http://client.abc.com') @@ -97,7 +97,7 @@ public function builderCanGenerateAToken(): Token ->issuedBy('http://api.abc.com') ->withClaim('user', $user) ->withHeader('jki', '1234') - ->getToken($this->config->getSigner(), $this->config->getSigningKey()); + ->getToken($this->config->signer(), $this->config->signingKey()); self::assertEquals('1234', $token->headers()->get('jki')); self::assertEquals('http://api.abc.com', $token->claims()->get(Token\RegisteredClaims::ISSUER)); @@ -117,7 +117,7 @@ public function builderCanGenerateAToken(): Token */ public function parserCanReadAToken(Token $generated): void { - $read = $this->config->getParser()->parse($generated->toString()); + $read = $this->config->parser()->parse($generated->toString()); assert($read instanceof Token\Plain); self::assertEquals($generated, $read); @@ -133,10 +133,10 @@ public function signatureAssertionShouldRaiseExceptionWhenKeyIsNotRight(Token $t $this->expectException(RequiredConstraintsViolated::class); $this->expectExceptionMessage('The token violates some mandatory constraints'); - $this->config->getValidator()->assert( + $this->config->validator()->assert( $token, new SignedWith( - $this->config->getSigner(), + $this->config->signer(), self::$ecdsaKeys['public2_ec512'] ) ); @@ -151,7 +151,7 @@ public function signatureAssertionShouldRaiseExceptionWhenAlgorithmIsDifferent(T $this->expectException(RequiredConstraintsViolated::class); $this->expectExceptionMessage('The token violates some mandatory constraints'); - $this->config->getValidator()->assert( + $this->config->validator()->assert( $token, new SignedWith( Sha256::create(), @@ -169,9 +169,9 @@ public function signatureAssertionShouldRaiseExceptionWhenKeyIsNotEcdsaCompatibl $this->expectException(InvalidKeyProvided::class); $this->expectExceptionMessage('This key is not compatible with this signer'); - $this->config->getValidator()->assert( + $this->config->validator()->assert( $token, - new SignedWith($this->config->getSigner(), self::$rsaKeys['public']) + new SignedWith($this->config->signer(), self::$rsaKeys['public']) ); } @@ -182,10 +182,10 @@ public function signatureAssertionShouldRaiseExceptionWhenKeyIsNotEcdsaCompatibl public function signatureValidationShouldSucceedWhenKeyIsRight(Token $token): void { $constraint = new SignedWith( - $this->config->getSigner(), - $this->config->getVerificationKey() + $this->config->signer(), + $this->config->verificationKey() ); - self::assertTrue($this->config->getValidator()->validate($token, $constraint)); + self::assertTrue($this->config->validator()->validate($token, $constraint)); } } diff --git a/test/functional/EcdsaTokenTest.php b/test/functional/EcdsaTokenTest.php index 2719b4dc..f8794e6c 100644 --- a/test/functional/EcdsaTokenTest.php +++ b/test/functional/EcdsaTokenTest.php @@ -62,7 +62,7 @@ public function createConfiguration(): void /** @test */ public function builderShouldRaiseExceptionWhenKeyIsInvalid(): void { - $builder = $this->config->createBuilder(); + $builder = $this->config->builder(); $this->expectException(InvalidKeyProvided::class); $this->expectExceptionMessage('It was not possible to parse your key, reason:'); @@ -71,13 +71,13 @@ public function builderShouldRaiseExceptionWhenKeyIsInvalid(): void ->permittedFor('http://client.abc.com') ->issuedBy('http://api.abc.com') ->withClaim('user', ['name' => 'testing', 'email' => 'testing@abc.com']) - ->getToken($this->config->getSigner(), InMemory::plainText('testing')); + ->getToken($this->config->signer(), InMemory::plainText('testing')); } /** @test */ public function builderShouldRaiseExceptionWhenKeyIsNotEcdsaCompatible(): void { - $builder = $this->config->createBuilder(); + $builder = $this->config->builder(); $this->expectException(InvalidKeyProvided::class); $this->expectExceptionMessage('This key is not compatible with this signer'); @@ -86,14 +86,14 @@ public function builderShouldRaiseExceptionWhenKeyIsNotEcdsaCompatible(): void ->permittedFor('http://client.abc.com') ->issuedBy('http://api.abc.com') ->withClaim('user', ['name' => 'testing', 'email' => 'testing@abc.com']) - ->getToken($this->config->getSigner(), static::$rsaKeys['private']); + ->getToken($this->config->signer(), static::$rsaKeys['private']); } /** @test */ public function builderCanGenerateAToken(): Token { $user = ['name' => 'testing', 'email' => 'testing@abc.com']; - $builder = $this->config->createBuilder(); + $builder = $this->config->builder(); $token = $builder->identifiedBy('1') ->permittedFor('http://client.abc.com') @@ -101,7 +101,7 @@ public function builderCanGenerateAToken(): Token ->issuedBy('http://api.abc.com') ->withClaim('user', $user) ->withHeader('jki', '1234') - ->getToken($this->config->getSigner(), $this->config->getSigningKey()); + ->getToken($this->config->signer(), $this->config->signingKey()); self::assertEquals('1234', $token->headers()->get('jki')); self::assertEquals('http://api.abc.com', $token->claims()->get(Token\RegisteredClaims::ISSUER)); @@ -121,7 +121,7 @@ public function builderCanGenerateAToken(): Token */ public function parserCanReadAToken(Token $generated): void { - $read = $this->config->getParser()->parse($generated->toString()); + $read = $this->config->parser()->parse($generated->toString()); assert($read instanceof Token\Plain); self::assertEquals($generated, $read); @@ -137,10 +137,10 @@ public function signatureAssertionShouldRaiseExceptionWhenKeyIsNotRight(Token $t $this->expectException(RequiredConstraintsViolated::class); $this->expectExceptionMessage('The token violates some mandatory constraints'); - $this->config->getValidator()->assert( + $this->config->validator()->assert( $token, new SignedWith( - $this->config->getSigner(), + $this->config->signer(), self::$ecdsaKeys['public2'] ) ); @@ -155,7 +155,7 @@ public function signatureAssertionShouldRaiseExceptionWhenAlgorithmIsDifferent(T $this->expectException(RequiredConstraintsViolated::class); $this->expectExceptionMessage('The token violates some mandatory constraints'); - $this->config->getValidator()->assert( + $this->config->validator()->assert( $token, new SignedWith( Sha512::create(), @@ -173,9 +173,9 @@ public function signatureAssertionShouldRaiseExceptionWhenKeyIsNotEcdsaCompatibl $this->expectException(InvalidKeyProvided::class); $this->expectExceptionMessage('This key is not compatible with this signer'); - $this->config->getValidator()->assert( + $this->config->validator()->assert( $token, - new SignedWith($this->config->getSigner(), self::$rsaKeys['public']) + new SignedWith($this->config->signer(), self::$rsaKeys['public']) ); } @@ -186,18 +186,18 @@ public function signatureAssertionShouldRaiseExceptionWhenKeyIsNotEcdsaCompatibl public function signatureValidationShouldSucceedWhenKeyIsRight(Token $token): void { $constraint = new SignedWith( - $this->config->getSigner(), - $this->config->getVerificationKey() + $this->config->signer(), + $this->config->verificationKey() ); - self::assertTrue($this->config->getValidator()->validate($token, $constraint)); + self::assertTrue($this->config->validator()->validate($token, $constraint)); } /** @test */ public function everythingShouldWorkWithAKeyWithParams(): void { - $builder = $this->config->createBuilder(); - $signer = $this->config->getSigner(); + $builder = $this->config->builder(); + $signer = $this->config->signer(); $token = $builder->identifiedBy('1') ->permittedFor('http://client.abc.com') @@ -207,11 +207,11 @@ public function everythingShouldWorkWithAKeyWithParams(): void ->getToken($signer, static::$ecdsaKeys['private-params']); $constraint = new SignedWith( - $this->config->getSigner(), + $this->config->signer(), static::$ecdsaKeys['public-params'] ); - self::assertTrue($this->config->getValidator()->validate($token, $constraint)); + self::assertTrue($this->config->validator()->validate($token, $constraint)); } /** @test */ @@ -229,11 +229,11 @@ public function everythingShouldWorkWhenUsingATokenGeneratedByOtherLibs(): void . 'mZudf1zCUZ8/4eodlHU=' . PHP_EOL . '-----END PUBLIC KEY-----'; - $token = $this->config->getParser()->parse($data); + $token = $this->config->parser()->parse($data); assert($token instanceof Token\Plain); $constraint = new SignedWith(Sha512::create(), InMemory::plainText($key)); - self::assertTrue($this->config->getValidator()->validate($token, $constraint)); + self::assertTrue($this->config->validator()->validate($token, $constraint)); self::assertEquals('world', $token->claims()->get('hello')); } } diff --git a/test/functional/HmacTokenTest.php b/test/functional/HmacTokenTest.php index 8887fd69..d87771a6 100644 --- a/test/functional/HmacTokenTest.php +++ b/test/functional/HmacTokenTest.php @@ -47,14 +47,14 @@ public function createConfiguration(): void public function builderCanGenerateAToken(): Token { $user = ['name' => 'testing', 'email' => 'testing@abc.com']; - $builder = $this->config->createBuilder(); + $builder = $this->config->builder(); $token = $builder->identifiedBy('1') ->permittedFor('http://client.abc.com') ->issuedBy('http://api.abc.com') ->withClaim('user', $user) ->withHeader('jki', '1234') - ->getToken($this->config->getSigner(), $this->config->getSigningKey()); + ->getToken($this->config->signer(), $this->config->signingKey()); self::assertEquals('1234', $token->headers()->get('jki')); self::assertEquals(['http://client.abc.com'], $token->claims()->get(Token\RegisteredClaims::AUDIENCE)); @@ -70,7 +70,7 @@ public function builderCanGenerateAToken(): Token */ public function parserCanReadAToken(Token $generated): void { - $read = $this->config->getParser()->parse($generated->toString()); + $read = $this->config->parser()->parse($generated->toString()); assert($read instanceof Token\Plain); self::assertEquals($generated, $read); @@ -86,9 +86,9 @@ public function signatureAssertionShouldRaiseExceptionWhenKeyIsNotRight(Token $t $this->expectException(RequiredConstraintsViolated::class); $this->expectExceptionMessage('The token violates some mandatory constraints'); - $this->config->getValidator()->assert( + $this->config->validator()->assert( $token, - new SignedWith($this->config->getSigner(), InMemory::plainText('testing1')) + new SignedWith($this->config->signer(), InMemory::plainText('testing1')) ); } @@ -101,9 +101,9 @@ public function signatureAssertionShouldRaiseExceptionWhenAlgorithmIsDifferent(T $this->expectException(RequiredConstraintsViolated::class); $this->expectExceptionMessage('The token violates some mandatory constraints'); - $this->config->getValidator()->assert( + $this->config->validator()->assert( $token, - new SignedWith(new Sha512(), $this->config->getVerificationKey()) + new SignedWith(new Sha512(), $this->config->verificationKey()) ); } @@ -113,9 +113,9 @@ public function signatureAssertionShouldRaiseExceptionWhenAlgorithmIsDifferent(T */ public function signatureValidationShouldSucceedWhenKeyIsRight(Token $token): void { - $constraint = new SignedWith($this->config->getSigner(), $this->config->getVerificationKey()); + $constraint = new SignedWith($this->config->signer(), $this->config->verificationKey()); - self::assertTrue($this->config->getValidator()->validate($token, $constraint)); + self::assertTrue($this->config->validator()->validate($token, $constraint)); } /** @test */ @@ -124,11 +124,11 @@ public function everythingShouldWorkWhenUsingATokenGeneratedByOtherLibs(): void $data = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJoZWxsbyI6IndvcmxkIn0.Rh' . '7AEgqCB7zae1PkgIlvOpeyw9Ab8NGTbeOH7heHO0o'; - $token = $this->config->getParser()->parse($data); + $token = $this->config->parser()->parse($data); assert($token instanceof Token\Plain); - $constraint = new SignedWith($this->config->getSigner(), $this->config->getVerificationKey()); + $constraint = new SignedWith($this->config->signer(), $this->config->verificationKey()); - self::assertTrue($this->config->getValidator()->validate($token, $constraint)); + self::assertTrue($this->config->validator()->validate($token, $constraint)); self::assertEquals('world', $token->claims()->get('hello')); } } diff --git a/test/functional/MaliciousTamperingPreventionTest.php b/test/functional/MaliciousTamperingPreventionTest.php index cf05775b..6a46ec64 100644 --- a/test/functional/MaliciousTamperingPreventionTest.php +++ b/test/functional/MaliciousTamperingPreventionTest.php @@ -80,15 +80,15 @@ public function preventRegressionsThatAllowsMaliciousTampering(): void * (e.g. HMAC-SHA512 instead of ECDSA), they can forge messages! */ - $token = $this->config->getParser()->parse($bad); + $token = $this->config->parser()->parse($bad); assert($token instanceof Plain); self::assertEquals('world', $token->claims()->get('hello'), 'The claim content should not be modified'); - $validator = $this->config->getValidator(); + $validator = $this->config->validator(); self::assertFalse( - $validator->validate($token, new SignedWith(new HS512(), $this->config->getVerificationKey())), + $validator->validate($token, new SignedWith(new HS512(), $this->config->verificationKey())), 'Using the attackers signer should make things unsafe' ); @@ -96,8 +96,8 @@ public function preventRegressionsThatAllowsMaliciousTampering(): void $validator->validate( $token, new SignedWith( - $this->config->getSigner(), - $this->config->getVerificationKey() + $this->config->signer(), + $this->config->verificationKey() ) ), 'But we know which Signer should be used so the attack fails' @@ -116,7 +116,7 @@ private function createMaliciousToken(string $token): string $hmac = hash_hmac( 'sha512', $asplode[0] . '.' . $asplode[1], - $this->config->getVerificationKey()->contents(), + $this->config->verificationKey()->contents(), true ); diff --git a/test/functional/RsaTokenTest.php b/test/functional/RsaTokenTest.php index 8d348a48..5ecb0844 100644 --- a/test/functional/RsaTokenTest.php +++ b/test/functional/RsaTokenTest.php @@ -57,7 +57,7 @@ public function createConfiguration(): void /** @test */ public function builderShouldRaiseExceptionWhenKeyIsInvalid(): void { - $builder = $this->config->createBuilder(); + $builder = $this->config->builder(); $this->expectException(InvalidKeyProvided::class); $this->expectExceptionMessage('It was not possible to parse your key'); @@ -66,13 +66,13 @@ public function builderShouldRaiseExceptionWhenKeyIsInvalid(): void ->permittedFor('http://client.abc.com') ->issuedBy('http://api.abc.com') ->withClaim('user', ['name' => 'testing', 'email' => 'testing@abc.com']) - ->getToken($this->config->getSigner(), InMemory::plainText('testing')); + ->getToken($this->config->signer(), InMemory::plainText('testing')); } /** @test */ public function builderShouldRaiseExceptionWhenKeyIsNotRsaCompatible(): void { - $builder = $this->config->createBuilder(); + $builder = $this->config->builder(); $this->expectException(InvalidKeyProvided::class); $this->expectExceptionMessage('This key is not compatible with this signer'); @@ -81,21 +81,21 @@ public function builderShouldRaiseExceptionWhenKeyIsNotRsaCompatible(): void ->permittedFor('http://client.abc.com') ->issuedBy('http://api.abc.com') ->withClaim('user', ['name' => 'testing', 'email' => 'testing@abc.com']) - ->getToken($this->config->getSigner(), static::$ecdsaKeys['private']); + ->getToken($this->config->signer(), static::$ecdsaKeys['private']); } /** @test */ public function builderCanGenerateAToken(): Token { $user = ['name' => 'testing', 'email' => 'testing@abc.com']; - $builder = $this->config->createBuilder(); + $builder = $this->config->builder(); $token = $builder->identifiedBy('1') ->permittedFor('http://client.abc.com') ->issuedBy('http://api.abc.com') ->withClaim('user', $user) ->withHeader('jki', '1234') - ->getToken($this->config->getSigner(), $this->config->getSigningKey()); + ->getToken($this->config->signer(), $this->config->signingKey()); self::assertEquals('1234', $token->headers()->get('jki')); self::assertEquals(['http://client.abc.com'], $token->claims()->get(Token\RegisteredClaims::AUDIENCE)); @@ -111,7 +111,7 @@ public function builderCanGenerateAToken(): Token */ public function parserCanReadAToken(Token $generated): void { - $read = $this->config->getParser()->parse($generated->toString()); + $read = $this->config->parser()->parse($generated->toString()); assert($read instanceof Token\Plain); self::assertEquals($generated, $read); @@ -127,9 +127,9 @@ public function signatureAssertionShouldRaiseExceptionWhenKeyIsNotRight(Token $t $this->expectException(RequiredConstraintsViolated::class); $this->expectExceptionMessage('The token violates some mandatory constraints'); - $this->config->getValidator()->assert( + $this->config->validator()->assert( $token, - new SignedWith($this->config->getSigner(), self::$rsaKeys['encrypted-public']) + new SignedWith($this->config->signer(), self::$rsaKeys['encrypted-public']) ); } @@ -142,9 +142,9 @@ public function signatureAssertionShouldRaiseExceptionWhenAlgorithmIsDifferent(T $this->expectException(RequiredConstraintsViolated::class); $this->expectExceptionMessage('The token violates some mandatory constraints'); - $this->config->getValidator()->assert( + $this->config->validator()->assert( $token, - new SignedWith(new Sha512(), $this->config->getVerificationKey()) + new SignedWith(new Sha512(), $this->config->verificationKey()) ); } @@ -157,10 +157,10 @@ public function signatureAssertionShouldRaiseExceptionWhenKeyIsNotRsaCompatible( $this->expectException(InvalidKeyProvided::class); $this->expectExceptionMessage('This key is not compatible with this signer'); - $this->config->getValidator()->assert( + $this->config->validator()->assert( $token, new SignedWith( - $this->config->getSigner(), + $this->config->signer(), self::$ecdsaKeys['public1'] ) ); @@ -172,9 +172,9 @@ public function signatureAssertionShouldRaiseExceptionWhenKeyIsNotRsaCompatible( */ public function signatureValidationShouldSucceedWhenKeyIsRight(Token $token): void { - $constraint = new SignedWith($this->config->getSigner(), $this->config->getVerificationKey()); + $constraint = new SignedWith($this->config->signer(), $this->config->verificationKey()); - self::assertTrue($this->config->getValidator()->validate($token, $constraint)); + self::assertTrue($this->config->validator()->validate($token, $constraint)); } /** @test */ @@ -187,11 +187,11 @@ public function everythingShouldWorkWhenUsingATokenGeneratedByOtherLibs(): void . 'nJCupP-Lqh4TmIhftIimSCgLNmJg80wyrpUEfZYReE7hPuEmY0ClTqAGIMQoNS' . '98ljwDxwhfbSuL2tAdbV4DekbTpWzspe3dOJ7RSzmPKVZ6NoezaIazKqyqkmHZfcMaHI1lQeGia6LTbHU1bp0gINi74Vw'; - $token = $this->config->getParser()->parse($data); + $token = $this->config->parser()->parse($data); assert($token instanceof Token\Plain); - $constraint = new SignedWith($this->config->getSigner(), $this->config->getVerificationKey()); + $constraint = new SignedWith($this->config->signer(), $this->config->verificationKey()); - self::assertTrue($this->config->getValidator()->validate($token, $constraint)); + self::assertTrue($this->config->validator()->validate($token, $constraint)); self::assertEquals('world', $token->claims()->get('hello')); } } diff --git a/test/functional/UnsignedTokenTest.php b/test/functional/UnsignedTokenTest.php index 7ac23ea9..f661bfd1 100644 --- a/test/functional/UnsignedTokenTest.php +++ b/test/functional/UnsignedTokenTest.php @@ -54,7 +54,7 @@ public function createConfiguration(): void public function builderCanGenerateAToken(): Token { $user = ['name' => 'testing', 'email' => 'testing@abc.com']; - $builder = $this->config->createBuilder(); + $builder = $this->config->builder(); $expiration = new DateTimeImmutable('@' . (self::CURRENT_TIME + 3000)); @@ -63,7 +63,7 @@ public function builderCanGenerateAToken(): Token ->issuedBy('http://api.abc.com') ->expiresAt($expiration) ->withClaim('user', $user) - ->getToken($this->config->getSigner(), $this->config->getSigningKey()); + ->getToken($this->config->signer(), $this->config->signingKey()); self::assertEquals(new Token\Signature('', ''), $token->signature()); self::assertEquals(['http://client.abc.com'], $token->claims()->get(Token\RegisteredClaims::AUDIENCE)); @@ -80,7 +80,7 @@ public function builderCanGenerateAToken(): Token */ public function parserCanReadAToken(Token $generated): void { - $read = $this->config->getParser()->parse($generated->toString()); + $read = $this->config->parser()->parse($generated->toString()); assert($read instanceof Token\Plain); self::assertEquals($generated, $read); @@ -102,7 +102,7 @@ public function tokenValidationShouldPassWhenEverythingIsFine(Token $generated): new ValidAt($clock), ]; - self::assertTrue($this->config->getValidator()->validate($generated, ...$constraints)); + self::assertTrue($this->config->validator()->validate($generated, ...$constraints)); } /** @@ -111,7 +111,7 @@ public function tokenValidationShouldPassWhenEverythingIsFine(Token $generated): */ public function tokenValidationShouldAllowCustomConstraint(Token $generated): void { - self::assertTrue($this->config->getValidator()->validate($generated, $this->validUserConstraint())); + self::assertTrue($this->config->validator()->validate($generated, $this->validUserConstraint())); } /** @@ -128,7 +128,7 @@ public function tokenAssertionShouldRaiseExceptionWhenOneOfTheConstraintsFails(T $this->expectException(RequiredConstraintsViolated::class); $this->expectExceptionMessage('The token violates some mandatory constraints'); - $this->config->getValidator()->assert($generated, ...$constraints); + $this->config->validator()->assert($generated, ...$constraints); } private function validUserConstraint(): Constraint diff --git a/test/unit/ConfigurationTest.php b/test/unit/ConfigurationTest.php index fa339e5f..68b0ba32 100644 --- a/test/unit/ConfigurationTest.php +++ b/test/unit/ConfigurationTest.php @@ -58,9 +58,9 @@ public function createDependencies(): void * * @covers ::forAsymmetricSigner * @covers ::__construct - * @covers ::getSigner - * @covers ::getSigningKey - * @covers ::getVerificationKey + * @covers ::signer + * @covers ::signingKey + * @covers ::verificationKey * * @uses \Lcobucci\JWT\Signer\Key\InMemory */ @@ -71,9 +71,9 @@ public function forAsymmetricSignerShouldConfigureSignerAndBothKeys(): void $config = Configuration::forAsymmetricSigner($this->signer, $signingKey, $verificationKey); - self::assertSame($this->signer, $config->getSigner()); - self::assertSame($signingKey, $config->getSigningKey()); - self::assertSame($verificationKey, $config->getVerificationKey()); + self::assertSame($this->signer, $config->signer()); + self::assertSame($signingKey, $config->signingKey()); + self::assertSame($verificationKey, $config->verificationKey()); } /** @@ -81,9 +81,9 @@ public function forAsymmetricSignerShouldConfigureSignerAndBothKeys(): void * * @covers ::forSymmetricSigner * @covers ::__construct - * @covers ::getSigner - * @covers ::getSigningKey - * @covers ::getVerificationKey + * @covers ::signer + * @covers ::signingKey + * @covers ::verificationKey * * @uses \Lcobucci\JWT\Signer\Key\InMemory */ @@ -92,9 +92,9 @@ public function forSymmetricSignerShouldConfigureSignerAndBothKeys(): void $key = InMemory::plainText('private'); $config = Configuration::forSymmetricSigner($this->signer, $key); - self::assertSame($this->signer, $config->getSigner()); - self::assertSame($key, $config->getSigningKey()); - self::assertSame($key, $config->getVerificationKey()); + self::assertSame($this->signer, $config->signer()); + self::assertSame($key, $config->signingKey()); + self::assertSame($key, $config->verificationKey()); } /** @@ -102,9 +102,9 @@ public function forSymmetricSignerShouldConfigureSignerAndBothKeys(): void * * @covers ::forUnsecuredSigner * @covers ::__construct - * @covers ::getSigner - * @covers ::getSigningKey - * @covers ::getVerificationKey + * @covers ::signer + * @covers ::signingKey + * @covers ::verificationKey * * @uses \Lcobucci\JWT\Signer\Key\InMemory */ @@ -113,15 +113,15 @@ public function forUnsecuredSignerShouldConfigureSignerAndBothKeys(): void $key = InMemory::plainText(''); $config = Configuration::forUnsecuredSigner(); - self::assertInstanceOf(None::class, $config->getSigner()); - self::assertEquals($key, $config->getSigningKey()); - self::assertEquals($key, $config->getVerificationKey()); + self::assertInstanceOf(None::class, $config->signer()); + self::assertEquals($key, $config->signingKey()); + self::assertEquals($key, $config->verificationKey()); } /** * @test * - * @covers ::createBuilder + * @covers ::builder * * @uses \Lcobucci\JWT\Configuration::forUnsecuredSigner * @uses \Lcobucci\JWT\Configuration::__construct @@ -129,10 +129,10 @@ public function forUnsecuredSignerShouldConfigureSignerAndBothKeys(): void * @uses \Lcobucci\JWT\Signer\None * @uses \Lcobucci\JWT\Signer\Key\InMemory */ - public function createBuilderShouldCreateABuilderWithDefaultEncoderAndClaimFactory(): void + public function builderShouldCreateABuilderWithDefaultEncoderAndClaimFactory(): void { $config = Configuration::forUnsecuredSigner(); - $builder = $config->createBuilder(); + $builder = $config->builder(); self::assertInstanceOf(BuilderImpl::class, $builder); self::assertNotEquals(new BuilderImpl($this->encoder, ChainedFormatter::default()), $builder); @@ -142,7 +142,7 @@ public function createBuilderShouldCreateABuilderWithDefaultEncoderAndClaimFacto /** * @test * - * @covers ::createBuilder + * @covers ::builder * @covers ::__construct * * @uses \Lcobucci\JWT\Configuration::forUnsecuredSigner @@ -150,10 +150,10 @@ public function createBuilderShouldCreateABuilderWithDefaultEncoderAndClaimFacto * @uses \Lcobucci\JWT\Signer\None * @uses \Lcobucci\JWT\Signer\Key\InMemory */ - public function createBuilderShouldCreateABuilderWithCustomizedEncoderAndClaimFactory(): void + public function builderShouldCreateABuilderWithCustomizedEncoderAndClaimFactory(): void { $config = Configuration::forUnsecuredSigner($this->encoder); - $builder = $config->createBuilder(); + $builder = $config->builder(); self::assertInstanceOf(BuilderImpl::class, $builder); self::assertEquals(new BuilderImpl($this->encoder, ChainedFormatter::default()), $builder); @@ -162,7 +162,7 @@ public function createBuilderShouldCreateABuilderWithCustomizedEncoderAndClaimFa /** * @test * - * @covers ::createBuilder + * @covers ::builder * @covers ::setBuilderFactory * * @uses \Lcobucci\JWT\Configuration::forUnsecuredSigner @@ -171,7 +171,7 @@ public function createBuilderShouldCreateABuilderWithCustomizedEncoderAndClaimFa * @uses \Lcobucci\JWT\Signer\None * @uses \Lcobucci\JWT\Signer\Key\InMemory */ - public function createBuilderShouldUseBuilderFactoryWhenThatIsConfigured(): void + public function builderShouldUseBuilderFactoryWhenThatIsConfigured(): void { $builder = $this->createMock(Builder::class); @@ -181,23 +181,23 @@ static function () use ($builder): Builder { return $builder; } ); - self::assertSame($builder, $config->createBuilder()); + self::assertSame($builder, $config->builder()); } /** * @test * - * @covers ::getParser + * @covers ::parser * * @uses \Lcobucci\JWT\Configuration::forUnsecuredSigner * @uses \Lcobucci\JWT\Configuration::__construct * @uses \Lcobucci\JWT\Signer\None * @uses \Lcobucci\JWT\Signer\Key\InMemory */ - public function getParserShouldReturnAParserWithDefaultDecoder(): void + public function parserShouldReturnAParserWithDefaultDecoder(): void { $config = Configuration::forUnsecuredSigner(); - $parser = $config->getParser(); + $parser = $config->parser(); self::assertNotEquals(new ParserImpl($this->decoder), $parser); } @@ -205,17 +205,17 @@ public function getParserShouldReturnAParserWithDefaultDecoder(): void /** * @test * - * @covers ::getParser + * @covers ::parser * @covers ::__construct * * @uses \Lcobucci\JWT\Configuration::forUnsecuredSigner * @uses \Lcobucci\JWT\Signer\None * @uses \Lcobucci\JWT\Signer\Key\InMemory */ - public function getParserShouldReturnAParserWithCustomizedDecoder(): void + public function parserShouldReturnAParserWithCustomizedDecoder(): void { $config = Configuration::forUnsecuredSigner(null, $this->decoder); - $parser = $config->getParser(); + $parser = $config->parser(); self::assertEquals(new ParserImpl($this->decoder), $parser); } @@ -223,7 +223,7 @@ public function getParserShouldReturnAParserWithCustomizedDecoder(): void /** * @test * - * @covers ::getParser + * @covers ::parser * @covers ::setParser * * @uses \Lcobucci\JWT\Configuration::forUnsecuredSigner @@ -231,28 +231,28 @@ public function getParserShouldReturnAParserWithCustomizedDecoder(): void * @uses \Lcobucci\JWT\Signer\None * @uses \Lcobucci\JWT\Signer\Key\InMemory */ - public function getParserShouldNotCreateAnInstanceIfItWasConfigured(): void + public function parserShouldNotCreateAnInstanceIfItWasConfigured(): void { $config = Configuration::forUnsecuredSigner(); $config->setParser($this->parser); - self::assertSame($this->parser, $config->getParser()); + self::assertSame($this->parser, $config->parser()); } /** * @test * - * @covers ::getValidator + * @covers ::validator * * @uses \Lcobucci\JWT\Configuration::forUnsecuredSigner * @uses \Lcobucci\JWT\Configuration::__construct * @uses \Lcobucci\JWT\Signer\None * @uses \Lcobucci\JWT\Signer\Key\InMemory */ - public function getValidatorShouldReturnTheDefaultWhenItWasNotConfigured(): void + public function validatorShouldReturnTheDefaultWhenItWasNotConfigured(): void { $config = Configuration::forUnsecuredSigner(); - $validator = $config->getValidator(); + $validator = $config->validator(); self::assertNotSame($this->validator, $validator); } @@ -260,7 +260,7 @@ public function getValidatorShouldReturnTheDefaultWhenItWasNotConfigured(): void /** * @test * - * @covers ::getValidator + * @covers ::validator * @covers ::setValidator * * @uses \Lcobucci\JWT\Configuration::forUnsecuredSigner @@ -268,35 +268,35 @@ public function getValidatorShouldReturnTheDefaultWhenItWasNotConfigured(): void * @uses \Lcobucci\JWT\Signer\None * @uses \Lcobucci\JWT\Signer\Key\InMemory */ - public function getValidatorShouldReturnTheConfiguredValidator(): void + public function validatorShouldReturnTheConfiguredValidator(): void { $config = Configuration::forUnsecuredSigner(); $config->setValidator($this->validator); - self::assertSame($this->validator, $config->getValidator()); + self::assertSame($this->validator, $config->validator()); } /** * @test * - * @covers ::getValidationConstraints + * @covers ::validationConstraints * * @uses \Lcobucci\JWT\Configuration::forUnsecuredSigner * @uses \Lcobucci\JWT\Configuration::__construct * @uses \Lcobucci\JWT\Signer\None * @uses \Lcobucci\JWT\Signer\Key\InMemory */ - public function getValidationConstraintsShouldReturnAnEmptyArrayWhenItWasNotConfigured(): void + public function validationConstraintsShouldReturnAnEmptyArrayWhenItWasNotConfigured(): void { $config = Configuration::forUnsecuredSigner(); - self::assertSame([], $config->getValidationConstraints()); + self::assertSame([], $config->validationConstraints()); } /** * @test * - * @covers ::getValidationConstraints + * @covers ::validationConstraints * @covers ::setValidationConstraints * * @uses \Lcobucci\JWT\Configuration::forUnsecuredSigner @@ -304,18 +304,18 @@ public function getValidationConstraintsShouldReturnAnEmptyArrayWhenItWasNotConf * @uses \Lcobucci\JWT\Signer\None * @uses \Lcobucci\JWT\Signer\Key\InMemory */ - public function getValidationConstraintsShouldReturnTheConfiguredValidator(): void + public function validationConstraintsShouldReturnTheConfiguredValidator(): void { $config = Configuration::forUnsecuredSigner(); $config->setValidationConstraints($this->validationConstraints); - self::assertSame([$this->validationConstraints], $config->getValidationConstraints()); + self::assertSame([$this->validationConstraints], $config->validationConstraints()); } /** * @test * - * @covers ::createBuilder + * @covers ::builder * * @uses \Lcobucci\JWT\Configuration::forUnsecuredSigner * @uses \Lcobucci\JWT\Configuration::__construct @@ -327,6 +327,6 @@ public function customClaimFormatterCanBeUsed(): void $formatter = $this->createMock(ClaimsFormatter::class); $config = Configuration::forUnsecuredSigner(); - self::assertEquals(new BuilderImpl(new JoseEncoder(), $formatter), $config->createBuilder($formatter)); + self::assertEquals(new BuilderImpl(new JoseEncoder(), $formatter), $config->builder($formatter)); } }