Skip to content

Commit

Permalink
Cache support for X5U and JKU methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Florent Morselli committed Jul 7, 2016
1 parent 34d7f4b commit a88e8f9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"phpseclib/phpseclib": "^2.0",
"beberlei/assert": "^2.0",
"psr/log": "^1.0",
"symfony/polyfill-php56": "^1.1",
"symfony/polyfill-mbstring": "^1.1",
"symfony/polyfill-php70": "^1.1",
"fgrosse/phpasn1": "^1.5",
Expand All @@ -42,14 +41,15 @@
},
"require-dev": {
"phpunit/phpunit": "^5.0",
"satooshi/php-coveralls": "^1.0"
"satooshi/php-coveralls": "^1.0",
"symfony/cache": "^2.7|^3.0"
},
"suggest":{
"ext-crypto": "Highly recommended when you use AES GCM based algorithms."
},
"extra": {
"branch-alias": {
"dev-master": "4.0.x-dev"
"dev-master": "4.1.x-dev"
}
}
}
34 changes: 34 additions & 0 deletions tests/Unit/Objects/JWKFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Jose\Factory\JWKFactory;
use Jose\Object\JWKInterface;
use Jose\Object\JWKSetInterface;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

/**
* Class JWKFactoryTest.
Expand Down Expand Up @@ -125,6 +126,20 @@ public function testCreateFromJKU()
$this->assertTrue(0 !== $result->count());
}

public function testCreateFromJKUWithCache()
{
$url = 'https://www.googleapis.com/oauth2/v3/certs';
$cache = new FilesystemAdapter();
$cache_key = $this->getCacheKey($url);
$cache->clear();

$result = JWKFactory::createFromJKU($url, false, $cache);

$this->assertInstanceOf(JWKSetInterface::class, $result);
$this->assertTrue(0 !== $result->count());
$this->assertTrue($cache->hasItem($cache_key));
}

public function testCreateFromX5U()
{
$result = JWKFactory::createFromX5U('https://www.googleapis.com/oauth2/v1/certs');
Expand All @@ -133,6 +148,20 @@ public function testCreateFromX5U()
$this->assertTrue(0 !== $result->count());
}

public function testCreateFromX5UWithCache()
{
$url = 'https://www.googleapis.com/oauth2/v1/certs';
$cache = new FilesystemAdapter();
$cache_key = $this->getCacheKey($url);
$cache->clear();

$result = JWKFactory::createFromX5U($url, false, $cache);

$this->assertInstanceOf(JWKSetInterface::class, $result);
$this->assertTrue(0 !== $result->count());
$this->assertTrue($cache->hasItem($cache_key));
}

public function testCreateFromValues()
{
$result = JWKFactory::createFromValues([
Expand All @@ -147,4 +176,9 @@ public function testCreateFromValues()
$this->assertInstanceOf(JWKInterface::class, $result);
$this->assertEquals('{"kty":"EC","crv":"P-521","d":"Fp6KFKRiHIdR_7PP2VKxz6OkS_phyoQqwzv2I89-8zP7QScrx5r8GFLcN5mCCNJt3rN3SIgI4XoIQbNePlAj6vE","x":"AVpvo7TGpQk5P7ZLo0qkBpaT-fFDv6HQrWElBKMxcrJd_mRNapweATsVv83YON4lTIIRXzgGkmWeqbDr6RQO-1cS","y":"AIs-MoRmLaiPyG2xmPwQCHX2CGX_uCZiT3iOxTAJEZuUbeSA828K4WfAA4ODdGiB87YVShhPOkiQswV3LpbpPGhC"}', json_encode($result));
}

private function getCacheKey($url)
{
return sprintf('%s-%s', 'JWKFactory-Content', hash('sha512', $url));
}
}

0 comments on commit a88e8f9

Please sign in to comment.