getStatus() public static method

Gets Status from a Response.
public static getStatus ( DOMDocument $dom ) : array
$dom DOMDocument The Response as XML
return array $status The Status, an array with the code and a message.
Example #1
0
 /**
  * Gets the status of a message
  *
  * @covers OneLogin_Saml2_Utils::getStatus
  */
 public function testGetStatus()
 {
     $xml = base64_decode(file_get_contents(TEST_ROOT . '/data/responses/response1.xml.base64'));
     $dom = new DOMDocument();
     $dom->loadXML($xml);
     $status = OneLogin_Saml2_Utils::getStatus($dom);
     $this->assertEquals(OneLogin_Saml2_Constants::STATUS_SUCCESS, $status['code']);
     $xml2 = base64_decode(file_get_contents(TEST_ROOT . '/data/responses/invalids/status_code_responder.xml.base64'));
     $dom2 = new DOMDocument();
     $dom2->loadXML($xml2);
     $status2 = OneLogin_Saml2_Utils::getStatus($dom2);
     $this->assertEquals(OneLogin_Saml2_Constants::STATUS_RESPONDER, $status2['code']);
     $this->assertEmpty($status2['msg']);
     $xml3 = base64_decode(file_get_contents(TEST_ROOT . '/data/responses/invalids/status_code_responer_and_msg.xml.base64'));
     $dom3 = new DOMDocument();
     $dom3->loadXML($xml3);
     $status3 = OneLogin_Saml2_Utils::getStatus($dom3);
     $this->assertEquals(OneLogin_Saml2_Constants::STATUS_RESPONDER, $status3['code']);
     $this->assertEquals('something_is_wrong', $status3['msg']);
     $xmlInv = base64_decode(file_get_contents(TEST_ROOT . '/data/responses/invalids/no_status.xml.base64'));
     $domInv = new DOMDocument();
     $domInv->loadXML($xmlInv);
     try {
         $statusInv = OneLogin_Saml2_Utils::getStatus($domInv);
         $this->assertTrue(false);
     } catch (Exception $e) {
         $this->assertEquals('Missing Status on response', $e->getMessage());
     }
     $xmlInv2 = base64_decode(file_get_contents(TEST_ROOT . '/data/responses/invalids/no_status_code.xml.base64'));
     $domInv2 = new DOMDocument();
     $domInv2->loadXML($xmlInv2);
     try {
         $statusInv2 = OneLogin_Saml2_Utils::getStatus($domInv2);
         $this->assertTrue(false);
     } catch (Exception $e) {
         $this->assertEquals('Missing Status Code on response', $e->getMessage());
     }
 }
Example #2
0
 /**
  * Checks if the Status is success
  * 
  * @throws $statusExceptionMsg If status is not success
  */
 public function checkStatus()
 {
     $status = OneLogin_Saml2_Utils::getStatus($this->document);
     if (isset($status['code']) && $status['code'] !== OneLogin_Saml2_Constants::STATUS_SUCCESS) {
         $explodedCode = explode(':', $status['code']);
         $printableCode = array_pop($explodedCode);
         $statusExceptionMsg = 'The status code of the Response was not Success, was ' . $printableCode;
         if (!empty($status['msg'])) {
             $statusExceptionMsg .= ' -> ' . $status['msg'];
         }
         throw new Exception($statusExceptionMsg);
     }
 }