Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Jan 31, 2025
1 parent 88027f9 commit f903898
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 41 deletions.
6 changes: 0 additions & 6 deletions src/SAML11/XML/samlp/AbstractMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace SimpleSAML\SAML11\XML\samlp;

use DOMElement;
use SimpleSAML\SAML11\Constants as C;
use SimpleSAML\SAML11\Utils;
use SimpleSAML\SAML11\Type\DateTimeValue;
use SimpleSAML\SAML11\XML\{SignableElementTrait, SignedElementTrait};
Expand All @@ -29,7 +28,6 @@ abstract class AbstractMessage extends AbstractSamlpElement implements SignableE
SignedElementTrait::getBlacklistedAlgorithms insteadof SignableElementTrait;
}


/** @var bool */
protected bool $messageContainedSignatureUponConstruction = false;

Expand Down Expand Up @@ -147,10 +145,6 @@ protected function toUnsignedXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);

/* Ugly hack to add another namespace declaration to the root element. */
$e->setAttributeNS(C::NS_SAML, 'saml:tmp', 'tmp');
$e->removeAttributeNS(C::NS_SAML, 'tmp');

$e->setAttribute('MajorVersion', strval($this->getMajorVersion()));
$e->setAttribute('MinorVersion', strval($this->getMinorVersion()));
$e->setAttribute('IssueInstant', strval($this->getIssueInstant()));
Expand Down
29 changes: 0 additions & 29 deletions src/SAML11/XML/samlp/AbstractSubjectQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use SimpleSAML\SAML11\Utils;
use SimpleSAML\SAML11\XML\{ExtensionPointInterface, ExtensionPointTrait};
use SimpleSAML\SAML11\XML\saml\Subject;
use SimpleSAML\XML\Attribute as XMLAttribute;
use SimpleSAML\XML\Chunk;
use SimpleSAML\XML\Exception\{
InvalidDOMElementException,
Expand Down Expand Up @@ -92,32 +91,4 @@ public static function fromXML(DOMElement $xml): static

return $handler::fromXML($xml);
}


/**
* Convert this SubjectQuery to XML.
*
* @param \DOMElement $parent The element we are converting to XML.
* @return \DOMElement The XML element after adding the data corresponding to this SubjectQuery.
*/
public function toXML(?DOMElement $parent = null): DOMElement
{
// $e = parent::toXML($parent);
$e = $this->instantiateParentElement($parent);

if (!$e->lookupPrefix($this->getXsiType()->getNamespaceURI()->getValue())) {
$e->setAttributeNS(
'http://www.w3.org/2000/xmlns/',
'xmlns:' . $this->getXsiType()->getNamespacePrefix()->getValue(),
$this->getXsiType()->getNamespaceURI()->getValue(),
);
}

$type = new XMLAttribute(C::NS_XSI, 'xsi', 'type', $this->getXsiType());
$type->toXML($e);

// $this->getSubject()->toXML($e);

return $e;
}
}
1 change: 0 additions & 1 deletion src/SAML11/XML/samlp/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public static function fromXML(DOMElement $xml): static
$minorVersion = self::getAttribute($xml, 'MinorVersion', NonNegativeIntegerValue::class);
Assert::same($minorVersion->getValue(), '1', VersionMismatchException::class);


