Skip to content

Commit 03bd5f1

Browse files
committed
Adapted tests to verify that the request is checked for validity before asking for a token
1 parent b57259f commit 03bd5f1

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

tests/ZfrOAuth2ModuleTest/Server/Authentication/AuthenticationFunctionalTest.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ public function testSuccessAuthenticationOnValidToken()
7777
$owner = $this->getMock('ZfrOAuth2\Server\Entity\TokenOwnerInterface');
7878
$token->setOwner($owner);
7979

80+
$this
81+
->resourceServer
82+
->expects($this->atLeastOnce())
83+
->method('isRequestValid')
84+
->with($request)
85+
->will($this->returnValue(true));
86+
8087
$this
8188
->resourceServer
8289
->expects($this->atLeastOnce())
@@ -102,9 +109,11 @@ public function testFailAuthenticationOnNoToken()
102109
$this
103110
->resourceServer
104111
->expects($this->atLeastOnce())
105-
->method('getAccessToken')
112+
->method('isRequestValid')
106113
->with($request)
107-
->will($this->returnValue(null));
114+
->will($this->returnValue(false));
115+
116+
$this->resourceServer->expects($this->never())->method('getAccessToken');
108117

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

132+
$this
133+
->resourceServer
134+
->expects($this->atLeastOnce())
135+
->method('isRequestValid')
136+
->with($request)
137+
->will($this->returnValue(true));
138+
123139
$this
124140
->resourceServer
125141
->expects($this->atLeastOnce())
@@ -134,6 +150,7 @@ public function testFailAuthenticationOnExpiredToken()
134150

135151
public function testFailAuthenticationOnNoRequest()
136152
{
153+
$this->resourceServer->expects($this->never())->method('isRequestValid');
137154
$this->resourceServer->expects($this->never())->method('getAccessToken');
138155

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

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

166+
$this->resourceServer->expects($this->never())->method('isRequestValid');
149167
$this->resourceServer->expects($this->never())->method('getAccessToken');
150168

151169
$this->assertFalse($this->authenticationService->hasIdentity());

tests/ZfrOAuth2ModuleTest/Server/Authentication/Storage/AccessTokenStorageTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ public function testIsConsideredAsEmptyIfNoAccessToken()
6565
{
6666
$this->resourceServer
6767
->expects($this->atLeastOnce())
68-
->method('getAccessToken')
68+
->method('isRequestValid')
6969
->with($this->request)
70-
->will($this->returnValue(null));
70+
->will($this->returnValue(false));
71+
72+
$this->resourceServer->expects($this->never())->method('getAccessToken');
7173

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

8183
$token->setOwner($owner);
8284

85+
$this->resourceServer
86+
->expects($this->atLeastOnce())
87+
->method('isRequestValid')
88+
->with($this->request)
89+
->will($this->returnValue(true));
90+
8391
$this->resourceServer
8492
->expects($this->atLeastOnce())
8593
->method('getAccessToken')

0 commit comments

Comments
 (0)