@@ 251-291 (lines=41) @@ | ||
248 | ], $actual->getData()); |
|
249 | } |
|
250 | ||
251 | public function testProxyRedirect() { |
|
252 | $testUrl = 'http://abc.def/foobar?123'; |
|
253 | ||
254 | $this->client->expects($this->once()) |
|
255 | ->method('newClient') |
|
256 | ->will($this->returnValue($this->newClient)); |
|
257 | $this->newClient->expects($this->at(0)) |
|
258 | ->method('get') |
|
259 | ->with($testUrl, [ |
|
260 | 'stream' => true, |
|
261 | 'allow_redirects' => false, |
|
262 | ]) |
|
263 | ->will($this->returnValue($this->response0)); |
|
264 | $this->response0->expects($this->at(0)) |
|
265 | ->method('getStatusCode') |
|
266 | ->with() |
|
267 | ->will($this->returnValue(301)); |
|
268 | $this->response0->expects($this->at(1)) |
|
269 | ->method('getHeader') |
|
270 | ->with('Location') |
|
271 | ->will($this->returnValue('http://def.abc/foobar?456')); |
|
272 | $this->newClient->expects($this->at(1)) |
|
273 | ->method('get') |
|
274 | ->with('http://def.abc/foobar?456', [ |
|
275 | 'stream' => true, |
|
276 | 'allow_redirects' => false, |
|
277 | ]) |
|
278 | ->will($this->returnValue($this->response0)); |
|
279 | $this->response0->expects($this->at(2)) |
|
280 | ->method('getStatusCode') |
|
281 | ->with() |
|
282 | ->will($this->returnValue(200)); |
|
283 | ||
284 | $actual = $this->controller->proxy($testUrl); |
|
285 | ||
286 | $this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual); |
|
287 | $this->assertEquals([ |
|
288 | 'proxy_code' => -4, |
|
289 | 'new_url' => 'http://def.abc/foobar?456', |
|
290 | ], $actual->getData()); |
|
291 | } |
|
292 | ||
293 | public function testProxyRedirectNonPermanent() { |
|
294 | $testUrl = 'http://abc.def/foobar?123'; |
|
@@ 387-427 (lines=41) @@ | ||
384 | ], $actual->getData()); |
|
385 | } |
|
386 | ||
387 | public function testProxyMultipleRedirectsNonPermanent() { |
|
388 | $testUrl = 'http://abc.def/foobar?123'; |
|
389 | ||
390 | $this->client->expects($this->once()) |
|
391 | ->method('newClient') |
|
392 | ->will($this->returnValue($this->newClient)); |
|
393 | $this->newClient->expects($this->at(0)) |
|
394 | ->method('get') |
|
395 | ->with($testUrl, [ |
|
396 | 'stream' => true, |
|
397 | 'allow_redirects' => false, |
|
398 | ]) |
|
399 | ->will($this->returnValue($this->response0)); |
|
400 | $this->newClient->expects($this->at(1)) |
|
401 | ->method('get') |
|
402 | ->with('http://def.abc/foobar?456' , [ |
|
403 | 'stream' => true, |
|
404 | 'allow_redirects' => false, |
|
405 | ]) |
|
406 | ->will($this->returnValue($this->response1)); |
|
407 | $this->response0->expects($this->at(0)) |
|
408 | ->method('getStatusCode') |
|
409 | ->with() |
|
410 | ->will($this->returnValue(301)); |
|
411 | $this->response0->expects($this->at(1)) |
|
412 | ->method('getHeader') |
|
413 | ->with('Location') |
|
414 | ->will($this->returnValue('http://def.abc/foobar?456')); |
|
415 | $this->response1->expects($this->at(0)) |
|
416 | ->method('getStatusCode') |
|
417 | ->with() |
|
418 | ->will($this->returnValue(307)); |
|
419 | ||
420 | $actual = $this->controller->proxy($testUrl); |
|
421 | ||
422 | $this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $actual); |
|
423 | $this->assertEquals([ |
|
424 | 'proxy_code' => -4, |
|
425 | 'new_url' => 'http://def.abc/foobar?456', |
|
426 | ], $actual->getData()); |
|
427 | } |
|
428 | ||
429 | public function testProxyAtMostFiveRedirects() { |
|
430 | $testUrl = 'http://abc.def/foobar?123'; |