Skip to content
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

Fix: Move is_numeric check from build time to runtime #325

Merged
merged 1 commit into from
Apr 14, 2017
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
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