Skip to content

Commit

Permalink
Raise coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Jun 12, 2023
1 parent 3efbb76 commit e64f5f4
Show file tree
Hide file tree
Showing 17 changed files with 34 additions and 31 deletions.
10 changes: 4 additions & 6 deletions src/SAML2/XML/init/RequestInitiator.php
Expand Up @@ -76,13 +76,11 @@ public static function fromXML(DOMElement $xml): static

$children = [];
foreach ($xml->childNodes as $child) {
if ($child->namespaceURI === C::NS_MD) {
if (!($child instanceof DOMElement)) {
continue;
} elseif (!($child instanceof DOMElement)) {
continue;
}

$children[] = new Chunk($child);
} elseif ($child->namespaceURI !== C::NS_MD) {
$children[] = new Chunk($child);
} // else continue
}

return new static(
Expand Down
10 changes: 4 additions & 6 deletions src/SAML2/XML/md/AbstractEndpointType.php
Expand Up @@ -137,13 +137,11 @@ public static function fromXML(DOMElement $xml): static

$children = [];
foreach ($xml->childNodes as $child) {
if ($child->namespaceURI === C::NS_MD) {
if (!($child instanceof DOMElement)) {
continue;
} elseif (!($child instanceof DOMElement)) {
continue;
}

$children[] = new Chunk($child);
} elseif ($child->namespaceURI !== C::NS_MD) {
$children[] = new Chunk($child);
} // else continue
}

return new static(
Expand Down
10 changes: 4 additions & 6 deletions src/SAML2/XML/md/AbstractIndexedEndpointType.php
Expand Up @@ -89,13 +89,11 @@ public static function fromXML(DOMElement $xml): static

$children = [];
foreach ($xml->childNodes as $child) {
if ($child->namespaceURI === C::NS_MD) {
if (!($child instanceof DOMElement)) {
continue;
} elseif (!($child instanceof DOMElement)) {
continue;
}

$children[] = new Chunk($child);
} elseif ($child->namespaceURI !== C::NS_MD) {
$children[] = new Chunk($child);
} // else continue
}

return new static(
Expand Down
2 changes: 1 addition & 1 deletion src/SAML2/XML/md/AbstractMetadataDocument.php
Expand Up @@ -82,7 +82,7 @@ public function getCacheDuration(): ?string
*/
protected function getOriginalXML(): DOMElement
{
return $this->xml ?? $this->toUnsignedXML();
return $this->getXML() ?? $this->toUnsignedXML();
}


Expand Down
10 changes: 6 additions & 4 deletions src/SAML2/XML/md/AbstractSignedMdElement.php
Expand Up @@ -11,6 +11,8 @@
use SimpleSAML\XMLSecurity\XML\SignedElementTrait;
use SimpleSAML\XMLSecurity\XML\SignedElementInterface;

use function method_exists;

/**
* Abstract class that represents a signed metadata element.
*
Expand All @@ -26,17 +28,17 @@ abstract class AbstractSignedMdElement extends AbstractMdElement implements
/**
* The original signed XML
*
* @var \DOMElement
* @var \DOMElement|null
*/
protected DOMElement $xml;
protected ?DOMElement $xml = null;


/**
* Get the XML element.
*
* @return \DOMElement
* @return \DOMElement|null
*/
public function getXML(): DOMElement
public function getXML(): ?DOMElement
{
return $this->xml;
}
Expand Down
2 changes: 2 additions & 0 deletions tests/SAML2/XML/md/AffiliationDescriptorTest.php
Expand Up @@ -12,6 +12,7 @@
use SimpleSAML\SAML2\XML\md\AffiliationDescriptor;
use SimpleSAML\SAML2\XML\md\KeyDescriptor;
use SimpleSAML\Test\SAML2\Constants as C;
use SimpleSAML\XML\Attribute as XMLAttribute;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XML\Exception\MissingAttributeException;
use SimpleSAML\XML\Exception\SchemaViolationException;
Expand Down Expand Up @@ -79,6 +80,7 @@ public function testMarshalling(): void
'signing',
),
],
namespacedAttribute: [new XMLAttribute(C::NAMESPACE, 'ssp', 'attr1', 'value1')],
);