$status = Status::getChildrenOfClass($xml);
Assert::minCount($status, 1, MissingElementException::class);
Assert::maxCount($status, 1, TooManyElementsException::class);
Expand Down
4 changes: 2 additions & 2 deletions tests/resources/xml/saml_Conditions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<saml:AudienceRestrictionCondition>
<saml:Audience>urn:x-simplesamlphp:audience</saml:Audience>
</saml:AudienceRestrictionCondition>
<saml:DoNotCacheCondition xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion" />
<saml:Condition xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion" xmlns:ssp="urn:x-simplesamlphp:namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ssp:CustomConditionType">
<saml:DoNotCacheCondition />
<saml:Condition xmlns:ssp="urn:x-simplesamlphp:namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ssp:CustomConditionType">
<saml:Audience>urn:some:audience</saml:Audience>
</saml:Condition>
</saml:Conditions>
2 changes: 1 addition & 1 deletion tests/resources/xml/saml_Evidence.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<saml:Evidence xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion">
<saml:AssertionIDReference xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion">_Test</saml:AssertionIDReference>
<saml:AssertionIDReference>_Test</saml:AssertionIDReference>
<saml:Assertion MajorVersion="1" MinorVersion="1" AssertionID="EvidenceAssertionID" Issuer="urn:x-simplesamlphp:phpunit" IssueInstant="2023-01-24T09:42:26Z">
<saml:Conditions NotBefore="2023-01-24T09:42:26Z" NotOnOrAfter="2023-01-24T09:47:26Z">
<saml:AudienceRestrictionCondition>
Expand Down
2 changes: 1 addition & 1 deletion tests/resources/xml/samlp_SubjectQuery.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ds:X509Certificate>MIICxDCCAi2gAwIBAgIUZ9QDx+SBFHednUWDFGm9tyVKrgQwDQYJKoZIhvcNAQELBQAwczElMCMGA1UEAwwcc2VsZnNpZ25lZC5zaW1wbGVzYW1scGhwLm9yZzEZMBcGA1UECgwQU2ltcGxlU0FNTHBocCBIUTERMA8GA1UEBwwISG9ub2x1bHUxDzANBgNVBAgMBkhhd2FpaTELMAkGA1UEBhMCVVMwIBcNMjIxMjAzMTAzNTQwWhgPMjEyMjExMDkxMDM1NDBaMHMxJTAjBgNVBAMMHHNlbGZzaWduZWQuc2ltcGxlc2FtbHBocC5vcmcxGTAXBgNVBAoMEFNpbXBsZVNBTUxwaHAgSFExETAPBgNVBAcMCEhvbm9sdWx1MQ8wDQYDVQQIDAZIYXdhaWkxCzAJBgNVBAYTAlVTMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDessdFRVDTMQQW3Na81B1CjJV1tmY3nopoIhZrkbDxLa+pv7jGDRcYreyu1DoQxEs06V2nHLoyOPhqJXSFivqtUwVYhR6NYgbNI6RRSsIJCweH0YOdlHna7gULPcLX0Bfbi4odStaFwG9yzDySwSEPtsKxm5pENPjNVGh+jJ+H/QIDAQABo1MwUTAdBgNVHQ4EFgQUvV75t8EoQo2fVa0E9otdtIGK5X0wHwYDVR0jBBgwFoAUvV75t8EoQo2fVa0E9otdtIGK5X0wDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOBgQANQUeiwPJXkWMXuaDHToEBKcezYGqGEYnGUi9LMjeb+Kln7X8nn5iknlz4k77rWCbSwLPC/WDr0ySYQA+HagaeUaFpoiYFJKS6uFlK1HYWnM3W4PUiGHg1/xeZlMO44wTwybXVo0y9KMhchfB5XNbDdoJcqWYvi6xtmZZNRbxUyw==</ds:X509Certificate>
<ds:X509SubjectName>/CN=selfsigned.simplesamlphp.org/O=SimpleSAMLphp HQ/L=Honolulu/ST=Hawaii/C=US</ds:X509SubjectName>
</ds:X509Data>
<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">some</ssp:Chunk>
<ssp:Chunk>some</ssp:Chunk>
</ds:KeyInfo>
</saml:SubjectConfirmation>
</saml:Subject>
Expand Down
20 changes: 19 additions & 1 deletion tests/src/SAML11/CustomSubjectQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use SimpleSAML\SAML11\Constants as C;
use SimpleSAML\SAML11\XML\saml\Subject;
use SimpleSAML\SAML11\XML\samlp\{AbstractSubjectQuery, StatusMessage};
use SimpleSAML\XML\Attribute as XMLAttribute;
use SimpleSAML\XML\Exception\{InvalidDOMElementException, MissingElementException, TooManyElementsException};
use SimpleSAML\XML\Type\QNameValue;

Expand Down Expand Up @@ -103,7 +104,24 @@ public static function fromXML(DOMElement $xml): static
*/
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = parent::toXML($parent);
$e = $this->instantiateParentElement($parent);

if (!$e->lookupPrefix($this->getXsiType()->getNamespaceURI()->getValue())) {
$namespace = new XMLAttribute(
'http://www.w3.org/2000/xmlns/',
'xmlns',
$this->getXsiType()->getNamespacePrefix()->getValue(),
$this->getXsiType()->getNamespaceURI(),
);
$namespace->toXML($e);
}

if (!$e->lookupPrefix('xsi')) {
$type = new XMLAttribute(C::NS_XSI, 'xsi', 'type', $this->getXsiType());
$type->toXML($e);
}

$this->getSubject()->toXML($e);

foreach ($this->getStatusMessage() as $statusMessage) {
$statusMessage->toXML($e);
Expand Down

0 comments on commit f903898

Please sign in to comment.