Skip to content

Commit

Permalink
Add assertion to ensure binding matches idpdisco-specs
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Oct 18, 2023
1 parent 8e5fb9b commit ace246e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/SAML2/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ class Constants extends \SimpleSAML\XMLSecurity\Constants
*/
public const BINDING_HTTP_REDIRECT_DEFLATE = 'urn:oasis:names:tc:SAML:2.0:bindings:URL-Encoding:DEFLATE';

/*
* The URN for the IdP Discovery Protocol binding
*/
public const BINDING_IDPDISC = 'urn:oasis:names:tc:SAML:profiles:SSO:idp-discovery-protocol';

/**
* The URN for the PAOS binding.
*/
Expand Down
4 changes: 3 additions & 1 deletion src/SAML2/XML/idpdisc/DiscoveryResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use SimpleSAML\Assert\Assert;
use SimpleSAML\SAML2\Constants as C;
use SimpleSAML\SAML2\Exception\ProtocolViolationException;
use SimpleSAML\SAML2\XML\md\AbstractIndexedEndpointType;

/**
Expand Down Expand Up @@ -48,10 +49,11 @@ public function __construct(
array $attributes = [],
array $children = [],
) {
Assert::same($binding, C::BINDING_IDPDISC, ProtocolViolationException::class);
Assert::null(
$unused,
'The \'ResponseLocation\' attribute must be omitted for idpdisc:DiscoveryResponse.',
);
parent::__construct($index, $binding, $location, $isDefault, null, $attributes, $children);
parent::__construct($index, C::BINDING_IDPDISC, $location, $isDefault, null, $attributes, $children);
}
}
8 changes: 7 additions & 1 deletion tests/SAML2/XML/idpdisc/DiscoveryResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ public function testMarshallingWithResponseLocation(): void
$this->expectExceptionMessage(
'The \'ResponseLocation\' attribute must be omitted for idpdisc:DiscoveryResponse.',
);
new DiscoveryResponse(42, C::BINDING_HTTP_ARTIFACT, C::LOCATION_A, false, 'https://response.location/');
new DiscoveryResponse(
42,
C::BINDING_IDPDISC,
C::LOCATION_A,
false,
'https://response.location/',
);
}


Expand Down
3 changes: 2 additions & 1 deletion tests/SAML2/XML/md/IndexedEndpointTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public static function setUpBeforeClass(): void
*/
public function testMarshallingWithoutIsDefault(string $class): void
{
$idxep = new $class(42, C::BINDING_HTTP_POST, C::LOCATION_A);
$binding = ($class === DiscoveryResponse::class) ? C::BINDING_IDPDISCO : C::BINDING_HTTP_POST;

Check failure on line 54 in tests/SAML2/XML/md/IndexedEndpointTypeTest.php

View workflow job for this annotation

GitHub Actions / Quality control

UndefinedConstant

tests/SAML2/XML/md/IndexedEndpointTypeTest.php:54:60: UndefinedConstant: Constant SimpleSAML\Test\SAML2\Constants::BINDING_IDPDISCO is not defined (see https://psalm.dev/020)
$idxep = new $class(42, $binding, C::LOCATION_A);
$this->assertNull($idxep->getIsDefault());
}

Expand Down
2 changes: 1 addition & 1 deletion tests/resources/xml/idpdisc_DiscoveryResponse.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<idpdisc:DiscoveryResponse xmlns:idpdisc="urn:oasis:names:tc:SAML:profiles:SSO:idp-discovery-protocol" xmlns:ssp="urn:x-simplesamlphp:namespace" Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="https://simplesamlphp.org/some/endpoint" index="43" isDefault="false" ssp:attr1="testval1">
<idpdisc:DiscoveryResponse xmlns:idpdisc="urn:oasis:names:tc:SAML:profiles:SSO:idp-discovery-protocol" xmlns:ssp="urn:x-simplesamlphp:namespace" Binding="urn:oasis:names:tc:SAML:profiles:SSO:idp-discovery-protocol" Location="https://simplesamlphp.org/some/endpoint" index="43" isDefault="false" ssp:attr1="testval1">
<some:Ext xmlns:some="urn:mace:some:metadata:1.0">SomeExtension</some:Ext>
</idpdisc:DiscoveryResponse>

0 comments on commit ace246e

Please sign in to comment.