$this->assertEquals(
Expand Down
1 change: 1 addition & 0 deletions tests/SAML2/XML/md/AttributeAuthorityDescriptorTest.php
Expand Up @@ -32,6 +32,7 @@
* @covers \SimpleSAML\SAML2\XML\md\AbstractMdElement
* @covers \SimpleSAML\SAML2\XML\md\AbstractSignedMdElement
* @covers \SimpleSAML\SAML2\XML\md\AbstractMetadataDocument
* @covers \SimpleSAML\SAML2\XML\md\AbstractRoleDescriptorType
* @covers \SimpleSAML\SAML2\XML\md\AbstractRoleDescriptor
* @covers \SimpleSAML\SAML2\XML\md\AttributeAuthorityDescriptor
* @package simplesamlphp/saml2
Expand Down
3 changes: 2 additions & 1 deletion tests/SAML2/XML/md/AuthnAuthorityDescriptorTest.php
Expand Up @@ -24,9 +24,10 @@
/**
* @covers \SimpleSAML\SAML2\XML\md\AbstractMdElement
* @covers \SimpleSAML\SAML2\XML\md\AbstractSignedMdElement
* @covers \SimpleSAML\SAML2\XML\md\AuthnAuthorityDescriptor
* @covers \SimpleSAML\SAML2\XML\md\AbstractMetadataDocument
* @covers \SimpleSAML\SAML2\XML\md\AbstractRoleDescriptorType
* @covers \SimpleSAML\SAML2\XML\md\AbstractRoleDescriptor
* @covers \SimpleSAML\SAML2\XML\md\AuthnAuthorityDescriptor
* @package simplesamlphp/saml2
*/
final class AuthnAuthorityDescriptorTest extends TestCase
Expand Down
1 change: 0 additions & 1 deletion tests/SAML2/XML/md/EntityDescriptorTest.php
Expand Up @@ -52,7 +52,6 @@
* @covers \SimpleSAML\SAML2\XML\md\AbstractMdElement
* @covers \SimpleSAML\SAML2\XML\md\AbstractSignedMdElement
* @covers \SimpleSAML\SAML2\XML\md\AbstractMetadataDocument
* @covers \SimpleSAML\SAML2\XML\md\AbstractRoleDescriptor
* @covers \SimpleSAML\SAML2\XML\md\EntityDescriptor
*
* @package simplesamlphp/saml2
Expand Down
2 changes: 1 addition & 1 deletion tests/SAML2/XML/md/IDPSSODescriptorTest.php
Expand Up @@ -35,8 +35,8 @@
* Tests for IDPSSODescriptor.
*
* @covers \SimpleSAML\SAML2\XML\md\IDPSSODescriptor
* @covers \SimpleSAML\SAML2\XML\md\AbstractRoleDescriptor
* @covers \SimpleSAML\SAML2\XML\md\AbstractSSODescriptor
* @covers \SimpleSAML\SAML2\XML\md\AbstractRoleDescriptorType
* @covers \SimpleSAML\SAML2\XML\md\AbstractMetadataDocument
* @covers \SimpleSAML\SAML2\XML\md\AbstractSignedMdElement
* @covers \SimpleSAML\SAML2\XML\md\AbstractMdElement
Expand Down
3 changes: 3 additions & 0 deletions tests/SAML2/XML/md/OrganizationTest.php
Expand Up @@ -11,6 +11,8 @@
use SimpleSAML\SAML2\XML\md\OrganizationDisplayName;
use SimpleSAML\SAML2\XML\md\OrganizationName;
use SimpleSAML\SAML2\XML\md\OrganizationURL;
use SimpleSAML\Test\SAML2\Constants as C;
use SimpleSAML\XML\Attribute as XMLAttribute;
use SimpleSAML\XML\Chunk;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XML\Exception\MissingElementException;
Expand Down Expand Up @@ -88,6 +90,7 @@ public function testMarshalling(): void
new Chunk(self::$ext->documentElement),
],
),
[new XMLAttribute(C::NAMESPACE, 'ssp', 'attr1', 'value1')],
);
$root = DOMDocumentFactory::fromString('<root/>');
$root->formatOutput = true;
Expand Down
2 changes: 1 addition & 1 deletion tests/SAML2/XML/md/PDPDescriptorTest.php
Expand Up @@ -24,7 +24,7 @@
* Tests for md:PDPDescriptor
*
* @covers \SimpleSAML\SAML2\XML\md\PDPDescriptor
* @covers \SimpleSAML\SAML2\XML\md\AbstractRoleDescriptor
* @covers \SimpleSAML\SAML2\XML\md\AbstractRoleDescriptorType
* @covers \SimpleSAML\SAML2\XML\md\AbstractMetadataDocument
* @covers \SimpleSAML\SAML2\XML\md\AbstractSignedMdElement
* @covers \SimpleSAML\SAML2\XML\md\AbstractMdElement
Expand Down
1 change: 1 addition & 0 deletions tests/SAML2/XML/md/RoleDescriptorTest.php
Expand Up @@ -48,6 +48,7 @@
*
* @covers \SimpleSAML\SAML2\XML\md\UnknownRoleDescriptor
* @covers \SimpleSAML\SAML2\XML\md\AbstractRoleDescriptor
* @covers \SimpleSAML\SAML2\XML\md\AbstractRoleDescriptorType
* @covers \SimpleSAML\SAML2\XML\md\AbstractMetadataDocument
* @covers \SimpleSAML\SAML2\XML\md\AbstractSignedMdElement
* @covers \SimpleSAML\SAML2\XML\md\AbstractMdElement
Expand Down
2 changes: 1 addition & 1 deletion tests/SAML2/XML/md/SPSSODescriptorTest.php
Expand Up @@ -44,8 +44,8 @@
* Tests for the md:SPSSODescriptor element.
*
* @covers \SimpleSAML\SAML2\XML\md\SPSSODescriptor
* @covers \SimpleSAML\SAML2\XML\md\AbstractRoleDescriptor
* @covers \SimpleSAML\SAML2\XML\md\AbstractSSODescriptor
* @covers \SimpleSAML\SAML2\XML\md\AbstractRoleDescriptorType
* @covers \SimpleSAML\SAML2\XML\md\AbstractMetadataDocument
* @covers \SimpleSAML\SAML2\XML\md\AbstractSignedMdElement
* @covers \SimpleSAML\SAML2\XML\md\AbstractMdElement
Expand Down
1 change: 1 addition & 0 deletions tests/SAML2/XML/mdui/DiscoHintsTest.php
Expand Up @@ -113,6 +113,7 @@ public function testMarshallingChildren(): void
$keywords = new Keywords("nl", ["voorbeeld", "specimen"]);
$discoHints = new DiscoHints();
$discoHints->addChild(new Chunk($keywords->toXML()));
$this->assertCount(1, $discoHints->getElements());

