Skip to content

Commit

Permalink
Merge branch 'ubc-cpsc-579-fixes-nested-sub-path' into 4.x-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
pitbulk committed May 30, 2024
2 parents d3b5172 + 216ca81 commit 26e6dae
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/Saml2/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
28 changes: 24 additions & 4 deletions tests/src/OneLogin/Saml2/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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
*
Expand Down

0 comments on commit 26e6dae

Please sign in to comment.