From f5b813b66b0cfc472483fd0fba8cbdf64bc10031 Mon Sep 17 00:00:00 2001 From: Peter Date: Tue, 20 Dec 2022 18:51:07 +0800 Subject: [PATCH] Using the assertSame to make assert equals strict --- tests/CachedKeySetTest.php | 16 ++++++++-------- tests/JWKTest.php | 6 +++--- tests/JWTTest.php | 20 ++++++++++---------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/CachedKeySetTest.php b/tests/CachedKeySetTest.php index 73b1213d..91d4a27c 100644 --- a/tests/CachedKeySetTest.php +++ b/tests/CachedKeySetTest.php @@ -93,7 +93,7 @@ public function testWithExistingKeyId() $this->getMockEmptyCache() ); $this->assertInstanceOf(Key::class, $cachedKeySet['foo']); - $this->assertEquals('foo', $cachedKeySet['foo']->getAlgorithm()); + $this->assertSame('foo', $cachedKeySet['foo']->getAlgorithm()); } public function testWithDefaultAlg() @@ -108,7 +108,7 @@ public function testWithDefaultAlg() 'baz256' ); $this->assertInstanceOf(Key::class, $cachedKeySet['baz']); - $this->assertEquals('baz256', $cachedKeySet['baz']->getAlgorithm()); + $this->assertSame('baz256', $cachedKeySet['baz']->getAlgorithm()); } public function testKeyIdIsCached() @@ -132,7 +132,7 @@ public function testKeyIdIsCached() $cache->reveal() ); $this->assertInstanceOf(Key::class, $cachedKeySet['foo']); - $this->assertEquals('foo', $cachedKeySet['foo']->getAlgorithm()); + $this->assertSame('foo', $cachedKeySet['foo']->getAlgorithm()); } public function testCachedKeyIdRefresh() @@ -165,10 +165,10 @@ public function testCachedKeyIdRefresh() $cache->reveal() ); $this->assertInstanceOf(Key::class, $cachedKeySet['foo']); - $this->assertEquals('foo', $cachedKeySet['foo']->getAlgorithm()); + $this->assertSame('foo', $cachedKeySet['foo']->getAlgorithm()); $this->assertInstanceOf(Key::class, $cachedKeySet['bar']); - $this->assertEquals('bar', $cachedKeySet['bar']->getAlgorithm()); + $this->assertSame('bar', $cachedKeySet['bar']->getAlgorithm()); } public function testCacheItemWithExpiresAfter() @@ -204,7 +204,7 @@ public function testCacheItemWithExpiresAfter() $expiresAfter ); $this->assertInstanceOf(Key::class, $cachedKeySet['foo']); - $this->assertEquals('foo', $cachedKeySet['foo']->getAlgorithm()); + $this->assertSame('foo', $cachedKeySet['foo']->getAlgorithm()); } public function testJwtVerify() @@ -233,7 +233,7 @@ public function testJwtVerify() $result = JWT::decode($msg, $cachedKeySet); - $this->assertEquals('foo', $result->sub); + $this->assertSame('foo', $result->sub); } public function testRateLimit() @@ -290,7 +290,7 @@ public function testFullIntegration(string $jwkUri): void $this->assertArrayHasKey($kid, $cachedKeySet); $key = $cachedKeySet[$kid]; $this->assertInstanceOf(Key::class, $key); - $this->assertEquals($keys['keys'][0]['alg'], $key->getAlgorithm()); + $this->assertSame($keys['keys'][0]['alg'], $key->getAlgorithm()); } public function provideFullIntegration() diff --git a/tests/JWKTest.php b/tests/JWKTest.php index b8c24f98..93afea70 100644 --- a/tests/JWKTest.php +++ b/tests/JWKTest.php @@ -67,7 +67,7 @@ public function testParsePrivateKeyWithoutAlgWithDefaultAlgParameter() unset($jwkSet['keys'][0]['alg']); $jwks = JWK::parseKeySet($jwkSet, 'foo'); - $this->assertEquals('foo', $jwks['jwk1']->getAlgorithm()); + $this->assertSame('foo', $jwks['jwk1']->getAlgorithm()); } public function testParseKeyWithEmptyDValue() @@ -143,7 +143,7 @@ public function testDecodeByJwkKeySet($pemFile, $jwkFile, $alg) $keys = JWK::parseKeySet($jwkSet); $result = JWT::decode($msg, $keys); - $this->assertEquals('foo', $result->sub); + $this->assertSame('foo', $result->sub); } public function provideDecodeByJwkKeySet() @@ -165,6 +165,6 @@ public function testDecodeByMultiJwkKeySet() $result = JWT::decode($msg, self::$keys); - $this->assertEquals('bar', $result->sub); + $this->assertSame('bar', $result->sub); } } diff --git a/tests/JWTTest.php b/tests/JWTTest.php index e3b95144..3ce912ed 100644 --- a/tests/JWTTest.php +++ b/tests/JWTTest.php @@ -73,7 +73,7 @@ public function testValidToken() ]; $encoded = JWT::encode($payload, 'my_key', 'HS256'); $decoded = JWT::decode($encoded, new Key('my_key', 'HS256')); - $this->assertEquals($decoded->message, 'abc'); + $this->assertSame($decoded->message, 'abc'); } public function testValidTokenWithLeeway() @@ -85,7 +85,7 @@ public function testValidTokenWithLeeway() ]; $encoded = JWT::encode($payload, 'my_key', 'HS256'); $decoded = JWT::decode($encoded, new Key('my_key', 'HS256')); - $this->assertEquals($decoded->message, 'abc'); + $this->assertSame($decoded->message, 'abc'); JWT::$leeway = 0; } @@ -99,7 +99,7 @@ public function testExpiredTokenWithLeeway() $this->expectException(ExpiredException::class); $encoded = JWT::encode($payload, 'my_key', 'HS256'); $decoded = JWT::decode($encoded, new Key('my_key', 'HS256')); - $this->assertEquals($decoded->message, 'abc'); + $this->assertSame($decoded->message, 'abc'); JWT::$leeway = 0; } @@ -113,7 +113,7 @@ public function testValidTokenWithNbf() ]; $encoded = JWT::encode($payload, 'my_key', 'HS256'); $decoded = JWT::decode($encoded, new Key('my_key', 'HS256')); - $this->assertEquals($decoded->message, 'abc'); + $this->assertSame($decoded->message, 'abc'); } public function testValidTokenWithNbfLeeway() @@ -125,7 +125,7 @@ public function testValidTokenWithNbfLeeway() ]; $encoded = JWT::encode($payload, 'my_key', 'HS256'); $decoded = JWT::decode($encoded, new Key('my_key', 'HS256')); - $this->assertEquals($decoded->message, 'abc'); + $this->assertSame($decoded->message, 'abc'); JWT::$leeway = 0; } @@ -151,7 +151,7 @@ public function testValidTokenWithIatLeeway() ]; $encoded = JWT::encode($payload, 'my_key', 'HS256'); $decoded = JWT::decode($encoded, new Key('my_key', 'HS256')); - $this->assertEquals($decoded->message, 'abc'); + $this->assertSame($decoded->message, 'abc'); JWT::$leeway = 0; } @@ -301,7 +301,7 @@ public function testEdDsaEncodeDecode() $pubKey = base64_encode(sodium_crypto_sign_publickey($keyPair)); $decoded = JWT::decode($msg, new Key($pubKey, 'EdDSA')); - $this->assertEquals('bar', $decoded->foo); + $this->assertSame('bar', $decoded->foo); } public function testInvalidEdDsaEncodeDecode() @@ -350,7 +350,7 @@ public function testDecodesArraysInJWTAsArray() $payload = ['foo' => [1, 2, 3]]; $jwt = JWT::encode($payload, $key, 'HS256'); $decoded = JWT::decode($jwt, new Key($key, 'HS256')); - $this->assertEquals($payload['foo'], $decoded->foo); + $this->assertSame($payload['foo'], $decoded->foo); } /** @@ -367,7 +367,7 @@ public function testEncodeDecode($privateKeyFile, $publicKeyFile, $alg) $publicKey = file_get_contents($publicKeyFile); $decoded = JWT::decode($encoded, new Key($publicKey, $alg)); - $this->assertEquals('bar', $decoded->foo); + $this->assertSame('bar', $decoded->foo); } public function provideEncodeDecode() @@ -393,6 +393,6 @@ public function testEncodeDecodeWithResource() // Verify decoding succeeds $decoded = JWT::decode($encoded, new Key($resource, 'RS512')); - $this->assertEquals('bar', $decoded->foo); + $this->assertSame('bar', $decoded->foo); } }