X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2FHttpUtils%2FServerUrlTest.php;h=dac02b3e77cab58cdf05a57fbecfa3cabae1247b;hb=d9514becc4d8b06e2a31c6975f3bbbaf6f1fed42;hp=5096db653bda40498ddb4fcf1006cf347d15b252;hpb=482d67bd523bf12f36508a0131d09fe299ee02f4;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/HttpUtils/ServerUrlTest.php b/tests/HttpUtils/ServerUrlTest.php index 5096db65..dac02b3e 100644 --- a/tests/HttpUtils/ServerUrlTest.php +++ b/tests/HttpUtils/ServerUrlTest.php @@ -38,6 +38,34 @@ class ServerUrlTest extends PHPUnit_Framework_TestCase ); } + /** + * Detect a Proxy that sets Forwarded-Host + */ + public function testHttpsProxyForwardedHost() + { + $this->assertEquals( + 'https://host.tld:8080', + server_url( + array( + 'HTTP_X_FORWARDED_PROTO' => 'https', + 'HTTP_X_FORWARDED_PORT' => '8080', + 'HTTP_X_FORWARDED_HOST' => 'host.tld' + ) + ) + ); + + $this->assertEquals( + 'https://host.tld:4974', + server_url( + array( + 'HTTP_X_FORWARDED_PROTO' => 'https, https', + 'HTTP_X_FORWARDED_PORT' => '4974, 80', + 'HTTP_X_FORWARDED_HOST' => 'host.tld, example.com' + ) + ) + ); + } + /** * Detect a Proxy with SSL enabled */ @@ -67,6 +95,32 @@ class ServerUrlTest extends PHPUnit_Framework_TestCase ) ) ); + + $this->assertEquals( + 'https://host.tld', + server_url( + array( + 'HTTPS' => 'Off', + 'SERVER_NAME' => 'host.tld', + 'SERVER_PORT' => '80', + 'HTTP_X_FORWARDED_PROTO' => 'https', + 'HTTP_X_FORWARDED_PORT' => '443' + ) + ) + ); + + $this->assertEquals( + 'https://host.tld:4974', + server_url( + array( + 'HTTPS' => 'Off', + 'SERVER_NAME' => 'host.tld', + 'SERVER_PORT' => '80', + 'HTTP_X_FORWARDED_PROTO' => 'https, https', + 'HTTP_X_FORWARDED_PORT' => '4974, 80' + ) + ) + ); } /**