diff --git a/composer.json b/composer.json index dd3659002..a030cc04a 100644 --- a/composer.json +++ b/composer.json @@ -31,10 +31,10 @@ "psr/clock": "^1.0", "psr/http-message": "^2.0", "psr/log": "^2.0 || ^3.0", - "simplesamlphp/assert": "~1.7.0", - "simplesamlphp/xml-common": "~1.23.0", - "simplesamlphp/xml-security": "~1.12.0", - "simplesamlphp/xml-soap": "~1.6.0" + "simplesamlphp/assert": "~1.8.0", + "simplesamlphp/xml-common": "~1.24.0", + "simplesamlphp/xml-security": "~1.13.0", + "simplesamlphp/xml-soap": "~1.7.0" }, "require-dev": { "ext-intl": "*", diff --git a/src/Assert/Assert.php b/src/Assert/Assert.php index 09f7016b1..b22052798 100644 --- a/src/Assert/Assert.php +++ b/src/Assert/Assert.php @@ -4,29 +4,7 @@ namespace SimpleSAML\SAML2\Assert; -use BadMethodCallException; // Requires ext-spl -use DateTime; // requires ext-date -use DateTimeImmutable; // requires ext-date -use InvalidArgumentException; // Requires ext-spl -use SimpleSAML\Assert\Assert as BaseAssert; -use SimpleSAML\Assert\AssertionFailedException; -use Throwable; - -use function array_pop; -use function array_unshift; -use function call_user_func_array; -use function end; -use function enum_exists; -use function function_exists; -use function get_class; -use function is_object; -use function is_resource; -use function is_string; -use function is_subclass_of; -use function lcfirst; -use function method_exists; -use function preg_match; // Requires ext-pcre -use function strval; +use SimpleSAML\XMLSecurity\Assert\Assert as BaseAssert; /** * SimpleSAML\SAML2\Assert\Assert wrapper class @@ -43,136 +21,7 @@ * @method static void allValidURI(mixed $value, string $message = '', string $exception = '') * @method static void allValidEntityID(mixed $value, string $message = '', string $exception = '') */ -final class Assert +class Assert extends BaseAssert { use CustomAssertionTrait; - - - /** - * @param string $name - * @param array $arguments - */ - public static function __callStatic(string $name, array $arguments): void - { - // Handle Exception-parameter - $exception = AssertionFailedException::class; - - $last = end($arguments); - if (is_string($last) && class_exists($last) && is_subclass_of($last, Throwable::class)) { - $exception = $last; - array_pop($arguments); - } - - try { - if (method_exists(static::class, $name)) { - call_user_func_array([static::class, $name], $arguments); - return; - } elseif (preg_match('/^nullOr(.*)$/i', $name, $matches)) { - $method = lcfirst($matches[1]); - if (method_exists(static::class, $method)) { - call_user_func_array([static::class, 'nullOr'], [[static::class, $method], $arguments]); - } elseif (method_exists(BaseAssert::class, $method)) { - call_user_func_array([static::class, 'nullOr'], [[BaseAssert::class, $method], $arguments]); - } else { - throw new BadMethodCallException(sprintf("Assertion named `%s` does not exists.", $method)); - } - } elseif (preg_match('/^all(.*)$/i', $name, $matches)) { - $method = lcfirst($matches[1]); - if (method_exists(static::class, $method)) { - call_user_func_array([static::class, 'all'], [[static::class, $method], $arguments]); - } elseif (method_exists(BaseAssert::class, $method)) { - call_user_func_array([static::class, 'all'], [[BaseAssert::class, $method], $arguments]); - } else { - throw new BadMethodCallException(sprintf("Assertion named `%s` does not exists.", $method)); - } - } else { - throw new BadMethodCallException(sprintf("Assertion named `%s` does not exists.", $name)); - } - } catch (InvalidArgumentException $e) { - throw new $exception($e->getMessage()); - } - } - - - /** - * Handle nullOr* for either Webmozart or for our custom assertions - * - * @param callable $method - * @param array $arguments - * @return void - */ - private static function nullOr(callable $method, array $arguments): void - { - $value = reset($arguments); - ($value === null) || call_user_func_array($method, $arguments); - } - - - /** - * all* for our custom assertions - * - * @param callable $method - * @param array $arguments - * @return void - */ - private static function all(callable $method, array $arguments): void - { - $values = array_pop($arguments); - foreach ($values as $value) { - $tmp = $arguments; - array_unshift($tmp, $value); - call_user_func_array($method, $tmp); - } - } - - - /** - * @param mixed $value - * - * @return string - */ - protected static function valueToString(mixed $value): string - { - if (is_resource($value)) { - return 'resource'; - } - - if (null === $value) { - return 'null'; - } - - if (true === $value) { - return 'true'; - } - - if (false === $value) { - return 'false'; - } - - if (is_array($value)) { - return 'array'; - } - - if (is_object($value)) { - if (method_exists($value, '__toString')) { - return $value::class . ': ' . self::valueToString($value->__toString()); - } - - if ($value instanceof DateTime || $value instanceof DateTimeImmutable) { - return $value::class . ': ' . self::valueToString($value->format('c')); - } - - if (function_exists('enum_exists') && enum_exists(get_class($value))) { - return get_class($value) . '::' . $value->name; - } - - return $value::class; - } - - if (is_string($value)) { - return '"' . $value . '"'; - } - - return strval($value); - } } diff --git a/src/Assert/CustomAssertionTrait.php b/src/Assert/CustomAssertionTrait.php index 8d61a4b65..5ea636604 100644 --- a/src/Assert/CustomAssertionTrait.php +++ b/src/Assert/CustomAssertionTrait.php @@ -4,11 +4,9 @@ namespace SimpleSAML\SAML2\Assert; -use SimpleSAML\Assert\Assert as BaseAssert; use SimpleSAML\Assert\AssertionFailedException; use SimpleSAML\SAML2\Constants as C; use SimpleSAML\SAML2\Exception\ProtocolViolationException; -use SimpleSAML\XML\Exception\SchemaViolationException; /** * @package simplesamlphp/saml2 @@ -30,16 +28,12 @@ trait CustomAssertionTrait * @param string $value * @param string $message */ - private static function validDateTime(string $value, string $message = ''): void + protected static function validDateTime(string $value, string $message = ''): void { - try { - BaseAssert::validDateTime($value); - } catch (AssertionFailedException $e) { - throw new SchemaViolationException($e->getMessage()); - } + parent::validDateTime($value); try { - BaseAssert::endsWith( + parent::endsWith( $value, 'Z', '%s is not a DateTime expressed in the UTC timezone using the \'Z\' timezone identifier.', @@ -54,17 +48,13 @@ private static function validDateTime(string $value, string $message = ''): void * @param string $value * @param string $message */ - private static function validURI(string $value, string $message = ''): void + protected static function validURI(string $value, string $message = ''): void { - try { - BaseAssert::validURI($value); - } catch (AssertionFailedException $e) { - throw new SchemaViolationException($e->getMessage()); - } + parent::validURI($value); try { // 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'); + parent::regex($value, self::$scheme_regex, $message ?: '%s is not a SAML2-compliant URI'); } catch (AssertionFailedException $e) { throw new ProtocolViolationException($e->getMessage()); } @@ -75,13 +65,13 @@ private static function validURI(string $value, string $message = ''): void * @param string $value * @param string $message */ - private static function validEntityID(string $value, string $message = ''): void + protected static function validEntityID(string $value, string $message = ''): void { static::validURI($value); try { - BaseAssert::notWhitespaceOnly($value); - BaseAssert::maxLength( + parent::notWhitespaceOnly($value); + parent::maxLength( $value, C::ENTITYID_MAX_LENGTH, sprintf('An entityID cannot be longer than %d characters.', C::ENTITYID_MAX_LENGTH), diff --git a/src/Compat/AbstractContainer.php b/src/Compat/AbstractContainer.php index af45888e1..700ca79c0 100644 --- a/src/Compat/AbstractContainer.php +++ b/src/Compat/AbstractContainer.php @@ -6,7 +6,7 @@ use Psr\Clock\ClockInterface; use Psr\Log\LoggerInterface; -use SimpleSAML\Assert\Assert; +use SimpleSAML\SAML2\Assert\Assert; use SimpleSAML\SAML2\XML\ExtensionPointInterface; use SimpleSAML\XML\AbstractElement; use SimpleSAML\XML\Exception\SchemaViolationException; diff --git a/src/XML/ExtensionPointTrait.php b/src/XML/ExtensionPointTrait.php index 19a5f8891..3602fb67d 100644 --- a/src/XML/ExtensionPointTrait.php +++ b/src/XML/ExtensionPointTrait.php @@ -5,7 +5,7 @@ namespace SimpleSAML\SAML2\XML; use RuntimeException; -use SimpleSAML\Assert\Assert; +use SimpleSAML\SAML2\Assert\Assert; use SimpleSAML\XML\Exception\SchemaViolationException; /** diff --git a/src/XML/md/AbstractMetadataDocument.php b/src/XML/md/AbstractMetadataDocument.php index 29f8dfc5e..845e91090 100644 --- a/src/XML/md/AbstractMetadataDocument.php +++ b/src/XML/md/AbstractMetadataDocument.php @@ -6,7 +6,7 @@ use DateTimeImmutable; use DOMElement; -use SimpleSAML\Assert\Assert; +use SimpleSAML\SAML2\Assert\Assert; use SimpleSAML\SAML2\Constants as C; use SimpleSAML\SAML2\XML\ExtendableElementTrait; use SimpleSAML\XML\Exception\SchemaViolationException; diff --git a/src/XML/md/AbstractRoleDescriptor.php b/src/XML/md/AbstractRoleDescriptor.php index 9fc9d21c0..d88227e23 100644 --- a/src/XML/md/AbstractRoleDescriptor.php +++ b/src/XML/md/AbstractRoleDescriptor.php @@ -6,8 +6,7 @@ use DateTimeImmutable; use DOMElement; -use SimpleSAML\Assert\Assert; -use SimpleSAML\SAML2\Assert\Assert as SAMLAssert; +use SimpleSAML\SAML2\Assert\Assert; use SimpleSAML\SAML2\Constants as C; use SimpleSAML\SAML2\Utils; use SimpleSAML\SAML2\XML\ExtensionPointInterface; @@ -136,7 +135,7 @@ public static function fromXML(DOMElement $xml): static $protocols = self::getAttribute($xml, 'protocolSupportEnumeration'); $validUntil = self::getOptionalAttribute($xml, 'validUntil', null); - SAMLAssert::nullOrValidDateTime($validUntil); + Assert::nullOrValidDateTime($validUntil); $orgs = Organization::getChildrenOfClass($xml); Assert::maxCount( diff --git a/src/XML/saml/AbstractBaseID.php b/src/XML/saml/AbstractBaseID.php index dd4d50acb..330c06e4b 100644 --- a/src/XML/saml/AbstractBaseID.php +++ b/src/XML/saml/AbstractBaseID.php @@ -5,7 +5,7 @@ namespace SimpleSAML\SAML2\XML\saml; use DOMElement; -use SimpleSAML\Assert\Assert; +use SimpleSAML\SAML2\Assert\Assert; use SimpleSAML\SAML2\Constants as C; use SimpleSAML\SAML2\Utils; use SimpleSAML\SAML2\XML\EncryptableElementTrait; diff --git a/src/XML/saml/AbstractCondition.php b/src/XML/saml/AbstractCondition.php index 9b1ad027c..d35320834 100644 --- a/src/XML/saml/AbstractCondition.php +++ b/src/XML/saml/AbstractCondition.php @@ -5,7 +5,7 @@ namespace SimpleSAML\SAML2\XML\saml; use DOMElement; -use SimpleSAML\Assert\Assert; +use SimpleSAML\SAML2\Assert\Assert; use SimpleSAML\SAML2\Constants as C; use SimpleSAML\SAML2\Utils; use SimpleSAML\SAML2\XML\ExtensionPointInterface; diff --git a/src/XML/saml/AbstractStatement.php b/src/XML/saml/AbstractStatement.php index 7420337d3..61d427b9e 100644 --- a/src/XML/saml/AbstractStatement.php +++ b/src/XML/saml/AbstractStatement.php @@ -5,7 +5,7 @@ namespace SimpleSAML\SAML2\XML\saml; use DOMElement; -use SimpleSAML\Assert\Assert; +use SimpleSAML\SAML2\Assert\Assert; use SimpleSAML\SAML2\Constants as C; use SimpleSAML\SAML2\Utils; use SimpleSAML\SAML2\XML\ExtensionPointInterface; diff --git a/src/XML/saml/Assertion.php b/src/XML/saml/Assertion.php index 41aca4b87..224a27b5f 100644 --- a/src/XML/saml/Assertion.php +++ b/src/XML/saml/Assertion.php @@ -6,8 +6,7 @@ use DateTimeImmutable; use DOMElement; -use SimpleSAML\Assert\Assert; -use SimpleSAML\SAML2\Assert\Assert as SAMLAssert; +use SimpleSAML\SAML2\Assert\Assert; use SimpleSAML\SAML2\Constants as C; use SimpleSAML\SAML2\Exception\ProtocolViolationException; use SimpleSAML\SAML2\Utils\XPath; @@ -262,7 +261,7 @@ public static function fromXML(DOMElement $xml): static // Strip sub-seconds - See paragraph 1.3.3 of SAML core specifications $issueInstant = preg_replace('/([.][0-9]+Z)$/', 'Z', $issueInstant, 1); - SAMLAssert::validDateTime($issueInstant, ProtocolViolationException::class); + Assert::validDateTime($issueInstant, ProtocolViolationException::class); $issueInstant = new DateTimeImmutable($issueInstant); $issuer = Issuer::getChildrenOfClass($xml); diff --git a/src/XML/saml/AssertionIDRef.php b/src/XML/saml/AssertionIDRef.php index aec2b0c55..514f8b13e 100644 --- a/src/XML/saml/AssertionIDRef.php +++ b/src/XML/saml/AssertionIDRef.php @@ -4,7 +4,7 @@ namespace SimpleSAML\SAML2\XML\saml; -use SimpleSAML\Assert\Assert; +use SimpleSAML\SAML2\Assert\Assert; use SimpleSAML\SAML2\XML\StringElementTrait; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\SchemaValidatableElementInterface; diff --git a/src/XML/saml/Attribute.php b/src/XML/saml/Attribute.php index 4f94c6139..0873c9139 100644 --- a/src/XML/saml/Attribute.php +++ b/src/XML/saml/Attribute.php @@ -5,8 +5,7 @@ namespace SimpleSAML\SAML2\XML\saml; use DOMElement; -use SimpleSAML\Assert\Assert; -use SimpleSAML\SAML2\Assert\Assert as SAMLAssert; +use SimpleSAML\SAML2\Assert\Assert; use SimpleSAML\SAML2\Constants as C; use SimpleSAML\SAML2\XML\EncryptableElementTrait; use SimpleSAML\XML\Exception\InvalidDOMElementException; @@ -51,13 +50,13 @@ public function __construct( array $namespacedAttribute = [], ) { Assert::notWhitespaceOnly($name, 'Cannot specify an empty name for an Attribute.'); - SAMLAssert::nullOrValidURI($nameFormat); + Assert::nullOrValidURI($nameFormat); Assert::nullOrNotWhitespaceOnly($friendlyName, 'FriendlyName cannot be an empty string.'); Assert::maxCount($attributeValue, C::UNBOUNDED_LIMIT); Assert::allIsInstanceOf($attributeValue, AttributeValue::class, 'Invalid AttributeValue.'); if ($nameFormat === C::NAMEFORMAT_URI) { - SAMLAssert::validURI( + Assert::validURI( $name, sprintf("Attribute name `%s` does not match its declared format `%s`", $name, $nameFormat), ); diff --git a/src/XML/saml/AttributeValue.php b/src/XML/saml/AttributeValue.php index fabf94fe3..b17fdf934 100644 --- a/src/XML/saml/AttributeValue.php +++ b/src/XML/saml/AttributeValue.php @@ -7,7 +7,7 @@ use DateTimeImmutable; use DateTimeInterface; use DOMElement; -use SimpleSAML\Assert\Assert; +use SimpleSAML\SAML2\Assert\Assert; use SimpleSAML\SAML2\Constants as C; use SimpleSAML\XML\AbstractElement; use SimpleSAML\XML\Chunk; diff --git a/src/XML/saml/SubjectConfirmationData.php b/src/XML/saml/SubjectConfirmationData.php index 1fad8c8a1..e8522141b 100644 --- a/src/XML/saml/SubjectConfirmationData.php +++ b/src/XML/saml/SubjectConfirmationData.php @@ -6,7 +6,7 @@ use DateTimeImmutable; use DOMElement; -use SimpleSAML\Assert\Assert; +use SimpleSAML\SAML2\Assert\Assert; use SimpleSAML\SAML2\Assert\Assert as SAMLAssert; use SimpleSAML\SAML2\Constants as C; use SimpleSAML\SAML2\Exception\ProtocolViolationException; diff --git a/src/XML/samlp/AbstractMessage.php b/src/XML/samlp/AbstractMessage.php index bc51c1e0f..b31fc3533 100644 --- a/src/XML/samlp/AbstractMessage.php +++ b/src/XML/samlp/AbstractMessage.php @@ -6,8 +6,7 @@ use DateTimeImmutable; use DOMElement; -use SimpleSAML\Assert\Assert; -use SimpleSAML\SAML2\Assert\Assert as SAMLAssert; +use SimpleSAML\SAML2\Assert\Assert; use SimpleSAML\SAML2\Constants as C; use SimpleSAML\SAML2\Exception\ProtocolViolationException; use SimpleSAML\SAML2\Utils; @@ -75,8 +74,8 @@ protected function __construct( ) { Assert::nullOrSame($issueInstant?->getTimeZone()->getName(), 'Z', ProtocolViolationException::class); Assert::nullOrValidNCName($id); // Covers the empty string - SAMLAssert::nullOrValidURI($destination); - SAMLAssert::nullOrValidURI($consent); + Assert::nullOrValidURI($destination); + Assert::nullOrValidURI($consent); $this->setExtensions($extensions); } diff --git a/src/XML/samlp/AbstractStatusResponse.php b/src/XML/samlp/AbstractStatusResponse.php index da8913124..8ff880c91 100644 --- a/src/XML/samlp/AbstractStatusResponse.php +++ b/src/XML/samlp/AbstractStatusResponse.php @@ -6,7 +6,7 @@ use DateTimeImmutable; use DOMElement; -use SimpleSAML\Assert\Assert; +use SimpleSAML\SAML2\Assert\Assert; use SimpleSAML\SAML2\Constants as C; use SimpleSAML\SAML2\XML\saml\Issuer; diff --git a/src/XML/samlp/Artifact.php b/src/XML/samlp/Artifact.php index 66da4b5c3..559611363 100644 --- a/src/XML/samlp/Artifact.php +++ b/src/XML/samlp/Artifact.php @@ -5,7 +5,7 @@ namespace SimpleSAML\SAML2\XML\samlp; use DOMElement; -use SimpleSAML\Assert\Assert; +use SimpleSAML\SAML2\Assert\Assert; use SimpleSAML\XML\Base64ElementTrait; use SimpleSAML\XML\Exception\InvalidDOMElementException; use SimpleSAML\XML\SchemaValidatableElementInterface; diff --git a/src/XML/samlp/ArtifactResolve.php b/src/XML/samlp/ArtifactResolve.php index e7610dae1..91c626044 100644 --- a/src/XML/samlp/ArtifactResolve.php +++ b/src/XML/samlp/ArtifactResolve.php @@ -6,8 +6,7 @@ use DateTimeImmutable; use DOMElement; -use SimpleSAML\Assert\Assert; -use SimpleSAML\SAML2\Assert\Assert as SAMLAssert; +use SimpleSAML\SAML2\Assert\Assert; use SimpleSAML\SAML2\Exception\Protocol\RequestVersionTooHighException; use SimpleSAML\SAML2\Exception\Protocol\RequestVersionTooLowException; use SimpleSAML\SAML2\Exception\ProtocolViolationException; @@ -99,7 +98,7 @@ public static function fromXML(DOMElement $xml): static // Strip sub-seconds - See paragraph 1.3.3 of SAML core specifications $issueInstant = preg_replace('/([.][0-9]+Z)$/', 'Z', $issueInstant, 1); - SAMLAssert::validDateTime($issueInstant, ProtocolViolationException::class); + Assert::validDateTime($issueInstant, ProtocolViolationException::class); $issueInstant = new DateTimeImmutable($issueInstant); $issuer = Issuer::getChildrenOfClass($xml); diff --git a/src/XML/samlp/ArtifactResponse.php b/src/XML/samlp/ArtifactResponse.php index f0e2216fd..f928505bc 100644 --- a/src/XML/samlp/ArtifactResponse.php +++ b/src/XML/samlp/ArtifactResponse.php @@ -6,8 +6,7 @@ use DateTimeImmutable; use DOMElement; -use SimpleSAML\Assert\Assert; -use SimpleSAML\SAML2\Assert\Assert as SAMLAssert; +use SimpleSAML\SAML2\Assert\Assert; use SimpleSAML\SAML2\Exception\Protocol\RequestVersionTooHighException; use SimpleSAML\SAML2\Exception\Protocol\RequestVersionTooLowException; use SimpleSAML\SAML2\Exception\ProtocolViolationException; @@ -115,7 +114,7 @@ public static function fromXML(DOMElement $xml): static // Strip sub-seconds - See paragraph 1.3.3 of SAML core specifications $issueInstant = preg_replace('/([.][0-9]+Z)$/', 'Z', $issueInstant, 1); - SAMLAssert::validDateTime($issueInstant, ProtocolViolationException::class); + Assert::validDateTime($issueInstant, ProtocolViolationException::class); $issueInstant = new DateTimeImmutable($issueInstant); $issuer = Issuer::getChildrenOfClass($xml); diff --git a/src/XML/samlp/AssertionIDRequest.php b/src/XML/samlp/AssertionIDRequest.php index 22adeb0a2..d994a8345 100644 --- a/src/XML/samlp/AssertionIDRequest.php +++ b/src/XML/samlp/AssertionIDRequest.php @@ -6,8 +6,7 @@ use DateTimeImmutable; use DOMElement; -use SimpleSAML\Assert\Assert; -use SimpleSAML\SAML2\Assert\Assert as SAMLAssert; +use SimpleSAML\SAML2\Assert\Assert; use SimpleSAML\SAML2\Exception\Protocol\RequestVersionTooHighException; use SimpleSAML\SAML2\Exception\Protocol\RequestVersionTooLowException; use SimpleSAML\SAML2\Exception\ProtocolViolationException; @@ -116,7 +115,7 @@ public static function fromXML(DOMElement $xml): static // Strip sub-seconds - See paragraph 1.3.3 of SAML core specifications $issueInstant = preg_replace('/([.][0-9]+Z)$/', 'Z', $issueInstant, 1); - SAMLAssert::validDateTime($issueInstant, ProtocolViolationException::class); + Assert::validDateTime($issueInstant, ProtocolViolationException::class); $issueInstant = new DateTimeImmutable($issueInstant); $extensions = Extensions::getChildrenOfClass($xml); diff --git a/src/XML/samlp/AttributeQuery.php b/src/XML/samlp/AttributeQuery.php index 900491e26..07334e3dc 100644 --- a/src/XML/samlp/AttributeQuery.php +++ b/src/XML/samlp/AttributeQuery.php @@ -6,8 +6,7 @@ use DateTimeImmutable; use DOMElement; -use SimpleSAML\Assert\Assert; -use SimpleSAML\SAML2\Assert\Assert as SAMLAssert; +use SimpleSAML\SAML2\Assert\Assert; use SimpleSAML\SAML2\Exception\Protocol\RequestVersionTooHighException; use SimpleSAML\SAML2\Exception\Protocol\RequestVersionTooLowException; use SimpleSAML\SAML2\Exception\ProtocolViolationException; @@ -136,7 +135,7 @@ public static function fromXML(DOMElement $xml): static // Strip sub-seconds - See paragraph 1.3.3 of SAML core specifications $issueInstant = preg_replace('/([.][0-9]+Z)$/', 'Z', $issueInstant, 1); - SAMLAssert::validDateTime($issueInstant, ProtocolViolationException::class); + Assert::validDateTime($issueInstant, ProtocolViolationException::class); $issueInstant = new DateTimeImmutable($issueInstant); $issuer = Issuer::getChildrenOfClass($xml); diff --git a/src/XML/samlp/AuthnQuery.php b/src/XML/samlp/AuthnQuery.php index 618f913b3..543f33b94 100644 --- a/src/XML/samlp/AuthnQuery.php +++ b/src/XML/samlp/AuthnQuery.php @@ -6,8 +6,7 @@ use DateTimeImmutable; use DOMElement; -use SimpleSAML\Assert\Assert; -use SimpleSAML\SAML2\Assert\Assert as SAMLAssert; +use SimpleSAML\SAML2\Assert\Assert; use SimpleSAML\SAML2\Exception\Protocol\RequestVersionTooHighException; use SimpleSAML\SAML2\Exception\Protocol\RequestVersionTooLowException; use SimpleSAML\SAML2\Exception\ProtocolViolationException; @@ -121,7 +120,7 @@ public static function fromXML(DOMElement $xml): static // Strip sub-seconds - See paragraph 1.3.3 of SAML core specifications $issueInstant = preg_replace('/([.][0-9]+Z)$/', 'Z', $issueInstant, 1); - SAMLAssert::validDateTime($issueInstant, ProtocolViolationException::class); + Assert::validDateTime($issueInstant, ProtocolViolationException::class); $issueInstant = new DateTimeImmutable($issueInstant); $requestedAuthnContext = RequestedAuthnContext::getChildrenOfClass($xml); diff --git a/src/XML/samlp/AuthnRequest.php b/src/XML/samlp/AuthnRequest.php index c37323867..71d3ae32b 100644 --- a/src/XML/samlp/AuthnRequest.php +++ b/src/XML/samlp/AuthnRequest.php @@ -6,8 +6,7 @@ use DateTimeImmutable; use DOMElement; -use SimpleSAML\Assert\Assert; -use SimpleSAML\SAML2\Assert\Assert as SAMLAssert; +use SimpleSAML\SAML2\Assert\Assert; use SimpleSAML\SAML2\Exception\Protocol\RequestVersionTooHighException; use SimpleSAML\SAML2\Exception\Protocol\RequestVersionTooLowException; use SimpleSAML\SAML2\Exception\ProtocolViolationException; @@ -93,7 +92,7 @@ final public function __construct( ProtocolViolationException::class, ); Assert::nullOrValidURL($assertionConsumerServiceURL); - SAMLAssert::nullOrValidURI($protocolBinding); + Assert::nullOrValidURI($protocolBinding); Assert::nullOrRange($attributeConsumingServiceIndex, 0, 65535); Assert::nullOrRange($assertionConsumerServiceIndex, 0, 65535); @@ -257,7 +256,7 @@ public static function fromXML(DOMElement $xml): static // Strip sub-seconds - See paragraph 1.3.3 of SAML core specifications $issueInstant = preg_replace('/([.][0-9]+Z)$/', 'Z', $issueInstant, 1); - SAMLAssert::validDateTime($issueInstant, ProtocolViolationException::class); + Assert::validDateTime($issueInstant, ProtocolViolationException::class); $issueInstant = new DateTimeImmutable($issueInstant); $attributeConsumingServiceIndex = self::getOptionalIntegerAttribute( diff --git a/src/XML/samlp/AuthzDecisionQuery.php b/src/XML/samlp/AuthzDecisionQuery.php index 4ca5567f2..6f23b3ee6 100644 --- a/src/XML/samlp/AuthzDecisionQuery.php +++ b/src/XML/samlp/AuthzDecisionQuery.php @@ -6,8 +6,7 @@ use DateTimeImmutable; use DOMElement; -use SimpleSAML\Assert\Assert; -use SimpleSAML\SAML2\Assert\Assert as SAMLAssert; +use SimpleSAML\SAML2\Assert\Assert; use SimpleSAML\SAML2\Constants as C; use SimpleSAML\SAML2\Exception\Protocol\RequestVersionTooHighException; use SimpleSAML\SAML2\Exception\Protocol\RequestVersionTooLowException; @@ -63,7 +62,7 @@ public function __construct( ?string $consent = null, ?Extensions $extensions = null, ) { - SAMLAssert::validURI($resource); + Assert::validURI($resource); Assert::maxCount($action, C::UNBOUNDED_LIMIT); Assert::allIsInstanceOf($action, Action::class, SchemaViolationException::class); @@ -135,7 +134,7 @@ public static function fromXML(DOMElement $xml): static // Strip sub-seconds - See paragraph 1.3.3 of SAML core specifications $issueInstant = preg_replace('/([.][0-9]+Z)$/', 'Z', $issueInstant, 1); - SAMLAssert::validDateTime($issueInstant, ProtocolViolationException::class); + Assert::validDateTime($issueInstant, ProtocolViolationException::class); $issueInstant = new DateTimeImmutable($issueInstant); $issuer = Issuer::getChildrenOfClass($xml); diff --git a/src/XML/samlp/LogoutRequest.php b/src/XML/samlp/LogoutRequest.php index 665dd68fc..dbdca29a3 100644 --- a/src/XML/samlp/LogoutRequest.php +++ b/src/XML/samlp/LogoutRequest.php @@ -6,8 +6,7 @@ use DateTimeImmutable; use DOMElement; -use SimpleSAML\Assert\Assert; -use SimpleSAML\SAML2\Assert\Assert as SAMLAssert; +use SimpleSAML\SAML2\Assert\Assert; use SimpleSAML\SAML2\Constants as C; use SimpleSAML\SAML2\Exception\Protocol\RequestVersionTooHighException; use SimpleSAML\SAML2\Exception\Protocol\RequestVersionTooLowException; @@ -140,7 +139,7 @@ public static function fromXML(DOMElement $xml): static // Strip sub-seconds - See paragraph 1.3.3 of SAML core specifications $issueInstant = preg_replace('/([.][0-9]+Z)$/', 'Z', $issueInstant, 1); - SAMLAssert::validDateTime($issueInstant, ProtocolViolationException::class); + Assert::validDateTime($issueInstant, ProtocolViolationException::class); $issueInstant = new DateTimeImmutable($issueInstant); $notOnOrAfter = self::getOptionalAttribute($xml, 'NotOnOrAfter', null); @@ -148,7 +147,7 @@ public static function fromXML(DOMElement $xml): static // Strip sub-seconds - See paragraph 1.3.3 of SAML core specifications $notOnOrAfter = preg_replace('/([.][0-9]+Z)$/', 'Z', $notOnOrAfter, 1); - SAMLAssert::validDateTime($notOnOrAfter, ProtocolViolationException::class); + Assert::validDateTime($notOnOrAfter, ProtocolViolationException::class); $notOnOrAfter = new DateTimeImmutable($notOnOrAfter); } diff --git a/src/XML/samlp/LogoutResponse.php b/src/XML/samlp/LogoutResponse.php index 0f86636ea..8a5233dc2 100644 --- a/src/XML/samlp/LogoutResponse.php +++ b/src/XML/samlp/LogoutResponse.php @@ -6,8 +6,7 @@ use DateTimeImmutable; use DOMElement; -use SimpleSAML\Assert\Assert; -use SimpleSAML\SAML2\Assert\Assert as SAMLAssert; +use SimpleSAML\SAML2\Assert\Assert; use SimpleSAML\SAML2\Exception\Protocol\RequestVersionTooHighException; use SimpleSAML\SAML2\Exception\Protocol\RequestVersionTooLowException; use SimpleSAML\SAML2\Exception\ProtocolViolationException; @@ -96,7 +95,7 @@ public static function fromXML(DOMElement $xml): static // Strip sub-seconds - See paragraph 1.3.3 of SAML core specifications $issueInstant = preg_replace('/([.][0-9]+Z)$/', 'Z', $issueInstant, 1); - SAMLAssert::validDateTime($issueInstant, ProtocolViolationException::class); + Assert::validDateTime($issueInstant, ProtocolViolationException::class); $issueInstant = new DateTimeImmutable($issueInstant); $issuer = Issuer::getChildrenOfClass($xml); diff --git a/src/XML/samlp/Response.php b/src/XML/samlp/Response.php index 613a3fc40..e3f9884e8 100644 --- a/src/XML/samlp/Response.php +++ b/src/XML/samlp/Response.php @@ -6,8 +6,7 @@ use DateTimeImmutable; use DOMElement; -use SimpleSAML\Assert\Assert; -use SimpleSAML\SAML2\Assert\Assert as SAMLAssert; +use SimpleSAML\SAML2\Assert\Assert; use SimpleSAML\SAML2\Constants as C; use SimpleSAML\SAML2\Exception\Protocol\RequestVersionTooHighException; use SimpleSAML\SAML2\Exception\Protocol\RequestVersionTooLowException; @@ -124,7 +123,7 @@ public static function fromXML(DOMElement $xml): static // Strip sub-seconds - See paragraph 1.3.3 of SAML core specifications $issueInstant = preg_replace('/([.][0-9]+Z)$/', 'Z', $issueInstant, 1); - SAMLAssert::validDateTime($issueInstant, ProtocolViolationException::class); + Assert::validDateTime($issueInstant, ProtocolViolationException::class); $issueInstant = new DateTimeImmutable($issueInstant); $issuer = Issuer::getChildrenOfClass($xml); diff --git a/tests/SAML2/Assert/DateTimeTest.php b/tests/SAML2/Assert/DateTimeTest.php index 8681f1a48..d7392a468 100644 --- a/tests/SAML2/Assert/DateTimeTest.php +++ b/tests/SAML2/Assert/DateTimeTest.php @@ -7,6 +7,7 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; +use SimpleSAML\Assert\AssertionFailedException; use SimpleSAML\SAML2\Assert\Assert as SAML2Assert; use SimpleSAML\SAML2\Exception\ProtocolViolationException; use SimpleSAML\XML\Exception\SchemaViolationException; @@ -29,7 +30,7 @@ public function testValidDateTime(bool $shouldPass, string $timestamp): void try { SAML2Assert::validDateTime($timestamp); $this->assertTrue($shouldPass); - } catch (ProtocolViolationException | SchemaViolationException $e) { + } catch (AssertionFailedException | ProtocolViolationException | SchemaViolationException $e) { $this->assertFalse($shouldPass); } } diff --git a/tests/SAML2/XML/md/OrganizationURLTest.php b/tests/SAML2/XML/md/OrganizationURLTest.php index 8fd6163a1..e6decbacf 100644 --- a/tests/SAML2/XML/md/OrganizationURLTest.php +++ b/tests/SAML2/XML/md/OrganizationURLTest.php @@ -12,7 +12,6 @@ use SimpleSAML\SAML2\XML\md\AbstractMdElement; use SimpleSAML\SAML2\XML\md\OrganizationURL; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\TestUtils\ArrayizableElementTestTrait; use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; diff --git a/tests/SAML2/XML/mdrpi/RegistrationPolicyTest.php b/tests/SAML2/XML/mdrpi/RegistrationPolicyTest.php index e165f61f7..c85517674 100644 --- a/tests/SAML2/XML/mdrpi/RegistrationPolicyTest.php +++ b/tests/SAML2/XML/mdrpi/RegistrationPolicyTest.php @@ -12,7 +12,6 @@ use SimpleSAML\SAML2\XML\mdrpi\AbstractMdrpiElement; use SimpleSAML\SAML2\XML\mdrpi\RegistrationPolicy; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\TestUtils\ArrayizableElementTestTrait; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; diff --git a/tests/SAML2/XML/mdrpi/UsagePolicyTest.php b/tests/SAML2/XML/mdrpi/UsagePolicyTest.php index cf1de2a13..4e9f732bf 100644 --- a/tests/SAML2/XML/mdrpi/UsagePolicyTest.php +++ b/tests/SAML2/XML/mdrpi/UsagePolicyTest.php @@ -12,7 +12,6 @@ use SimpleSAML\SAML2\XML\mdrpi\AbstractMdrpiElement; use SimpleSAML\SAML2\XML\mdrpi\UsagePolicy; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\TestUtils\ArrayizableElementTestTrait; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; diff --git a/tests/SAML2/XML/mdui/InformationURLTest.php b/tests/SAML2/XML/mdui/InformationURLTest.php index 983389b3b..bca032371 100644 --- a/tests/SAML2/XML/mdui/InformationURLTest.php +++ b/tests/SAML2/XML/mdui/InformationURLTest.php @@ -12,7 +12,6 @@ use SimpleSAML\SAML2\XML\md\AbstractMdElement; use SimpleSAML\SAML2\XML\mdui\InformationURL; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\TestUtils\ArrayizableElementTestTrait; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; diff --git a/tests/SAML2/XML/mdui/PrivacyStatementURLTest.php b/tests/SAML2/XML/mdui/PrivacyStatementURLTest.php index 0d60de249..4ecde7714 100644 --- a/tests/SAML2/XML/mdui/PrivacyStatementURLTest.php +++ b/tests/SAML2/XML/mdui/PrivacyStatementURLTest.php @@ -12,7 +12,6 @@ use SimpleSAML\SAML2\XML\md\AbstractMdElement; use SimpleSAML\SAML2\XML\mdui\PrivacyStatementURL; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\TestUtils\ArrayizableElementTestTrait; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;