|
2 | 2 |
|
3 | 3 | namespace Pdsinterop\Solid\Auth\Utils; |
4 | 4 |
|
| 5 | +use Laminas\Diactoros\ServerRequest; |
5 | 6 | use Pdsinterop\Solid\Auth\AbstractTestCase; |
6 | 7 | use Lcobucci\JWT\Validation\RequiredConstraintsViolated; |
7 | 8 |
|
@@ -54,7 +55,7 @@ protected function setUp(): void |
54 | 55 | ]); |
55 | 56 |
|
56 | 57 | $this->url = 'https://www.example.com'; |
57 | | - $this->serverRequest = new \Laminas\Diactoros\ServerRequest(array(),array(), $this->url); |
| 58 | + $this->serverRequest = new ServerRequest(array(),array(), $this->url); |
58 | 59 | } |
59 | 60 |
|
60 | 61 | private function getWrongKey() |
@@ -179,7 +180,62 @@ public function testValidateDpopWithCorrectToken(): void |
179 | 180 | $this->assertTrue($result); |
180 | 181 | } |
181 | 182 |
|
182 | | - // getWebId |
| 183 | + final public function testGetWebIdWithoutRequest(): void |
| 184 | + { |
| 185 | + $dpop = new DPop(); |
| 186 | + |
| 187 | + $this->expectArgumentCountError(1); |
| 188 | + |
| 189 | + $dpop->getWebId(); |
| 190 | + } |
| 191 | + |
| 192 | + /** |
| 193 | + * @covers ::getWebId |
| 194 | + */ |
| 195 | + final public function testGetWebIdWithoutHttpAuthorizationHeader(): void |
| 196 | + { |
| 197 | + |
| 198 | + $dpop = new DPop(); |
| 199 | + |
| 200 | + $request = new ServerRequest(array(),array(), $this->url); |
| 201 | + |
| 202 | + $this->markTestIncomplete('The current result is not testable (Undefined array key "HTTP_AUTHORIZATION")'); |
| 203 | + |
| 204 | + $dpop->getWebId($request); |
| 205 | + } |
| 206 | + |
| 207 | + /** |
| 208 | + * @covers ::getWebId |
| 209 | + */ |
| 210 | + final public function testGetWebIdWithInvalidJwt(): void |
| 211 | + { |
| 212 | + $dpop = new DPop(); |
| 213 | + |
| 214 | + $this->expectException(\Exception::class); |
| 215 | + $this->expectExceptionMessage('Invalid JWT token'); |
| 216 | + |
| 217 | + $request = new ServerRequest(array('HTTP_AUTHORIZATION' => 'Invalid JWT'),array(), $this->url); |
| 218 | + |
| 219 | + $dpop->getWebId($request); |
| 220 | + } |
| 221 | + |
| 222 | + |
| 223 | + /** |
| 224 | + * @covers ::getWebId |
| 225 | + */ |
| 226 | + final public function testGetWebId(): void |
| 227 | + { |
| 228 | + $dpop = new DPop(); |
| 229 | + |
| 230 | + $token = $this->sign($this->dpop)['token']; |
| 231 | + |
| 232 | + $request = new ServerRequest(array('HTTP_AUTHORIZATION' => $token),array(), $this->url); |
| 233 | + |
| 234 | + $actual = $dpop->getWebId($request); |
| 235 | + $expected = 'public'; |
| 236 | + |
| 237 | + $this->assertEquals($expected, $actual); |
| 238 | + } |
183 | 239 |
|
184 | 240 | /////////////////////////////// DATAPROVIDERS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ |
185 | 241 |
|
|
0 commit comments