Skip to content

Commit

Permalink
Raise coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Mar 19, 2024
1 parent d07edb8 commit 98da916
Show file tree
Hide file tree
Showing 10 changed files with 831 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/SAML11/XML/saml/AbstractAssertionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function getAuthenticationStatements(): array
/**
* @return \SimpleSAML\SAML11\XML\saml\AuthorizationDecisionStatement[]
*/
public function getAuthorizationStatements(): array
public function getAuthorizationDecisionStatements(): array
{
return array_values(array_filter($this->statements, function ($statement) {
return $statement instanceof AuthorizationDecisionStatement;
Expand Down
158 changes: 158 additions & 0 deletions tests/resources/xml/saml_Advice.xml

Large diffs are not rendered by default.

158 changes: 158 additions & 0 deletions tests/resources/xml/saml_Assertion.xml

Large diffs are not rendered by default.

97 changes: 97 additions & 0 deletions tests/resources/xml/saml_AuthorizationDecisionStatement.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<saml:AuthorizationDecisionStatement xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion" Resource="resource" Decision="Permit">
<saml:Subject>
<saml:NameIdentifier NameQualifier="TheNameQualifier" Format="urn:the:format">TheNameIDValue</saml:NameIdentifier>
<saml:SubjectConfirmation>
<saml:ConfirmationMethod>_Test1</saml:ConfirmationMethod>
<saml:ConfirmationMethod>_Test2</saml:ConfirmationMethod>
<saml:SubjectConfirmationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:integer">2</saml:SubjectConfirmationData>
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="fed654">
<ds:KeyName>testkey</ds:KeyName>
<ds:X509Data>
<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>
</ds:KeyInfo>
</saml:SubjectConfirmation>
</saml:Subject>
<saml:Action Namespace="urn:x-simplesamlphp:namespace">urn:x-simplesamlphp:action</saml:Action>
<saml:Evidence>
<saml:AssertionIDReference>_Test</saml:AssertionIDReference>
<saml:Assertion MajorVersion="1" MinorVersion="1" AssertionID="_abc123" 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>
<saml:Audience>urn:x-simplesamlphp:audience</saml:Audience>
</saml:AudienceRestrictionCondition>
<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>
<saml:Statement xmlns:ssp="urn:x-simplesamlphp:namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ssp:CustomStatementType">
<saml:Audience>urn:some:audience</saml:Audience>
</saml:Statement>
<saml:SubjectStatement xmlns:ssp="urn:x-simplesamlphp:namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xsi:type="ssp:CustomSubjectStatementType">
<saml:Subject>
<saml:NameIdentifier NameQualifier="TheNameQualifier" Format="urn:the:format">TheNameIDValue</saml:NameIdentifier>
<saml:SubjectConfirmation>
<saml:ConfirmationMethod>_Test1</saml:ConfirmationMethod>
<saml:ConfirmationMethod>_Test2</saml:ConfirmationMethod>
<saml:SubjectConfirmationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:integer">2</saml:SubjectConfirmationData>
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="fed654">
<ds:KeyName>testkey</ds:KeyName>
<ds:X509Data>
<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>
</ds:KeyInfo>
</saml:SubjectConfirmation>
</saml:Subject>
<saml:Audience>urn:x-simplesamlphp:audience</saml:Audience>
</saml:SubjectStatement>
<saml:AuthenticationStatement AuthenticationMethod="urn:oasis:names:tc:SAML:1.0:am:password" AuthenticationInstant="2023-01-24T09:42:26Z">
<saml:Subject>
<saml:NameIdentifier NameQualifier="TheNameQualifier" Format="urn:the:format">TheNameIDValue</saml:NameIdentifier>
<saml:SubjectConfirmation>
<saml:ConfirmationMethod>_Test1</saml:ConfirmationMethod>
<saml:ConfirmationMethod>_Test2</saml:ConfirmationMethod>
<saml:SubjectConfirmationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:integer">2</saml:SubjectConfirmationData>
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="fed654">
<ds:KeyName>testkey</ds:KeyName>
<ds:X509Data>
<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>
</ds:KeyInfo>
</saml:SubjectConfirmation>
</saml:Subject>
<saml:SubjectLocality IPAddress="127.0.0.1" DNSAddress="simplesamlphp.org" />
<saml:AuthorityBinding xmlns:samlp="urn:oasis:names:tc:SAML:1.0:protocol" AuthorityKind="samlp:AttributeQuery" Location="urn:x-simplesamlphp:location" Binding="urn:x-simplesamlphp:binding" />
</saml:AuthenticationStatement>
<saml:AttributeStatement>
<saml:Subject>
<saml:NameIdentifier NameQualifier="TheNameQualifier" Format="urn:the:format">TheNameIDValue</saml:NameIdentifier>
<saml:SubjectConfirmation>
<saml:ConfirmationMethod>_Test1</saml:ConfirmationMethod>
<saml:ConfirmationMethod>_Test2</saml:ConfirmationMethod>
<saml:SubjectConfirmationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:integer">2</saml:SubjectConfirmationData>
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="fed654">
<ds:KeyName>testkey</ds:KeyName>
<ds:X509Data>
<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>
</ds:KeyInfo>
</saml:SubjectConfirmation>
</saml:Subject>
<saml:Attribute AttributeName="TheName" AttributeNamespace="https://example.org/">
<saml:AttributeValue>FirstValue</saml:AttributeValue>
<saml:AttributeValue>SecondValue</saml:AttributeValue>
</saml:Attribute>
</saml:AttributeStatement>
</saml:Assertion>
</saml:Evidence>
</saml:AuthorizationDecisionStatement>
195 changes: 195 additions & 0 deletions tests/src/SAML11/XML/saml/AdviceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\Test\SAML11\XML\saml;

use DateTimeImmutable;
use DOMDocument;
use PHPUnit\Framework\TestCase;
use SimpleSAML\SAML11\Compat\AbstractContainer;
use SimpleSAML\SAML11\Compat\ContainerSingleton;
use SimpleSAML\SAML11\XML\saml\AbstractStatement;
use SimpleSAML\SAML11\XML\saml\AbstractSubjectStatement;
use SimpleSAML\SAML11\XML\saml\Advice;
use SimpleSAML\SAML11\XML\saml\Assertion;
use SimpleSAML\SAML11\XML\saml\AssertionIDReference;
use SimpleSAML\SAML11\XML\saml\AttributeStatement;
use SimpleSAML\SAML11\XML\saml\AuthenticationStatement;
//use SimpleSAML\SAML11\XML\saml\AuthorizationDecisionStatement;
use SimpleSAML\SAML11\XML\saml\Conditions;
use SimpleSAML\Test\SAML11\CustomCondition;
use SimpleSAML\Test\SAML11\CustomStatement;
use SimpleSAML\Test\SAML11\CustomSubjectStatement;
use SimpleSAML\XML\Chunk;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;

use function dirname;
use function strval;

/**
* Class \SimpleSAML\SAML11\XML\saml\AdviceTest
*
* @covers \SimpleSAML\SAML11\XML\saml\Advice
* @covers \SimpleSAML\SAML11\XML\saml\AbstractAdviceType
* @covers \SimpleSAML\SAML11\XML\saml\AbstractSamlElement
*
* @package simplesamlphp/saml11
*/
final class AdviceTest extends TestCase
{
use SchemaValidationTestTrait;
use SerializableElementTestTrait;

/** @var \SimpleSAML\SAML11\Compat\AbstractContainer */
private static AbstractContainer $containerBackup;

/** @var \SimpleSAML\XML\Chunk $chunk */
private static Chunk $chunk;

/** @var \DOMDocument $conditions */
private static DOMDocument $conditions;

/** @var \DOMDocument $statement */
private static DOMDocument $statement;

/** @var \DOMDocument $subjectStatement */
private static DOMDocument $subjectStatement;

/** @var \DOMDocument $authnStatement */
private static DOMDocument $authnStatement;

/** @var \DOMDocument $authzDecisionStatement */
// private static DOMDocument $authzDecisionStatement;

/** @var \DOMDocument $attributeStatement */
private static DOMDocument $attributeStatement;


/**
*/
public static function setUpBeforeClass(): void
{
self::$containerBackup = ContainerSingleton::getInstance();

self::$schemaFile = dirname(__FILE__, 5) . '/resources/schemas/simplesamlphp.xsd';

self::$testedClass = Advice::class;

self::$xmlRepresentation = DOMDocumentFactory::fromFile(
dirname(__FILE__, 5) . '/resources/xml/saml_Advice.xml',
);

self::$conditions = DOMDocumentFactory::fromFile(
dirname(__FILE__, 5) . '/resources/xml/saml_Conditions.xml',
);

self::$statement = DOMDocumentFactory::fromFile(
dirname(__FILE__, 5) . '/resources/xml/saml_Statement.xml',
);

self::$subjectStatement = DOMDocumentFactory::fromFile(
dirname(__FILE__, 5) . '/resources/xml/saml_SubjectStatement.xml',
);

self::$authnStatement = DOMDocumentFactory::fromFile(
dirname(__FILE__, 5) . '/resources/xml/saml_AuthenticationStatement.xml',
);

// self::$authzDecisionStatement = DOMDocumentFactory::fromFile(
// dirname(__FILE__, 5) . '/resources/xml/saml_AuthorizationDecisionStatement.xml',
// );

self::$attributeStatement = DOMDocumentFactory::fromFile(
dirname(__FILE__, 5) . '/resources/xml/saml_AttributeStatement.xml',
);

self::$chunk = new Chunk(DOMDocumentFactory::fromString(
'<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">some</ssp:Chunk>'
)->documentElement);


$container = clone self::$containerBackup;
$container->registerExtensionHandler(CustomCondition::class);
$container->registerExtensionHandler(CustomStatement::class);
$container->registerExtensionHandler(CustomSubjectStatement::class);
ContainerSingleton::setContainer($container);
}


/**
*/
public static function tearDownAfterClass(): void
{
ContainerSingleton::setContainer(self::$containerBackup);
}


/**
*/
public function testMarshalling(): void
{
$assertionIDReference = new AssertionIDReference('_Test');

$assertion = new Assertion(
'_abc123',
'urn:x-simplesamlphp:phpunit',
new DateTimeImmutable('2023-01-24T09:42:26Z'),
Conditions::fromXML(self::$conditions->documentElement),
null, // null
[
AbstractStatement::fromXML(self::$statement->documentElement),
AbstractSubjectStatement::fromXML(self::$subjectStatement->documentElement),
AuthenticationStatement::fromXML(self::$authnStatement->documentElement),
//null, // authzDecisionStatement
AttributeStatement::fromXML(self::$attributeStatement->documentElement),
],
);

$advice = new Advice(
[$assertionIDReference],
[$assertion],
[self::$chunk],
);

$assertion = new Assertion(
'_abc123',
'urn:x-simplesamlphp:phpunit',
new DateTimeImmutable('2023-01-24T09:42:26Z'),
Conditions::fromXML(self::$conditions->documentElement),
$advice,
[
AbstractStatement::fromXML(self::$statement->documentElement),
AbstractSubjectStatement::fromXML(self::$subjectStatement->documentElement),
AuthenticationStatement::fromXML(self::$authnStatement->documentElement),
//null, // authzDecisionStatement
AttributeStatement::fromXML(self::$attributeStatement->documentElement),
],
);

$advice = new Advice(
[$assertionIDReference],
[$assertion],
[self::$chunk],
);

$this->assertEquals(
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
strval($advice),
);
}

/**
*/
public function testMarshallingEmpty(): void
{
$advice = new Advice();
$this->assertEquals(
'<saml:Advice xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion"/>',
strval($advice),
);
$this->assertTrue($advice->isEmptyElement());
}
}
Loading

0 comments on commit 98da916

Please sign in to comment.