|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\SAML11\Assert; |
|
6
|
|
|
|
|
7
|
|
|
use SimpleSAML\Assert\Assert as BaseAssert; |
|
8
|
|
|
use SimpleSAML\Assert\AssertionFailedException; |
|
9
|
|
|
use SimpleSAML\SAML11\Constants as C; |
|
10
|
|
|
use SimpleSAML\SAML11\Exception\ProtocolViolationException; |
|
11
|
|
|
use SimpleSAML\XML\Exception\SchemaViolationException; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @package simplesamlphp/assert |
|
15
|
|
|
*/ |
|
16
|
|
|
trait CustomAssertionTrait |
|
17
|
|
|
{ |
|
18
|
|
|
private static string $scheme_regex = '/^([a-z][a-z0-9\+\-\.]+[:])/i'; |
|
19
|
|
|
|
|
20
|
|
|
/*********************************************************************************** |
|
21
|
|
|
* NOTE: Custom assertions may be added below this line. * |
|
22
|
|
|
* They SHOULD be marked as `private` to ensure the call is forced * |
|
23
|
|
|
* through __callStatic(). * |
|
24
|
|
|
* Assertions marked `public` are called directly and will * |
|
25
|
|
|
* not handle any custom exception passed to it. * |
|
26
|
|
|
***********************************************************************************/ |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param string $value |
|
31
|
|
|
* @param string $message |
|
32
|
|
|
*/ |
|
33
|
|
|
private static function validDateTime(string $value, string $message = ''): void |
|
|
|
|
|
|
34
|
|
|
{ |
|
35
|
|
|
try { |
|
36
|
|
|
BaseAssert::validDateTime($value); |
|
37
|
|
|
} catch (AssertionFailedException $e) { |
|
38
|
|
|
throw new SchemaViolationException($e->getMessage()); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
try { |
|
42
|
|
|
BaseAssert::endsWith( |
|
43
|
|
|
$value, |
|
44
|
|
|
'Z', |
|
45
|
|
|
'%s is not a DateTime expressed in the UTC timezone using the \'Z\' timezone identifier.', |
|
46
|
|
|
); |
|
47
|
|
|
} catch (AssertionFailedException $e) { |
|
48
|
|
|
throw new ProtocolViolationException($e->getMessage()); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param string $value |
|
55
|
|
|
* @param string $message |
|
56
|
|
|
*/ |
|
57
|
|
|
private static function validURI(string $value, string $message = ''): void |
|
58
|
|
|
{ |
|
59
|
|
|
try { |
|
60
|
|
|
BaseAssert::validURI($value); |
|
61
|
|
|
} catch (AssertionFailedException $e) { |
|
62
|
|
|
throw new SchemaViolationException($e->getMessage()); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
try { |
|
66
|
|
|
BaseAssert::notWhitespaceOnly($value, $message ?: '%s is not a SAML1.1-compliant URI'); |
|
67
|
|
|
|
|
68
|
|
|
// If it doesn't have a scheme, it's not an absolute URI |
|
69
|
|
|
BaseAssert::regex($value, self::$scheme_regex, $message ?: '%s is not a SAML1.1-compliant URI'); |
|
70
|
|
|
} catch (AssertionFailedException $e) { |
|
71
|
|
|
throw new ProtocolViolationException($e->getMessage()); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param string $value |
|
78
|
|
|
* @param string $message |
|
79
|
|
|
*/ |
|
80
|
|
|
private static function validEntityID(string $value, string $message = ''): void |
|
|
|
|
|
|
81
|
|
|
{ |
|
82
|
|
|
static::validURI($value); |
|
83
|
|
|
|
|
84
|
|
|
try { |
|
85
|
|
|
BaseAssert::maxLength( |
|
86
|
|
|
$value, |
|
87
|
|
|
C::ENTITYID_MAX_LENGTH, |
|
|
|
|
|
|
88
|
|
|
sprintf('An entityID cannot be longer than %d characters.', C::ENTITYID_MAX_LENGTH), |
|
89
|
|
|
); |
|
90
|
|
|
} catch (AssertionFailedException $e) { |
|
91
|
|
|
throw new ProtocolViolationException($e->getMessage()); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.