Skip to content

Commit 1e1759e

Browse files
committed
Add coverage
1 parent 5ab7708 commit 1e1759e

File tree

4 files changed

+111
-5
lines changed

4 files changed

+111
-5
lines changed

config/module_oidc.php.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ $config = [
379379
// and value is Trust Mark Issuer ID, each representing a Trust Mark issued to this entity. Each Trust Mark ID
380380
// in this array will be dynamically fetched from noted Trust Mark Issuer as necessary. If federation caching
381381
// is enabled (recommended), fetched Trust Marks will also be cached until their expiry.
382-
ModuleConfig::OPTION_FEDERATION_DYNAMIC_TRUST_MARK_TOKENS => [
382+
ModuleConfig::OPTION_FEDERATION_DYNAMIC_TRUST_MARKS => [
383383
// 'trust-mark-id' => 'trust-mark-issuer-id',
384384
],
385385

src/ModuleConfig.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class ModuleConfig
7676
final public const OPTION_FEDERATION_CACHE_MAX_DURATION_FOR_FETCHED = 'federation_cache_max_duration_for_fetched';
7777
final public const OPTION_FEDERATION_TRUST_ANCHORS = 'federation_trust_anchors';
7878
final public const OPTION_FEDERATION_TRUST_MARK_TOKENS = 'federation_trust_mark_tokens';
79-
final public const OPTION_FEDERATION_DYNAMIC_TRUST_MARK_TOKENS = 'federation_dynamic_trust_mark_tokens';
79+
final public const OPTION_FEDERATION_DYNAMIC_TRUST_MARKS = 'federation_dynamic_trust_mark_tokens';
8080
final public const OPTION_FEDERATION_CACHE_DURATION_FOR_PRODUCED = 'federation_cache_duration_for_produced';
8181
final public const OPTION_PROTOCOL_CACHE_ADAPTER = 'protocol_cache_adapter';
8282
final public const OPTION_PROTOCOL_CACHE_ADAPTER_ARGUMENTS = 'protocol_cache_adapter_arguments';
@@ -636,7 +636,7 @@ public function getFederationTrustMarkTokens(): ?array
636636
public function getFederationDynamicTrustMarks(): ?array
637637
{
638638
$dynamicTrustMarks = $this->config()->getOptionalArray(
639-
self::OPTION_FEDERATION_DYNAMIC_TRUST_MARK_TOKENS,
639+
self::OPTION_FEDERATION_DYNAMIC_TRUST_MARKS,
640640
null,
641641
);
642642

tests/unit/src/Controllers/Admin/ConfigControllerTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class ConfigControllerTest extends TestCase
2828
protected MockObject $federationMock;
2929
protected MockObject $routesMock;
3030
protected MockObject $trustMarkFactoryMock;
31+
protected MockObject $entityStatementFetcherMock;
32+
protected MockObject $trustMarkFetcherMock;
3133

3234
protected function setUp(): void
3335
{
@@ -41,6 +43,12 @@ protected function setUp(): void
4143

4244
$this->trustMarkFactoryMock = $this->createMock(TrustMarkFactory::class);
4345
$this->federationMock->method('trustMarkFactory')->willReturn($this->trustMarkFactoryMock);
46+
47+
$this->entityStatementFetcherMock = $this->createMock(Federation\EntityStatementFetcher::class);
48+
$this->federationMock->method('entityStatementFetcher')->willReturn($this->entityStatementFetcherMock);
49+
50+
$this->trustMarkFetcherMock = $this->createMock(Federation\TrustMarkFetcher::class);
51+
$this->federationMock->method('trustMarkFetcher')->willReturn($this->trustMarkFetcherMock);
4452
}
4553

4654
public function sut(
@@ -129,4 +137,25 @@ public function testCanIncludeTrustMarksInFederationSettings(): void
129137

130138
$this->sut()->federationSettings();
131139
}
140+
141+
public function testCanIncludeDynamicTrustMarksInFederationSettings(): void
142+
{
143+
$this->moduleConfigMock->method('getIssuer')->willReturn('issuer-id');
144+
$this->moduleConfigMock->method('getFederationDynamicTrustMarks')
145+
->willReturn(['trust-mark-id' => 'trust-mark-issuer-id']);
146+
147+
$this->entityStatementFetcherMock->expects($this->once())->method('fromCacheOrWellKnownEndpoint')
148+
->with('trust-mark-issuer-id');
149+
150+
$this->trustMarkFetcherMock->expects($this->once())->method('fromCacheOrFederationTrustMarkEndpoint')
151+
->with(
152+
'trust-mark-id',
153+
'issuer-id',
154+
);
155+
156+
$this->templateFactoryMock->expects($this->once())->method('build')
157+
->with('oidc:config/federation.twig');
158+
159+
$this->sut()->federationSettings();
160+
}
132161
}

tests/unit/src/ModuleConfigTest.php

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,86 @@ public function testCanGetProtocolDiscoveryShowClaimsSupported(): void
378378
$this->assertFalse($this->sut()->getProtocolDiscoveryShowClaimsSupported());
379379
$this->assertTrue(
380380
$this->sut(
381-
null,
382-
[ModuleConfig::OPTION_PROTOCOL_DISCOVERY_SHOW_CLAIMS_SUPPORTED => true],
381+
overrides: [ModuleConfig::OPTION_PROTOCOL_DISCOVERY_SHOW_CLAIMS_SUPPORTED => true],
383382
)->getProtocolDiscoveryShowClaimsSupported(),
384383
);
385384
}
385+
386+
public function testCanGetProtocolNewCertPath(): void
387+
{
388+
$this->assertNull($this->sut()->getProtocolNewCertPath());
389+
390+
$sut = $this->sut(
391+
overrides: [ModuleConfig::OPTION_PKI_NEW_CERTIFICATE_FILENAME => 'new-cert'],
392+
);
393+
394+
$this->assertStringContainsString('new-cert', $sut->getProtocolNewCertPath());
395+
}
396+
397+
public function testCanGetFederationNewCertPath(): void
398+
{
399+
$this->assertNull($this->sut()->getFederationNewCertPath());
400+
401+
$sut = $this->sut(
402+
overrides: [ModuleConfig::OPTION_PKI_FEDERATION_NEW_CERTIFICATE_FILENAME => 'new-cert'],
403+
);
404+
405+
$this->assertStringContainsString('new-cert', $sut->getFederationNewCertPath());
406+
}
407+
408+
public function testCanGetFederationDynamicTrustMarks(): void
409+
{
410+
$this->assertNull($this->sut()->getFederationDynamicTrustMarks());
411+
412+
$sut = $this->sut(
413+
overrides: [
414+
ModuleConfig::OPTION_FEDERATION_DYNAMIC_TRUST_MARKS => [
415+
'trust-mark-id' => 'trust-mark-issuer-id',
416+
],
417+
],
418+
);
419+
420+
$this->assertArrayHasKey(
421+
'trust-mark-id',
422+
$sut->getFederationDynamicTrustMarks(),
423+
);
424+
}
425+
426+
public function testCanGetFederationParticipationLimitByTrustMarks(): void
427+
{
428+
$this->assertArrayHasKey(
429+
'https://ta.example.org/',
430+
$this->sut()->getFederationParticipationLimitByTrustMarks(),
431+
);
432+
}
433+
434+
public function testCanGetTrustMarksNeededForFederationParticipationFor(): void
435+
{
436+
$neededTrustMarks = $this->sut()->getTrustMarksNeededForFederationParticipationFor('https://ta.example.org/');
437+
438+
$this->assertArrayHasKey('one_of', $neededTrustMarks);
439+
$this->assertTrue(in_array('trust-mark-id', $neededTrustMarks['one_of']));
440+
}
441+
442+
public function testGetTrustMarksNeededForFederationParticipationForThrowsOnInvalidConfigValue(): void
443+
{
444+
$sut = $this->sut(
445+
overrides: [
446+
ModuleConfig::OPTION_FEDERATION_PARTICIPATION_LIMIT_BY_TRUST_MARKS => [
447+
'https://ta.example.org/' => 'invalid',
448+
],
449+
],
450+
);
451+
452+
$this->expectException(ConfigurationError::class);
453+
454+
$sut->getTrustMarksNeededForFederationParticipationFor('https://ta.example.org/');
455+
}
456+
457+
public function testCanGetIsFederationParticipationLimitedByTrustMarksFor(): void
458+
{
459+
$this->assertTrue(
460+
$this->sut()->isFederationParticipationLimitedByTrustMarksFor('https://ta.example.org/'),
461+
);
462+
}
386463
}

0 commit comments

Comments
 (0)