From fd76b574240d6b3cb4e340f15528f8abfdfc4af2 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Tue, 23 Jul 2024 23:17:56 +0200 Subject: [PATCH] Fix QA --- src/SAML2/Assert/CustomAssertionTrait.php | 4 ++-- src/SAML2/XML/md/AffiliateMember.php | 2 -- src/SAML2/XML/md/AffiliationDescriptor.php | 1 - tests/InterOperability/EntitiesDescriptorTest.php | 8 ++++---- tests/SAML2/Assert/EntityIDTest.php | 2 +- tests/SAML2/Assert/URITest.php | 2 +- 6 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/SAML2/Assert/CustomAssertionTrait.php b/src/SAML2/Assert/CustomAssertionTrait.php index 208447d49..59d875ccf 100644 --- a/src/SAML2/Assert/CustomAssertionTrait.php +++ b/src/SAML2/Assert/CustomAssertionTrait.php @@ -15,7 +15,7 @@ */ trait CustomAssertionTrait { - private const SCHEME_REGEX = '/^([a-z][a-z0-9\+\-\.]+[:])/i'; + private static string $scheme_regex = '/^([a-z][a-z0-9\+\-\.]+[:])/i'; /*********************************************************************************** * NOTE: Custom assertions may be added below this line. * @@ -66,7 +66,7 @@ private static function validURI(string $value, string $message = ''): void BaseAssert::notWhitespaceOnly($value, $message ?: '%s is not a SAML2-compliant URI'); // If it doesn't have a scheme, it's not an absolute URI - BaseAssert::regex($value, self::SCHEME_REGEX, $message ?: '%s is not a SAML2-compliant URI'); + BaseAssert::regex($value, self::$scheme_regex, $message ?: '%s is not a SAML2-compliant URI'); } catch (AssertionFailedException $e) { throw new ProtocolViolationException($e->getMessage()); } diff --git a/src/SAML2/XML/md/AffiliateMember.php b/src/SAML2/XML/md/AffiliateMember.php index ec1ac5f62..d58d4a032 100644 --- a/src/SAML2/XML/md/AffiliateMember.php +++ b/src/SAML2/XML/md/AffiliateMember.php @@ -5,8 +5,6 @@ namespace SimpleSAML\SAML2\XML\md; use SimpleSAML\SAML2\Assert\Assert as SAMLAssert; -use SimpleSAML\SAML2\Constants as C; -use SimpleSAML\SAML2\Exception\ProtocolViolationException; use SimpleSAML\XML\StringElementTrait; /** diff --git a/src/SAML2/XML/md/AffiliationDescriptor.php b/src/SAML2/XML/md/AffiliationDescriptor.php index fe2bcc19a..4d0e4286c 100644 --- a/src/SAML2/XML/md/AffiliationDescriptor.php +++ b/src/SAML2/XML/md/AffiliationDescriptor.php @@ -9,7 +9,6 @@ use SimpleSAML\Assert\Assert; use SimpleSAML\SAML2\Assert\Assert as SAMLAssert; use SimpleSAML\SAML2\Constants as C; -use SimpleSAML\SAML2\Exception\ProtocolViolationException; use SimpleSAML\XML\Exception\InvalidDOMElementException; use SimpleSAML\XML\Exception\TooManyElementsException; use SimpleSAML\XML\ExtendableAttributesTrait; diff --git a/tests/InterOperability/EntitiesDescriptorTest.php b/tests/InterOperability/EntitiesDescriptorTest.php index b47ec6a90..7cd71b598 100644 --- a/tests/InterOperability/EntitiesDescriptorTest.php +++ b/tests/InterOperability/EntitiesDescriptorTest.php @@ -8,10 +8,7 @@ use Exception; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -use SimpleSAML\Assert\AssertionFailedException; -use SimpleSAML\SAML2\Constants as C; use SimpleSAML\SAML2\Utils\XPath; -use SimpleSAML\SAML2\XML\md\EntitiesDescriptor; use SimpleSAML\SAML2\XML\md\EntityDescriptor; use SimpleSAML\XML\DOMDocumentFactory; @@ -51,11 +48,14 @@ private function parseMetadata(DOMElement $metadata): void // Test for an EntitiesDescriptor or EntityDescriptor $entityDescriptorElements = XPath::xpQuery($metadata, './saml_metadata:EntityDescriptor', $xpCache); $entitiesDescriptorElements = XPath::xpQuery($metadata, './saml_metadata:EntitiesDescriptor', $xpCache); - $descriptors = array_merge($entityDescriptorElements ?? [], $entitiesDescriptorElement ?? []); + $descriptors = array_merge($entityDescriptorElements, $entitiesDescriptorElements); + foreach ($descriptors as $descriptor) { + /** @var \DOMElement $descriptor */ $this->parseMetadata($descriptor); } } elseif ($metadata->localName === 'EntityDescriptor') { + /** @var \DOMAttr[] $entityID */ $entityID = XPath::xpQuery($metadata, './@entityID', $xpCache); try { diff --git a/tests/SAML2/Assert/EntityIDTest.php b/tests/SAML2/Assert/EntityIDTest.php index 73546b3ac..60966bbd6 100644 --- a/tests/SAML2/Assert/EntityIDTest.php +++ b/tests/SAML2/Assert/EntityIDTest.php @@ -7,9 +7,9 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; +use SimpleSAML\SAML2\Assert\Assert as SAML2Assert; use SimpleSAML\SAML2\Constants as C; use SimpleSAML\SAML2\Exception\ProtocolViolationException; -use SimpleSAML\SAML2\Assert\Assert as SAML2Assert; use SimpleSAML\XML\Exception\SchemaViolationException; use function str_pad; diff --git a/tests/SAML2/Assert/URITest.php b/tests/SAML2/Assert/URITest.php index 146697c97..31213b52b 100644 --- a/tests/SAML2/Assert/URITest.php +++ b/tests/SAML2/Assert/URITest.php @@ -7,8 +7,8 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -use SimpleSAML\SAML2\Exception\ProtocolViolationException; use SimpleSAML\SAML2\Assert\Assert as SAML2Assert; +use SimpleSAML\SAML2\Exception\ProtocolViolationException; use SimpleSAML\XML\Exception\SchemaViolationException; /**