Skip to content

Commit 7a0f6d9

Browse files
committed
Enable validating TMs using TMS endpoint
1 parent 36a3b95 commit 7a0f6d9

1 file changed

Lines changed: 90 additions & 0 deletions

File tree

tests/src/Federation/TrustMarkValidatorTest.php

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
use SimpleSAML\OpenID\Codebooks\TrustMarkStatusEnum;
1414
use SimpleSAML\OpenID\Decorators\CacheDecorator;
1515
use SimpleSAML\OpenID\Decorators\DateIntervalDecorator;
16+
use SimpleSAML\OpenID\Exceptions\FetchException;
1617
use SimpleSAML\OpenID\Exceptions\TrustMarkException;
18+
use SimpleSAML\OpenID\Exceptions\TrustMarkStatusException;
1719
use SimpleSAML\OpenID\Federation\Claims\TrustMarkIssuersClaimBag;
1820
use SimpleSAML\OpenID\Federation\Claims\TrustMarkIssuersClaimValue;
1921
use SimpleSAML\OpenID\Federation\Claims\TrustMarkOwnersClaimBag;
@@ -70,6 +72,8 @@ final class TrustMarkValidatorTest extends TestCase
7072

7173
protected MockObject $trustMarkStatusMock;
7274

75+
protected MockObject $trustMarkIssuerConfigurationMock;
76+
7377

7478
protected function setUp(): void
7579
{
@@ -100,6 +104,9 @@ protected function setUp(): void
100104
$this->trustMarkIssuersClaimValueMock = $this->createMock(TrustMarkIssuersClaimValue::class);
101105

102106
$this->trustMarkStatusMock = $this->createMock(TrustMarkStatus::class);
107+
108+
$this->trustMarkIssuerConfigurationMock = $this->createMock(EntityStatement::class);
109+
$this->trustMarkIssuerConfigurationMock->method('getIssuer')->willReturn('trustMarkIssuerId');
103110
}
104111

105112

@@ -950,4 +957,87 @@ public function testShouldUseTrustMarkStatusForNonExpiringWhenEndpointIsAvailabl
950957
),
951958
);
952959
}
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+
}
9531043
}

0 commit comments

Comments
 (0)