|
13 | 13 | use SimpleSAML\OpenID\Codebooks\TrustMarkStatusEnum; |
14 | 14 | use SimpleSAML\OpenID\Decorators\CacheDecorator; |
15 | 15 | use SimpleSAML\OpenID\Decorators\DateIntervalDecorator; |
| 16 | +use SimpleSAML\OpenID\Exceptions\FetchException; |
16 | 17 | use SimpleSAML\OpenID\Exceptions\TrustMarkException; |
| 18 | +use SimpleSAML\OpenID\Exceptions\TrustMarkStatusException; |
17 | 19 | use SimpleSAML\OpenID\Federation\Claims\TrustMarkIssuersClaimBag; |
18 | 20 | use SimpleSAML\OpenID\Federation\Claims\TrustMarkIssuersClaimValue; |
19 | 21 | use SimpleSAML\OpenID\Federation\Claims\TrustMarkOwnersClaimBag; |
@@ -70,6 +72,8 @@ final class TrustMarkValidatorTest extends TestCase |
70 | 72 |
|
71 | 73 | protected MockObject $trustMarkStatusMock; |
72 | 74 |
|
| 75 | + protected MockObject $trustMarkIssuerConfigurationMock; |
| 76 | + |
73 | 77 |
|
74 | 78 | protected function setUp(): void |
75 | 79 | { |
@@ -100,6 +104,9 @@ protected function setUp(): void |
100 | 104 | $this->trustMarkIssuersClaimValueMock = $this->createMock(TrustMarkIssuersClaimValue::class); |
101 | 105 |
|
102 | 106 | $this->trustMarkStatusMock = $this->createMock(TrustMarkStatus::class); |
| 107 | + |
| 108 | + $this->trustMarkIssuerConfigurationMock = $this->createMock(EntityStatement::class); |
| 109 | + $this->trustMarkIssuerConfigurationMock->method('getIssuer')->willReturn('trustMarkIssuerId'); |
103 | 110 | } |
104 | 111 |
|
105 | 112 |
|
@@ -950,4 +957,87 @@ public function testShouldUseTrustMarkStatusForNonExpiringWhenEndpointIsAvailabl |
950 | 957 | ), |
951 | 958 | ); |
952 | 959 | } |
| 960 | + |
| 961 | + |
| 962 | + public function testValidateUsingTrustMarkStatusEndpointThrowsOnFetchError(): void |
| 963 | + { |
| 964 | + $this->trustMarkStatusFetcherMock->method('fromFederationTrustMarkStatusEndpoint') |
| 965 | + ->willThrowException(new FetchException('error')); |
| 966 | + |
| 967 | + $this->expectException(TrustMarkException::class); |
| 968 | + $this->expectExceptionMessage('Error fetching Trust Mark Status'); |
| 969 | + |
| 970 | + $this->sut()->validateUsingTrustMarkStatusEndpoint( |
| 971 | + $this->trustMarkMock, |
| 972 | + $this->trustMarkIssuerConfigurationMock, |
| 973 | + ); |
| 974 | + } |
| 975 | + |
| 976 | + |
| 977 | + public function testValidateUsingTrustMarkStatusEndpointThrowsOnInvalidTrustMarkStatus(): void |
| 978 | + { |
| 979 | + $this->trustMarkStatusFetcherMock->method('fromFederationTrustMarkStatusEndpoint') |
| 980 | + ->willReturn($this->trustMarkStatusMock); |
| 981 | + $this->trustMarkStatusMock->method('getStatus') |
| 982 | + ->willReturn('invalid'); // From the spec |
| 983 | + |
| 984 | + $this->expectException(TrustMarkStatusException::class); |
| 985 | + $this->expectExceptionMessage('not valid'); |
| 986 | + |
| 987 | + $this->sut()->validateUsingTrustMarkStatusEndpoint( |
| 988 | + $this->trustMarkMock, |
| 989 | + $this->trustMarkIssuerConfigurationMock, |
| 990 | + ); |
| 991 | + } |
| 992 | + |
| 993 | + |
| 994 | + public function testValidateUsingTrustMarkStatusThrowsOnCustomStatus(): void |
| 995 | + { |
| 996 | + $this->trustMarkStatusFetcherMock->method('fromFederationTrustMarkStatusEndpoint') |
| 997 | + ->willReturn($this->trustMarkStatusMock); |
| 998 | + $this->trustMarkStatusMock->method('getStatus') |
| 999 | + ->willReturn('custom-status'); // Not from the spec |
| 1000 | + |
| 1001 | + $this->expectException(TrustMarkStatusException::class); |
| 1002 | + $this->expectExceptionMessage('not valid'); |
| 1003 | + |
| 1004 | + $this->sut()->validateUsingTrustMarkStatusEndpoint( |
| 1005 | + $this->trustMarkMock, |
| 1006 | + $this->trustMarkIssuerConfigurationMock, |
| 1007 | + ); |
| 1008 | + } |
| 1009 | + |
| 1010 | + |
| 1011 | + public function testValidateUsingTrustMarkStatusPassesOnCustomValidTrustMarkStatus(): void |
| 1012 | + { |
| 1013 | + $this->trustMarkStatusFetcherMock->method('fromFederationTrustMarkStatusEndpoint') |
| 1014 | + ->willReturn($this->trustMarkStatusMock); |
| 1015 | + $this->trustMarkStatusMock->expects($this->atLeastOnce()) |
| 1016 | + ->method('getStatus') |
| 1017 | + ->willReturn('custom-status'); // Not from the spec |
| 1018 | + |
| 1019 | + $this->sut()->validateUsingTrustMarkStatusEndpoint( |
| 1020 | + $this->trustMarkMock, |
| 1021 | + $this->trustMarkIssuerConfigurationMock, |
| 1022 | + ['custom-status'], |
| 1023 | + ); |
| 1024 | + } |
| 1025 | + |
| 1026 | + |
| 1027 | + public function testValidateUsingTrustMarkStatusThrowsOnInvalidCustomStatus(): void |
| 1028 | + { |
| 1029 | + $this->trustMarkStatusFetcherMock->method('fromFederationTrustMarkStatusEndpoint') |
| 1030 | + ->willReturn($this->trustMarkStatusMock); |
| 1031 | + $this->trustMarkStatusMock->method('getStatus') |
| 1032 | + ->willReturn('invalid-custom-status'); // Not from the spec |
| 1033 | + |
| 1034 | + $this->expectException(TrustMarkStatusException::class); |
| 1035 | + $this->expectExceptionMessage('not valid'); |
| 1036 | + |
| 1037 | + $this->sut()->validateUsingTrustMarkStatusEndpoint( |
| 1038 | + $this->trustMarkMock, |
| 1039 | + $this->trustMarkIssuerConfigurationMock, |
| 1040 | + ['custom-status'], |
| 1041 | + ); |
| 1042 | + } |
953 | 1043 | } |
0 commit comments