Skip to content

Commit

Permalink
Updated test to include test for no authorization.
Browse files Browse the repository at this point in the history
  • Loading branch information
frodosghost committed Jan 29, 2016
1 parent 80512a5 commit 96aa61a
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions Tests/Security/JWTAuthenticatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class JWTAuthenticatorTest extends \PHPUnit_Framework_TestCase
public function testTokenCreation()
{
$mockAuth0 = $this->getMockBuilder('Auth0\JWTAuthBundle\Security\Auth0Service')
->disableOriginalConstructor()
->getMock();
->disableOriginalConstructor()
->getMock();

$mockAuth0->expects($this->once())
->method('decodeJWT')
Expand All @@ -35,8 +35,34 @@ public function testTokenCreation()
$token = $authenticator->createToken($request, $providerKey);

$this->assertEquals('anon.',$token->GetUser());
$this->assertEquals($providerKey,$token->getProviderKey());
$this->assertEquals($providerKey,$token->getProviderKey());
$this->assertEquals($providerKey, $token->getProviderKey());
$this->assertEquals($providerKey, $token->getProviderKey());
}

public function testNoAuthorization()
{
$mockAuth0 = $this->getMockBuilder('Auth0\JWTAuthBundle\Security\Auth0Service')
->disableOriginalConstructor()
->getMock();

$authenticator = new JWTAuthenticator($mockAuth0);
$providerKey = 'providerKey';

$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
$request->headers = $this->getMock('Symfony\Component\HttpFoundation\ParameterBag');

$request->headers
->expects($this->once())
->method('get')
->with('Authorization')
->will($this->returnValue(NULL));

$token = $authenticator->createToken($request, $providerKey);

$this->assertInstanceOf('Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken', $token);

$this->assertEquals($providerKey, $token->getProviderKey());
$this->assertNull($token->getCredentials());
}

}

0 comments on commit 96aa61a

Please sign in to comment.