Skip to content

Commit

Permalink
Adapted tests to verify that the request is checked for validity befo…
Browse files Browse the repository at this point in the history
…re asking for a token
  • Loading branch information
Ocramius committed Apr 26, 2014
1 parent b57259f commit 03bd5f1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ public function testSuccessAuthenticationOnValidToken()
$owner = $this->getMock('ZfrOAuth2\Server\Entity\TokenOwnerInterface');
$token->setOwner($owner);

$this
->resourceServer
->expects($this->atLeastOnce())
->method('isRequestValid')
->with($request)
->will($this->returnValue(true));

$this
->resourceServer
->expects($this->atLeastOnce())
Expand All @@ -102,9 +109,11 @@ public function testFailAuthenticationOnNoToken()
$this
->resourceServer
->expects($this->atLeastOnce())
->method('getAccessToken')
->method('isRequestValid')
->with($request)
->will($this->returnValue(null));
->will($this->returnValue(false));

$this->resourceServer->expects($this->never())->method('getAccessToken');

$this->assertFalse($this->authenticationService->hasIdentity());
$this->assertNull($this->authenticationService->getIdentity());
Expand All @@ -120,6 +129,13 @@ public function testFailAuthenticationOnExpiredToken()
$owner = $this->getMock('ZfrOAuth2\Server\Entity\TokenOwnerInterface');
$token->setOwner($owner);

$this
->resourceServer
->expects($this->atLeastOnce())
->method('isRequestValid')
->with($request)
->will($this->returnValue(true));

$this
->resourceServer
->expects($this->atLeastOnce())
Expand All @@ -134,6 +150,7 @@ public function testFailAuthenticationOnExpiredToken()

public function testFailAuthenticationOnNoRequest()
{
$this->resourceServer->expects($this->never())->method('isRequestValid');
$this->resourceServer->expects($this->never())->method('getAccessToken');

$this->assertFalse($this->authenticationService->hasIdentity());
Expand All @@ -146,6 +163,7 @@ public function testFailAuthenticationOnNonHttpRequest()

$this->mvcEvent->expects($this->any())->method('getRequest')->will($this->returnValue($request));

$this->resourceServer->expects($this->never())->method('isRequestValid');
$this->resourceServer->expects($this->never())->method('getAccessToken');

$this->assertFalse($this->authenticationService->hasIdentity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ public function testIsConsideredAsEmptyIfNoAccessToken()
{
$this->resourceServer
->expects($this->atLeastOnce())
->method('getAccessToken')
->method('isRequestValid')
->with($this->request)
->will($this->returnValue(null));
->will($this->returnValue(false));

$this->resourceServer->expects($this->never())->method('getAccessToken');

$this->assertTrue($this->storage->isEmpty());
$this->assertNull($this->storage->read());
Expand All @@ -80,6 +82,12 @@ public function testReadOwnerFromAccessToken()

$token->setOwner($owner);

$this->resourceServer
->expects($this->atLeastOnce())
->method('isRequestValid')
->with($this->request)
->will($this->returnValue(true));

$this->resourceServer
->expects($this->atLeastOnce())
->method('getAccessToken')
Expand Down

0 comments on commit 03bd5f1

Please sign in to comment.