Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pitbulk committed Sep 29, 2024
1 parent 772a655 commit a86c597
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/src/OneLogin/Saml2/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@ public function testSetBaseURLPath()
{
$this->assertNull(OneLogin_Saml2_Utils::getBaseURLPath());

OneLogin_Saml2_Utils::setBaseURLPath('/');
$this->assertEquals('/', OneLogin_Saml2_Utils::getBaseURLPath());

OneLogin_Saml2_Utils::setBaseURLPath('sp');
$this->assertEquals('/sp/', OneLogin_Saml2_Utils::getBaseURLPath());

Expand All @@ -461,6 +464,25 @@ public function testSetBaseURLPath()
$this->assertEquals('/sp/', OneLogin_Saml2_Utils::getBaseURLPath());
}

/**
* @covers OneLogin_Saml2_Utils::setBaseURLPath
*/
public function testSetBaseURLPath2()
{
$_SERVER['HTTP_HOST'] = 'sp.example.com';
$_SERVER['HTTPS'] = 'https';
$_SERVER['REQUEST_URI'] = null;
$_SERVER['QUERY_STRING'] = null;
$_SERVER['SCRIPT_NAME'] = '/';
unset($_SERVER['PATH_INFO']);

OneLogin_Saml2_Utils::setBaseURLPath('/');
$this->assertEquals("https://sp.example.com/", OneLogin_Saml2_Utils::getSelfURLNoQuery());
$this->assertEquals("https://sp.example.com/", OneLogin_Saml2_Utils::getSelfRoutedURLNoQuery());
$this->assertEquals("https://sp.example.com/", OneLogin_Saml2_Utils::getSelfURL());
$this->assertEquals('/', OneLogin_Saml2_Utils::getBaseURLPath());
}

/**
* @covers OneLogin_Saml2_Utils::setBaseURL
*/
Expand Down Expand Up @@ -513,6 +535,16 @@ public function testSetBaseURL()
$this->assertEquals($expectedRoutedUrlNQ2, OneLogin_Saml2_Utils::getSelfRoutedURLNoQuery());
$this->assertEquals($expectedUrl2, OneLogin_Saml2_Utils::getSelfURL());
$this->assertEquals('/example2/', OneLogin_Saml2_Utils::getBaseURLPath());

$_SERVER['PATH_INFO'] = null;
$_SERVER['REQUEST_URI'] = null;
$_SERVER['QUERY_STRING'] = null;
$_SERVER['SCRIPT_NAME'] = '/';
OneLogin_Saml2_Utils::setBaseURL("https://sp.example.com/");
$this->assertEquals("https://sp.example.com/", OneLogin_Saml2_Utils::getSelfURLNoQuery());
$this->assertEquals("https://sp.example.com/", OneLogin_Saml2_Utils::getSelfRoutedURLNoQuery());
$this->assertEquals("https://sp.example.com/", OneLogin_Saml2_Utils::getSelfURL());
$this->assertEquals('/', OneLogin_Saml2_Utils::getBaseURLPath());
}

/**
Expand Down Expand Up @@ -572,6 +604,13 @@ public function testGetSelfURL()

$_SERVER['REQUEST_URI'] = 'https://example.com/testing';
$this->assertEquals($url.'/testing', OneLogin_Saml2_Utils::getSelfURL());

$_SERVER['REQUEST_URI'] = 'https://example.com/test/';
$this->assertEquals($url.'/test/', OneLogin_Saml2_Utils::getSelfURL());

$_SERVER['REQUEST_URI'] = 'https://example.com/';
$this->assertEquals($url.'/', OneLogin_Saml2_Utils::getSelfURL());

}

/**
Expand Down

0 comments on commit a86c597

Please sign in to comment.