From: Antoine Musso Date: Wed, 21 Dec 2011 15:31:30 +0000 (+0000) Subject: tests for r94881 which interprets relative Location: headers X-Git-Tag: 1.31.0-rc.0~25833 X-Git-Url: http://git.cyclocoop.org/fichier?a=commitdiff_plain;h=7505ddbb6daae8e0360df7107446bb39c4052f5f;p=lhc%2Fweb%2Fwiklou.git tests for r94881 which interprets relative Location: headers --- diff --git a/tests/phpunit/includes/HttpTest.php b/tests/phpunit/includes/HttpTest.php index 7ddedb9b24..07ccfa45d0 100644 --- a/tests/phpunit/includes/HttpTest.php +++ b/tests/phpunit/includes/HttpTest.php @@ -124,4 +124,49 @@ class HttpTest extends MediaWikiTestCase { ); } + function testRelativeRedirections() { + $h = new MWHttpRequestTester( 'http://oldsite/file.ext' ); + # Forge a Location header + $h->setRespHeaders( 'location', array( + 'http://newsite/file.ext', + '/newfile.ext', + ) + ); + # Verify we correctly fix the Location + $this->assertEquals( + 'http://newsite/newfile.ext', + $h->getFinalUrl(), + "Relative file path Location: interpreted as full URL" + ); + + $h->setRespHeaders( 'location', array( + 'https://oldsite/file.ext' + ) + ); + $this->assertEquals( + 'https://oldsite/file.ext', + $h->getFinalUrl(), + "Location to the HTTPS version of the site" + ); + + $h->setRespHeaders( 'location', array( + '/anotherfile.ext', + 'http://anotherfile/hoster.ext', + 'https://anotherfile/hoster.ext' + ) + ); + $this->assertEquals( + 'https://anotherfile/hoster.ext', + $h->getFinalUrl( "Relative file path Location: should keep the latest host and scheme!") + ); + } +} + +/** + * Class to let us overwrite MWHttpREquest respHeaders variable + */ +class MWHttpRequestTester extends MWHttpRequest { + function setRespHeaders( $name, $value ) { + $this->respHeaders[$name] = $value ; + } }