$document = DOMDocumentFactory::fromString('<root />');
$xml = $discoHints->toXML($document->documentElement);
Expand Down
3 changes: 1 addition & 2 deletions tests/resources/xml/md_AffiliationDescriptor.xml
@@ -1,5 +1,4 @@
<md:AffiliationDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" ID="TheID" validUntil="2009-02-13T23:31:30Z"
cacheDuration="PT5000S" affiliationOwnerID="https://simplesamlphp.org/idp/metadata">
<md:AffiliationDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" xmlns:ssp="urn:x-simplesamlphp:namespace" ID="TheID" validUntil="2009-02-13T23:31:30Z" cacheDuration="PT5000S" affiliationOwnerID="https://simplesamlphp.org/idp/metadata" ssp:attr1="value1">
<md:AffiliateMember>https://simplesamlphp.org/sp/metadata</md:AffiliateMember>
<md:AffiliateMember>https://example.org/metadata</md:AffiliateMember>
<md:KeyDescriptor use="signing">
Expand Down
2 changes: 1 addition & 1 deletion tests/resources/xml/md_Organization.xml
@@ -1,4 +1,4 @@
<md:Organization xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata">
<md:Organization xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" xmlns:ssp="urn:x-simplesamlphp:namespace" ssp:attr1="value1">
<md:Extensions>
<some:Ext xmlns:some="urn:mace:some:metadata:1.0">SomeExtension</some:Ext>
</md:Extensions>
Expand Down

0 comments on commit e64f5f4

Please sign in to comment.