Skip to content

Commit

Permalink
Merge pull request SAML-Toolkits#286 from stephanedelprat/patch-1
Browse files Browse the repository at this point in the history
Change Fatal Error to Exception
  • Loading branch information
pitbulk authored Apr 26, 2018
2 parents 9593164 + 035a3bf commit c211712
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 6 deletions.
9 changes: 9 additions & 0 deletions lib/Saml2/LogoutRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ public function getRequest($deflate = null)
* @param string|DOMDocument $request Logout Request Message
*
* @return string ID
*
* @throws OneLogin_Saml2_Error
*/
public static function getID($request)
{
Expand All @@ -158,6 +160,13 @@ public static function getID($request)
} else {
$dom = new DOMDocument();
$dom = OneLogin_Saml2_Utils::loadXML($dom, $request);

if (false === $dom) {
throw new OneLogin_Saml2_Error(
"LogoutRequest could not be processed",
OneLogin_Saml2_Error::SAML_LOGOUTREQUEST_INVALID
);
}
}

$id = $dom->documentElement->getAttribute('ID');
Expand Down
9 changes: 9 additions & 0 deletions lib/Saml2/LogoutResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class OneLogin_Saml2_LogoutResponse
*
* @param OneLogin_Saml2_Settings $settings Settings.
* @param string|null $response An UUEncoded SAML Logout response from the IdP.
*
* @throws OneLogin_Saml2_Error
*/
public function __construct(OneLogin_Saml2_Settings $settings, $response = null)
{
Expand All @@ -63,6 +65,13 @@ public function __construct(OneLogin_Saml2_Settings $settings, $response = null)
$this->document = new DOMDocument();
$this->document = OneLogin_Saml2_Utils::loadXML($this->document, $this->_logoutResponse);

if (false === $this->document) {
throw new OneLogin_Saml2_Error(
"LogoutResponse could not be processed",
OneLogin_Saml2_Error::SAML_LOGOUTRESPONSE_INVALID
);
}

if ($this->document->documentElement->hasAttribute('ID')) {
$this->id = $this->document->documentElement->getAttribute('ID');
}
Expand Down
25 changes: 22 additions & 3 deletions tests/src/OneLogin/Saml2/LogoutRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public function testCreateDeflatedSAMLLogoutRequestURLParameter()
/**
* Tests the OneLogin_Saml2_LogoutRequest Constructor.
* Case: Able to generate encryptedID with MultiCert
*
*
* @covers OneLogin_Saml2_LogoutRequest
*/
public function testConstructorEncryptIdUsingX509certMulti()
Expand Down Expand Up @@ -828,7 +828,7 @@ public function testGetXML()
$logoutRequest = new OneLogin_Saml2_LogoutRequest($settings);
$xml = $logoutRequest->getXML();
$this->assertRegExp('#^<samlp:LogoutRequest#', $xml);

$logoutRequestProcessed = new OneLogin_Saml2_LogoutRequest($settings, base64_encode($xml));
$xml2 = $logoutRequestProcessed->getXML();
$this->assertRegExp('#^<samlp:LogoutRequest#', $xml2);
Expand All @@ -849,9 +849,28 @@ public function testGetID()
$xml = $logoutRequest->getXML();
$id1 = OneLogin_Saml2_LogoutRequest::getID($xml);
$this->assertNotNull($id1);

$logoutRequestProcessed = new OneLogin_Saml2_LogoutRequest($settings, base64_encode($xml));
$id2 = $logoutRequestProcessed->id;
$this->assertEquals($id1, $id2);
}

/**
* Tests that the LogoutRequest throws an exception
*
* @covers OneLogin_Saml2_LogoutRequest::getID()
*
* @expectedException OneLogin_Saml2_Error
* @expectedExceptionMessage LogoutRequest could not be processed
*/
public function testGetIDException()
{
$settingsDir = TEST_ROOT .'/settings/';
include $settingsDir.'settings1.php';

$settings = new OneLogin_Saml2_Settings($settingsInfo);
$logoutRequest = new OneLogin_Saml2_LogoutRequest($settings);
$xml = $logoutRequest->getXML();
$id1 = OneLogin_Saml2_LogoutRequest::getID($xml.'<garbage>');
}
}
23 changes: 20 additions & 3 deletions tests/src/OneLogin/Saml2/LogoutResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ public function testWeCanChooseToDeflateAResponseBody()
//Test that we can choose not to compress the request payload.
$settingsDir = TEST_ROOT .'/settings/';
include $settingsDir.'settings1.php';

//Compression is currently turned on in settings.
$settings = new OneLogin_Saml2_Settings($settingsInfo);
$logoutResponse = new OneLogin_Saml2_LogoutResponse($settings, $message);
Expand All @@ -448,7 +448,7 @@ public function testWeCanChooseToDeflateAResponseBody()
//Test that we can choose not to compress the request payload.
$settingsDir = TEST_ROOT .'/settings/';
include $settingsDir.'settings2.php';

//Compression is currently turned on in settings.
$settings = new OneLogin_Saml2_Settings($settingsInfo);
$logoutResponse = new OneLogin_Saml2_LogoutResponse($settings, $message);
Expand Down Expand Up @@ -497,9 +497,26 @@ public function testGetID()
$xml = $logoutResponse->getXML();
$id1 = $logoutResponse->getID();
$this->assertNotNull($id1);

$processedLogoutResponse = new OneLogin_Saml2_LogoutResponse($settings, base64_encode($xml));
$id2 = $processedLogoutResponse->getID();
$this->assertEquals($id1, $id2);
}

/**
* Tests that the LogoutRequest throws an exception
*
* @covers OneLogin_Saml2_LogoutRequest::getID()
*
* @expectedException OneLogin_Saml2_Error
* @expectedExceptionMessage LogoutResponse could not be processed
*/
public function testGetIDException()
{
$settingsDir = TEST_ROOT .'/settings/';
include $settingsDir.'settings1.php';

$settings = new OneLogin_Saml2_Settings($settingsInfo);
$logoutResponse = new OneLogin_Saml2_LogoutResponse($settings, '<garbage>');
}
}

0 comments on commit c211712

Please sign in to comment.