Skip to content

Commit

Permalink
#325 Move ttl is_numeric check from build time to runtime to allow …
Browse files Browse the repository at this point in the history
…use of %env()% (@drbenton)

Fix: Move `is_numeric` check from build time to runtime
  • Loading branch information
chalasr authored Apr 14, 2017
2 parents 4b6f328 + 47f3b31 commit 5b09887
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
6 changes: 0 additions & 6 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ public function getConfigTreeBuilder()
->end()
->scalarNode('token_ttl')
->defaultValue(3600)
->validate()
->ifTrue(function ($ttl) {
return !is_numeric($ttl);
})
->thenInvalid('The token_ttl must be a numeric value.')
->end()
->end()
->arrayNode('encoder')
->addDefaultsIfNotSet()
Expand Down
4 changes: 4 additions & 0 deletions Services/JWSProvider/DefaultJWSProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class DefaultJWSProvider implements JWSProviderInterface
*/
public function __construct(KeyLoaderInterface $keyLoader, $cryptoEngine, $signatureAlgorithm, $ttl)
{
if (!is_numeric($ttl)) {
throw new \InvalidArgumentException(sprintf('The TTL should be a numeric value, got %s instead.', $ttl));
}

$cryptoEngine = $cryptoEngine == 'openssl' ? 'OpenSSL' : 'SecLib';

if (!$this->isAlgorithmSupportedForEngine($cryptoEngine, $signatureAlgorithm)) {
Expand Down
4 changes: 4 additions & 0 deletions Services/JWSProvider/LcobucciJWSProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class LcobucciJWSProvider implements JWSProviderInterface
*/
public function __construct(RawKeyLoader $keyLoader, $cryptoEngine, $signatureAlgorithm, $ttl)
{
if (!is_numeric($ttl)) {
throw new \InvalidArgumentException(sprintf('The TTL should be a numeric value, got %s instead.', $ttl));
}

$this->keyLoader = $keyLoader;
$this->signer = $this->getSignerForAlgorithm($signatureAlgorithm);
$this->ttl = $ttl;
Expand Down
9 changes: 9 additions & 0 deletions Tests/Services/JWSProvider/AbstractJWSProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ public function testInvalidsignatureAlgorithm()
new static::$providerClass($this->getKeyLoaderMock(), 'openssl', 'wrongAlgorithm', 3600);
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The TTL should be a numeric value
*/
public function testInvalidTtl()
{
new static::$providerClass($this->getKeyLoaderMock(), 'openssl', 'wrongAlgorithm', 'invalid_ttl');
}

private function getKeyLoaderMock()
{
return $this
Expand Down

0 comments on commit 5b09887

Please sign in to comment.