Skip to content

Commit

Permalink
See #581. buildWithBaseURLPath returned only last part of url
Browse files Browse the repository at this point in the history
  • Loading branch information
pitbulk committed Sep 29, 2024
1 parent 14af016 commit 772a655
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
6 changes: 4 additions & 2 deletions lib/Saml2/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -709,8 +709,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;
}
Expand Down
14 changes: 10 additions & 4 deletions tests/src/OneLogin/Saml2/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,9 @@ public function testSetBaseURL()
$this->assertEquals($expectedUrl, OneLogin_Saml2_Utils::getSelfURL());

OneLogin_Saml2_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', OneLogin_Saml2_Utils::getSelfProtocol());
$this->assertEquals('anothersp.example.com', OneLogin_Saml2_Utils::getSelfHost());
Expand All @@ -502,11 +502,17 @@ public function testSetBaseURL()
$this->assertEquals($expectedUrl2, OneLogin_Saml2_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, OneLogin_Saml2_Utils::getSelfURLNoQuery());
$this->assertEquals($expectedRoutedUrlNQ2, OneLogin_Saml2_Utils::getSelfRoutedURLNoQuery());
$this->assertEquals($expectedUrl2, OneLogin_Saml2_Utils::getSelfURL());

OneLogin_Saml2_Utils::setBaseURL("http://anothersp.example.com:81/example2");
$this->assertEquals($expectedUrlNQ2, OneLogin_Saml2_Utils::getSelfURLNoQuery());
$this->assertEquals($expectedRoutedUrlNQ2, OneLogin_Saml2_Utils::getSelfRoutedURLNoQuery());
$this->assertEquals($expectedUrl2, OneLogin_Saml2_Utils::getSelfURL());
$this->assertEquals('/example2/', OneLogin_Saml2_Utils::getBaseURLPath());
}

/**
Expand Down

0 comments on commit 772a655

Please sign in to comment.