|
@@ 270-308 (lines=39) @@
|
| 267 |
|
], $actual->getData()); |
| 268 |
|
} |
| 269 |
|
|
| 270 |
|
public function testProxyRedirect() { |
| 271 |
|
$testUrl = 'http://abc.def/foobar?123'; |
| 272 |
|
|
| 273 |
|
$this->client->expects($this->once()) |
| 274 |
|
->method('newClient') |
| 275 |
|
->will($this->returnValue($this->newClient)); |
| 276 |
|
$this->newClient->expects($this->at(0)) |
| 277 |
|
->method('get') |
| 278 |
|
->with($testUrl, [ |
| 279 |
|
'allow_redirects' => false, |
| 280 |
|
]) |
| 281 |
|
->will($this->returnValue($this->response0)); |
| 282 |
|
$this->response0->expects($this->at(0)) |
| 283 |
|
->method('getStatusCode') |
| 284 |
|
->with() |
| 285 |
|
->will($this->returnValue(301)); |
| 286 |
|
$this->response0->expects($this->at(1)) |
| 287 |
|
->method('getHeader') |
| 288 |
|
->with('Location') |
| 289 |
|
->will($this->returnValue('http://def.abc/foobar?456')); |
| 290 |
|
$this->newClient->expects($this->at(1)) |
| 291 |
|
->method('get') |
| 292 |
|
->with('http://def.abc/foobar?456', [ |
| 293 |
|
'allow_redirects' => false, |
| 294 |
|
]) |
| 295 |
|
->will($this->returnValue($this->response0)); |
| 296 |
|
$this->response0->expects($this->at(2)) |
| 297 |
|
->method('getStatusCode') |
| 298 |
|
->with() |
| 299 |
|
->will($this->returnValue(200)); |
| 300 |
|
|
| 301 |
|
$actual = $this->controller->proxy($testUrl); |
| 302 |
|
|
| 303 |
|
$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual); |
| 304 |
|
$this->assertEquals([ |
| 305 |
|
'proxy_code' => -4, |
| 306 |
|
'new_url' => 'http://def.abc/foobar?456', |
| 307 |
|
], $actual->getData()); |
| 308 |
|
} |
| 309 |
|
|
| 310 |
|
public function testProxyRedirectNonPermanent() { |
| 311 |
|
$testUrl = 'http://abc.def/foobar?123'; |
|
@@ 404-442 (lines=39) @@
|
| 401 |
|
], $actual->getData()); |
| 402 |
|
} |
| 403 |
|
|
| 404 |
|
public function testProxyMultipleRedirectsNonPermanent() { |
| 405 |
|
$testUrl = 'http://abc.def/foobar?123'; |
| 406 |
|
|
| 407 |
|
$this->client->expects($this->once()) |
| 408 |
|
->method('newClient') |
| 409 |
|
->will($this->returnValue($this->newClient)); |
| 410 |
|
$this->newClient->expects($this->at(0)) |
| 411 |
|
->method('get') |
| 412 |
|
->with($testUrl, [ |
| 413 |
|
'allow_redirects' => false, |
| 414 |
|
]) |
| 415 |
|
->will($this->returnValue($this->response0)); |
| 416 |
|
$this->newClient->expects($this->at(1)) |
| 417 |
|
->method('get') |
| 418 |
|
->with('http://def.abc/foobar?456' , [ |
| 419 |
|
'allow_redirects' => false, |
| 420 |
|
]) |
| 421 |
|
->will($this->returnValue($this->response1)); |
| 422 |
|
$this->response0->expects($this->at(0)) |
| 423 |
|
->method('getStatusCode') |
| 424 |
|
->with() |
| 425 |
|
->will($this->returnValue(301)); |
| 426 |
|
$this->response0->expects($this->at(1)) |
| 427 |
|
->method('getHeader') |
| 428 |
|
->with('Location') |
| 429 |
|
->will($this->returnValue('http://def.abc/foobar?456')); |
| 430 |
|
$this->response1->expects($this->at(0)) |
| 431 |
|
->method('getStatusCode') |
| 432 |
|
->with() |
| 433 |
|
->will($this->returnValue(307)); |
| 434 |
|
|
| 435 |
|
$actual = $this->controller->proxy($testUrl); |
| 436 |
|
|
| 437 |
|
$this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual); |
| 438 |
|
$this->assertEquals([ |
| 439 |
|
'proxy_code' => -4, |
| 440 |
|
'new_url' => 'http://def.abc/foobar?456', |
| 441 |
|
], $actual->getData()); |
| 442 |
|
} |
| 443 |
|
|
| 444 |
|
public function testProxyAtMostFiveRedirects() { |
| 445 |
|
$testUrl = 'http://abc.def/foobar?123'; |