Skip to content

Commit df6a0a2

Browse files
committed
Fix #286. Change Fatal Error to Exception on getID methods of LogoutRequest and LogoutResponse
1 parent 3212c89 commit df6a0a2

4 files changed

Lines changed: 51 additions & 0 deletions

File tree

src/Saml2/LogoutRequest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ public function getRequest($deflate = null)
172172
* @param string|DOMDocument $request Logout Request Message
173173
*
174174
* @return string ID
175+
*
176+
* @throws OneLogin_Saml2_Error
175177
*/
176178
public static function getID($request)
177179
{
@@ -182,6 +184,14 @@ public static function getID($request)
182184
$dom = Utils::loadXML($dom, $request);
183185
}
184186

187+
188+
if (false === $dom) {
189+
throw new Error(
190+
"LogoutRequest could not be processed",
191+
Error::SAML_LOGOUTREQUEST_INVALID
192+
);
193+
}
194+
185195
$id = $dom->documentElement->getAttribute('ID');
186196
return $id;
187197
}

src/Saml2/LogoutResponse.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ public function __construct(\OneLogin\Saml2\Settings $settings, $response = null
8686
$this->document = new DOMDocument();
8787
$this->document = Utils::loadXML($this->document, $this->_logoutResponse);
8888

89+
if (false === $this->document) {
90+
throw new Error(
91+
"LogoutResponse could not be processed",
92+
Error::SAML_LOGOUTRESPONSE_INVALID
93+
);
94+
}
95+
8996
if ($this->document->documentElement->hasAttribute('ID')) {
9097
$this->id = $this->document->documentElement->getAttribute('ID');
9198
}

tests/src/OneLogin/Saml2/LogoutRequestTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,4 +875,22 @@ public function testGetID()
875875
$id2 = $logoutRequestProcessed->id;
876876
$this->assertEquals($id1, $id2);
877877
}
878+
879+
/**
880+
* Tests that the LogoutRequest throws an exception
881+
*
882+
* @covers OneLogin\Saml2\LogoutRequest::getID()
883+
*
884+
* @expectedException OneLogin\Saml2\Error
885+
* @expectedExceptionMessage LogoutRequest could not be processed
886+
*/
887+
public function testGetIDException()
888+
{
889+
$settingsDir = TEST_ROOT .'/settings/';
890+
include $settingsDir.'settings1.php';
891+
$settings = new Settings($settingsInfo);
892+
$logoutRequest = new LogoutRequest($settings);
893+
$xml = $logoutRequest->getXML();
894+
$id1 = LogoutRequest::getID($xml.'<garbage>');
895+
}
878896
}

tests/src/OneLogin/Saml2/LogoutResponseTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,4 +543,20 @@ public function testGetID()
543543
$id2 = $processedLogoutResponse->getID();
544544
$this->assertEquals($id1, $id2);
545545
}
546+
547+
/**
548+
* Tests that the LogoutRequest throws an exception
549+
*
550+
* @covers OneLogin\Saml2\LogoutRequest::getID()
551+
*
552+
* @expectedException OneLogin\Saml2\Error
553+
* @expectedExceptionMessage LogoutResponse could not be processed
554+
*/
555+
public function testGetIDException()
556+
{
557+
$settingsDir = TEST_ROOT .'/settings/';
558+
include $settingsDir.'settings1.php';
559+
$settings = new Settings($settingsInfo);
560+
$logoutResponse = new LogoutResponse($settings, '<garbage>');
561+
}
546562
}

0 commit comments

Comments
 (0)