diff --git a/src/Saml2/Utils.php b/src/Saml2/Utils.php index 3a6f77b3..eea057ff 100644 --- a/src/Saml2/Utils.php +++ b/src/Saml2/Utils.php @@ -722,8 +722,10 @@ protected static function buildWithBaseURLPath($info) if (!empty($baseURLPath)) { $result = $baseURLPath; if (!empty($info)) { - $path = explode('/', $info); - $extractedInfo = array_pop($path); + // Remove base path from the path info. + $extractedInfo = str_replace($baseURLPath, '', $info); + // Remove starting and ending slash. + $extractedInfo = trim($extractedInfo, '/'); if (!empty($extractedInfo)) { $result .= $extractedInfo; } diff --git a/tests/src/OneLogin/Saml2/UtilsTest.php b/tests/src/OneLogin/Saml2/UtilsTest.php index 7fabe35d..7cc4050b 100644 --- a/tests/src/OneLogin/Saml2/UtilsTest.php +++ b/tests/src/OneLogin/Saml2/UtilsTest.php @@ -503,9 +503,9 @@ public function testSetBaseURL() $this->assertEquals($expectedUrl, Utils::getSelfURL()); Utils::setBaseURL("http://anothersp.example.com:81/example2/"); - $expectedUrlNQ2 = 'http://anothersp.example.com:81/example2/route.php'; - $expectedRoutedUrlNQ2 = 'http://anothersp.example.com:81/example2/route.php'; - $expectedUrl2 = 'http://anothersp.example.com:81/example2/route.php?x=test'; + $expectedUrlNQ2 = 'http://anothersp.example.com:81/example2/example1/route.php'; + $expectedRoutedUrlNQ2 = 'http://anothersp.example.com:81/example2/example1/route.php'; + $expectedUrl2 = 'http://anothersp.example.com:81/example2/example1/route.php?x=test'; $this->assertEquals('http', Utils::getSelfProtocol()); $this->assertEquals('anothersp.example.com', Utils::getSelfHost()); @@ -517,13 +517,33 @@ public function testSetBaseURL() $this->assertEquals($expectedUrl2, Utils::getSelfURL()); $_SERVER['PATH_INFO'] = '/test'; - $expectedUrlNQ2 = 'http://anothersp.example.com:81/example2/route.php/test'; + $expectedUrlNQ2 = 'http://anothersp.example.com:81/example2/example1/route.php/test'; $this->assertEquals($expectedUrlNQ2, Utils::getSelfURLNoQuery()); $this->assertEquals($expectedRoutedUrlNQ2, Utils::getSelfRoutedURLNoQuery()); $this->assertEquals($expectedUrl2, Utils::getSelfURL()); } + /** + * Tests the buildWithBaseURLPath method of the Utils + * + * @covers OneLogin\Saml2\Utils::buildWithBaseURLPath + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function testBuildWithBaseURLPath() + { + $class = new \ReflectionClass("Utils"); + $method = $class->getMethod("buildWithBaseURLPath"); + + Utils::setBaseURL("http://sp.example.com:81/"); + $result = Utils::buildWithBaseURLPath(); + + $this->assertEquals("", $result); + } + + /** * Tests the getSelfURLhost method of the Utils *