Skip to content

Commit 8fe0a0f

Browse files
committed
Add test for invalid audience exception
Makes debugging issues far easier, also I adjusted the code in the `in_array` here to use a strict comparison. Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
1 parent 4210bc8 commit 8fe0a0f

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

lib/Saml2/Response.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,16 @@ public function isValid($requestId = null)
243243

244244
// Check audience
245245
$validAudiences = $this->getAudiences();
246-
if (!empty($validAudiences) && !in_array($spEntityId, $validAudiences)) {
247-
throw new OneLogin_Saml2_ValidationError(
248-
"$spEntityId is not a valid audience for this Response",
249-
OneLogin_Saml2_ValidationError::WRONG_AUDIENCE
250-
);
251-
}
246+
if (!empty($validAudiences) && !in_array($spEntityId, $validAudiences, true)) {
247+
throw new OneLogin_Saml2_ValidationError(
248+
sprintf(
249+
"Invalid audience for this Response (expected '%s', got '%s')",
250+
$spEntityId,
251+
implode(',', $validAudiences)
252+
),
253+
OneLogin_Saml2_ValidationError::WRONG_AUDIENCE
254+
);
255+
}
252256

253257
// Check the issuers
254258
$issuers = $this->getIssuers();

tests/src/OneLogin/Saml2/ResponseTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ public function testIsInValidAudience()
915915
$response2 = new OneLogin_Saml2_Response($this->_settings, $message);
916916

917917
$this->assertFalse($response2->isValid());
918-
$this->assertContains('is not a valid audience for this Response', $response2->getError());
918+
$this->assertSame('Invalid audience for this Response (expected \'http://stuff.com/endpoints/metadata.php\', got \'http://invalid.audience.com\')', $response2->getError());
919919
}
920920

921921
/**

0 commit comments

Comments
 (0)