Skip to content

Commit

Permalink
style: Apply coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
albertemozo committed Oct 9, 2017
1 parent 1b29487 commit 9e73f76
Show file tree
Hide file tree
Showing 17 changed files with 106 additions and 84 deletions.
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Expand Up @@ -110,7 +110,7 @@ public function getConfigTreeBuilder()
->ifTrue(function ($display) {
return !Configuration::isHttpMethodSupported($display);
})
->thenInvalid('Unknown request mathod "%s".')
->thenInvalid('Unknown request method "%s".')
->end()
->defaultValue('POST')->end()

Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/SyntelixOidcRelyingPartyExtension.php
Expand Up @@ -89,7 +89,7 @@ private function configureBuzz(ContainerBuilder $container, $config)
}

/**
* Add issuer URL to the begining of each endpoint url.
* Add issuer URL to the beginning of each endpoint url.
*
* @param array $config
*/
Expand Down
11 changes: 7 additions & 4 deletions OpenIdConnect/JWK/JWKSetHandler.php
Expand Up @@ -6,8 +6,11 @@
use Buzz\Message\Request as HttpClientRequest;
use Buzz\Message\Response as HttpClientResponse;
use Buzz\Message\RequestInterface;
use DateInterval;
use DateTime;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
use Symfony\Component\Serializer\Encoder\JsonDecode;
use Symfony\Component\Serializer\Encoder\JsonEncoder;

Expand Down Expand Up @@ -110,13 +113,13 @@ private function refreshCache($url)

$needToBeUpdate = false;

$now = new \DateTime('Now');
$now = new DateTime('Now');

/* @var $file Symfony\Component\Finder\SplFileInfo */
/* @var $file SplFileInfo */
foreach ($files as $file) {
$ctime = new \DateTime();
$ctime = new DateTime();
$ctime->setTimestamp($file->getCTime());
$ctime->add(new \DateInterval(sprintf('PT%dS', $this->jwkCacheTtl)));
$ctime->add(new DateInterval(sprintf('PT%dS', $this->jwkCacheTtl)));

$needToBeUpdate |= $ctime < $now;
}
Expand Down
2 changes: 1 addition & 1 deletion OpenIdConnect/NonceHelper.php
Expand Up @@ -109,7 +109,7 @@ public function generateNonce($uniqueValue)
* @param mixed $responseNonce the nonce reply by the OpenID Connect Provider
*
* @return bool
* @internal param mixed $uniqueValue the same as this passed to the generateNonce mehode
* @internal param mixed $uniqueValue the same as this passed to the generateNonce method
*/
public function isNonceValid($type, $responseNonce)
{
Expand Down
2 changes: 1 addition & 1 deletion OpenIdConnect/ResourceOwnerInterface.php
Expand Up @@ -34,7 +34,7 @@ public function getTokenEndpointUrl();
public function getUserinfoEndpointUrl();

/**
* Use the code parameter set in request query for retrieve the enduser informations.
* Use the code parameter set in request query for retrieve the end user information.
*
* @param Request $request
*
Expand Down
2 changes: 1 addition & 1 deletion Security/Core/Exception/InvalidRequestException.php
Expand Up @@ -14,6 +14,6 @@ class InvalidRequestException extends InvalidArgumentException
*/
public function getMessageKey()
{
return 'Invalide request';
return 'Invalid request';
}
}
2 changes: 1 addition & 1 deletion Security/Core/Exception/InvalidResponseTypeException.php
Expand Up @@ -14,6 +14,6 @@ class InvalidResponseTypeException extends InvalidArgumentException
*/
public function getMessageKey()
{
return 'Response type used is unknow';
return 'Response type used is unknown';
}
}
2 changes: 1 addition & 1 deletion Security/Http/Logout/OICLogout.php
Expand Up @@ -62,7 +62,7 @@ public function logout(Request $request)

$redirectResponse = new RedirectResponse($this->getRedirectAfterLogoutURI($request));

