Skip to content

Using the assertSame to make assert equals strict #478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 10, 2023
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
16 changes: 8 additions & 8 deletions tests/CachedKeySetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions tests/JWKTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -165,6 +165,6 @@ public function testDecodeByMultiJwkKeySet()

$result = JWT::decode($msg, self::$keys);

$this->assertEquals('bar', $result->sub);
$this->assertSame('bar', $result->sub);
}
}
20 changes: 10 additions & 10 deletions tests/JWTTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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()
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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()
Expand All @@ -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);
}
}