Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
odino authored and cirpo committed Jun 16, 2015
1 parent 190df49 commit 2fc7736
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Namshi/JOSE/JWS.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static function load($jwsTokenString, $allowUnsecure = false, Encoder $en
$payload = json_decode($encoder->decode($parts[1]), true);

if (is_array($header) && is_array($payload)) {
if ($header['alg'] === 'None' && !$allowUnsecure) {
if (strtolower($header['alg']) === 'none' && !$allowUnsecure) {
throw new InvalidArgumentException(sprintf('The token "%s" cannot be validated in a secure context, as it uses the unallowed "none" algorithm', $jwsTokenString));
}

Expand Down
23 changes: 22 additions & 1 deletion tests/Namshi/JOSE/Test/JWSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function setup()
/**
* @expectedException InvalidArgumentException
*/
public function testLoadingUnsecureJws()
public function testLoadingUnsecureJwsWithNoneAlgo()
{
$date = new DateTime('tomorrow');
$data = array(
Expand All @@ -42,6 +42,27 @@ public function testLoadingUnsecureJws()
$payload = $jws->getPayload();
$this->assertEquals('b', $payload['a']);
}

/**
* @expectedException InvalidArgumentException
*/
public function testLoadingUnsecureJwsWithLowercaseNone()
{
$date = new DateTime('tomorrow');
$data = array(
'a' => 'b',
'exp' => $date->format('U')
);
$this->jws = new JWS(array('alg' => 'none'));
$this->jws->setPayload($data);
$this->jws->sign('111');

$jws = JWS::load($this->jws->getTokenString());
$this->assertFalse($jws->verify('111'));

$payload = $jws->getPayload();
$this->assertEquals('b', $payload['a']);
}

public function testAllowingUnsecureJws()
{
Expand Down

0 comments on commit 2fc7736

Please sign in to comment.