Skip to content

Commit

Permalink
Add time_to_live option to UsernamePasswordAuthenticator
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrik Bjornskov committed Sep 15, 2015
1 parent 1ca2278 commit 07d2398
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions DependencyInjection/AntennaExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class AntennaExtension extends \Symfony\Component\HttpKernel\DependencyInjection
protected function loadInternal(array $mergedConfig, ContainerBuilder $container)
{
$container->setParameter('antenna.shared_secret', $mergedConfig['secret']);
$container->setParameter('antenna.time_to_live', $mergedConfig['time_to_live']);

$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');
Expand Down
3 changes: 3 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public function getConfigTreeBuilder()
->isRequired()
->cannotBeEmpty()
->end()
->scalarNode('time_to_live')
->defaultValue('7 days')
->end()
->end()
;

Expand Down
3 changes: 3 additions & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<argument type="service" id="security.user_checker" />
<argument type="service" id="security.password_encoder" />
<argument type="service" id="antenna.coder" />
<argument type="collection">
<argument key="time_to_live">%antenna.time_to_live%</argument>
</argument>
</service>

<service id="antenna.token_authenticator" class="Antenna\Security\TokenAuthenticator">
Expand Down
37 changes: 37 additions & 0 deletions Tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Flint\Bundle\AntennaBundle\Tests\DependencyInjection;

use Flint\Bundle\AntennaBundle\DependencyInjection\Configuration;
use Matthias\SymfonyConfigTest\PhpUnit\AbstractConfigurationTestCase;

class ConfigurationTest extends AbstractConfigurationTestCase
{
protected function getConfiguration()
{
return new Configuration();
}

public function testSecretIsRequired()
{
$this->assertConfigurationIsInvalid([], 'The child node "secret" at path "antenna" must be configured.');
}

/**
* @dataProvider configurationSets
*/
public function testConfiguration($config, $expectedConfig)
{
$mergedConfigs = [$config];

$this->assertProcessedConfigurationEquals($mergedConfigs, $expectedConfig);
}

public function configurationSets()
{
return [
[['secret' => 'my_secret'], ['secret' => 'my_secret', 'time_to_live' => '7 days']],
[['secret' => 'my_secret', 'time_to_live' => '10 days'], ['secret' => 'my_secret', 'time_to_live' => '10 days']],
];
}
}
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
},

"require" : {
"flint/antenna" : "~1.0",
"flint/antenna" : "~1.2",
"symfony/security-bundle" : "~2.7",
"symfony/framework-bundle" : "~2.7"
},

"require-dev" : {
"symfony/finder" : "~2.7"
"symfony/finder" : "~2.7",
"matthiasnoback/symfony-config-test" : "~1.2"
}
}

0 comments on commit 07d2398

Please sign in to comment.