if ($request->server->get('HTTP_REFERER') != $this->httpUtils->generateUri($request, '_oic_rp_logout')) {
if ($request->server->get('HTTP_REFERRER') != $this->httpUtils->generateUri($request, '_oic_rp_logout')) {
$redirectResponse = new RedirectResponse($this->getRedirectAfterLogoutURI($request));
}

Expand Down
Expand Up @@ -19,7 +19,7 @@ public function testDefault()
$container = new ContainerBuilder();
$loader = new SyntelixOidcRelyingPartyExtension();
$config = array($this->getFullConfig());
$loader->load(array($this->getFullConfig()), $container);
$loader->load($config, $container);

$definitionArray = array(
'syntelix_oidc_rp.authentication.listener',
Expand Down
18 changes: 18 additions & 0 deletions Tests/Mocks/HttpClientMock.php
Expand Up @@ -14,9 +14,19 @@
*/
class HttpClientMock extends AbstractCurl
{
/**
* @var null
*/
public $response = null;
/**
* @var
*/
public $request;

/**
* @param RequestInterface $request
* @param MessageInterface $response
*/
public function send(RequestInterface $request, MessageInterface $response)
{
$this->request = $request;
Expand All @@ -25,11 +35,19 @@ public function send(RequestInterface $request, MessageInterface $response)
$response->setContent($this->response->getContent());
}

/**
* @return mixed
*/
public function getRequest()
{
return $this->request;
}

/**
* @param $isOk
* @param $headers
* @param $content
*/
public function setResponseContent($isOk, $headers, $content)
{
$this->response = new Response();
Expand Down
28 changes: 14 additions & 14 deletions Tests/OpenIdConnect/Constraint/IDTokenValidatorTest.php
Expand Up @@ -14,7 +14,7 @@ class IDTokenValidatorTest extends TestCase
{
private $options = array(
'issuer' => 'anIssuer',
'client_id' => 'anclient_id',
'client_id' => 'a_client_id',
'token_ttl' => 3600,
'authentication_ttl' => 3600,
);
Expand All @@ -25,16 +25,16 @@ public function setUp()
$this->token = array(
'claims' => array(
'iss' => 'anIssuer',
'aud' => 'anclient_id',
'azp' => 'anclient_id',
'aud' => 'a_client_id',
'azp' => 'a_client_id',
'exp' => (time() + 3600),
'iat' => time(),
'auth_time' => time(),
),
);
}

public function testAllSouldBeGood()
public function testAllShouldBeGood()
{
$validator = new IDTokenValidator($this->options);

Expand All @@ -44,7 +44,7 @@ public function testAllSouldBeGood()
$this->assertTrue($res);
}

public function testAllSouldBeGoodWithoutTime()
public function testAllShouldBeGoodWithoutTime()
{
$this->options['authentication_ttl'] = null;
$validator = new IDTokenValidator($this->options);
Expand All @@ -55,7 +55,7 @@ public function testAllSouldBeGoodWithoutTime()
$this->assertTrue($res);
}

public function testAllSouldNotFailWithoutTime()
public function testAllShouldNotFailWithoutTime()
{
unset($this->token['claims']['auth_time']);

Expand All @@ -67,9 +67,9 @@ public function testAllSouldNotFailWithoutTime()
$this->assertTrue($res);
}

public function testAllSouldBeGoodAud()
public function testAllShouldBeGoodAdd()
{
$this->token['claims']['aud'] = array('anclient_id', 'anclient_id2');
$this->token['claims']['aud'] = array('a_client_id', 'a_client_id2');

$validator = new IDTokenValidator($this->options);

Expand All @@ -79,9 +79,9 @@ public function testAllSouldBeGoodAud()
$this->assertTrue($res);
}

public function testAllSouldBeGoodAudSecond()
public function testAllShouldBeGoodAddSecond()
{
$this->token['claims']['aud'] = array('anclient_id');
$this->token['claims']['aud'] = array('a_client_id');

$validator = new IDTokenValidator($this->options);

Expand All @@ -91,7 +91,7 @@ public function testAllSouldBeGoodAudSecond()
$this->assertTrue($res);
}

public function testAllSouldFaildAtIssuer()
public function testAllShouldFailAtIssuer()
{
$this->options['issuer'] = 'fake';
$validator = new IDTokenValidator($this->options);
Expand All @@ -102,7 +102,7 @@ public function testAllSouldFaildAtIssuer()
$this->assertFalse($res);
}

public function testAllSouldFaildAtClient()
public function testAllShouldFailAtClient()
{
$this->token['claims']['aud'] = new IDTokenValidator($this->options);
$this->token['claims']['azp'] = new IDTokenValidator($this->options);
Expand All @@ -114,9 +114,9 @@ public function testAllSouldFaildAtClient()
$this->assertFalse($res);
}

public function testAllSouldFaildAtAzp()
public function testAllShouldFailAtAzp()
{
$this->token['claims']['aud'] = array('anclient_id', 'anclient_id2');
$this->token['claims']['aud'] = array('a_client_id', 'a_client_id2');
unset($this->token['claims']['azp']);
$validator = new IDTokenValidator($this->options);

Expand Down
2 changes: 1 addition & 1 deletion Tests/OpenIdConnect/JWK/JWKSetHandlerTest.php
Expand Up @@ -40,7 +40,7 @@ private static function clearCache()
$fs->remove(sys_get_temp_dir().'/syntelix');
}

public function testGetJwkShoulReturnFalse()
public function testGetJwkShouldReturnFalse()
{
$httpClient = new HttpClientMock();
$jWKSetHandler = new JWKSetHandler(null, 1, '', $httpClient);
Expand Down
35 changes: 18 additions & 17 deletions Tests/OpenIdConnect/NonceHelperTest.php
Expand Up @@ -4,6 +4,7 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;

/**
* Nonce.
Expand All @@ -14,12 +15,12 @@ class NonceHelperTest extends TestCase
{
public function testBuildNonceValue()
{
$ession = $this->createMock('Symfony\Component\HttpFoundation\Session\Session');
$ession->expects($this->once())
$session = $this->createMock('Symfony\Component\HttpFoundation\Session\Session');
$session->expects($this->once())
->method('set')
->with($this->equalTo('auth.oic.test'), $this->anything());

$nonceHelper = new NonceHelper($ession, array('nonce' => true, 'state' => true));
$nonceHelper = new NonceHelper($session, array('nonce' => true, 'state' => true));

$nonce = $nonceHelper->buildNonceValue('amy', 'test');

Expand All @@ -29,12 +30,12 @@ public function testBuildNonceValue()

public function testBuildNonceValueGreaterThan255()
{
$ession = $this->createMock('Symfony\Component\HttpFoundation\Session\Session');
$ession->expects($this->once())
$session = $this->createMock('Symfony\Component\HttpFoundation\Session\Session');
$session->expects($this->once())
->method('set')
->with($this->equalTo('auth.oic.test'), $this->anything());

$nonceHelper = new NonceHelper($ession, array('nonce' => true, 'state' => true));
$nonceHelper = new NonceHelper($session, array('nonce' => true, 'state' => true));

$nonce = $nonceHelper->buildNonceValue(hash('SHA512', 'amy').hash('SHA512', 'amy'), 'test');

Expand All @@ -45,14 +46,14 @@ public function testBuildNonceValueGreaterThan255()
public function testCheckStateAndNonceShouldBeValid()
{
$request = new Request();
$request->query->set('state', 'unevaleur');
$request->query->set('nonce', 'unevaleur');
$request->query->set('state', 'value');
$request->query->set('nonce', 'value');

$ession = $this->createMock('Symfony\Component\HttpFoundation\Session\Session');
$ession->expects($this->exactly(2))
$session = $this->createMock('Symfony\Component\HttpFoundation\Session\Session');
$session->expects($this->exactly(2))
->method('get')
->willReturn(serialize('unevaleur'));
$nonceHelper = new NonceHelper($ession, array('nonce' => true, 'state' => true));
->willReturn(serialize('value'));
$nonceHelper = new NonceHelper($session, array('nonce' => true, 'state' => true));

$nonceHelper->checkStateAndNonce($request);
}
Expand All @@ -63,14 +64,14 @@ public function testCheckStateAndNonceShouldBeValid()
public function testCheckStateAndNonceShouldFail()
{
$request = new Request();
$request->query->set('state', 'unevaleur');
$request->query->set('nonce', 'unevaleur');
$request->query->set('state', 'value');
$request->query->set('nonce', 'value');

$ession = $this->createMock('Symfony\Component\HttpFoundation\Session\Session');
$ession->expects($this->once())
$session = $this->createMock(Session::class);
$session->expects($this->once())
->method('get')
->willReturn(serialize('error'));
$nonceHelper = new NonceHelper($ession, array('nonce' => true, 'state' => true));
$nonceHelper = new NonceHelper($session, array('nonce' => true, 'state' => true));

$nonceHelper->checkStateAndNonce($request);
}
Expand Down

0 comments on commit 9e73f76

Please sign in to comment.