Skip to content

Commit 93c0e0b

Browse files
committed
Fix theoretical issue with unconnected defaultIdp and the banner not showing on the functional-testing route.
1 parent daef5e4 commit 93c0e0b

3 files changed

Lines changed: 56 additions & 3 deletions

File tree

src/OpenConext/EngineBlockBundle/Service/WayfRenderer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public function render(
5353
): string {
5454
$split = $this->splitter->split($idpList, $preferredIdpEntityIds);
5555
$showPreferredIdps = !empty($split['preferred']);
56-
$isDefaultIdpPreferred = in_array($defaultIdpEntityId, $preferredIdpEntityIds, true);
56+
$preferredEntityIdsShown = array_map(static fn(WayfIdp $idp) => $idp->entityId, $split['preferred']);
57+
$isDefaultIdpPreferred = in_array($defaultIdpEntityId, $preferredEntityIdsShown, true);
5758

5859
$showIdPBanner = $shouldDisplayBanner
5960
&& $this->isDefaultIdpPresent($idpList)

src/OpenConext/EngineBlockFunctionalTestingBundle/Helper/TestEntitySeeder.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,13 @@ private static function transformIdpsForWayf(array $idpEntityIds, $currentLocale
198198

199199
$wayfIdps = [];
200200
foreach ($identityProviders as $identityProvider) {
201+
$isDefaultIdp = $idpEntityIds[$identityProvider->entityId]['isDefaultIdp'];
202+
203+
// Mirror the production guard: do not show the default IdP in the disconnected section.
204+
if (!$identityProvider->enabledInWayf && $isDefaultIdp) {
205+
continue;
206+
}
207+
201208
$name = 'name' . ucfirst($currentLocale);
202209
$wayfIdps[] = new WayfIdp(
203210
name: $identityProvider->$name,
@@ -206,7 +213,7 @@ private static function transformIdpsForWayf(array $idpEntityIds, $currentLocale
206213
accessible: $identityProvider->enabledInWayf,
207214
id: md5($identityProvider->entityId),
208215
entityId: $identityProvider->entityId,
209-
isDefaultIdp: $idpEntityIds[$identityProvider->entityId]['isDefaultIdp'],
216+
isDefaultIdp: $isDefaultIdp,
210217
discoveryHash: null,
211218
);
212219

@@ -218,7 +225,7 @@ private static function transformIdpsForWayf(array $idpEntityIds, $currentLocale
218225
accessible: $identityProvider->enabledInWayf,
219226
id: md5($identityProvider->entityId),
220227
entityId: $identityProvider->entityId,
221-
isDefaultIdp: $idpEntityIds[$identityProvider->entityId]['isDefaultIdp'],
228+
isDefaultIdp: $isDefaultIdp,
222229
discoveryHash: $discoveryService->hash($discovery),
223230
);
224231
}

tests/unit/OpenConext/EngineBlockBundle/Service/WayfRendererTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,51 @@ public static function bannerConditionProvider(): array
137137
];
138138
}
139139

140+
public function testBannerShownWhenDefaultIdpIsInPreferredConfigButDroppedBySpitter(): void
141+
{
142+
$defaultId = 'https://default.example.org';
143+
$otherId = 'https://other.example.org';
144+
145+
// Default IdP is unconnected (splitter will drop it); other preferred IdP is connected.
146+
$idpList = [
147+
new WayfIdp(name: null, logo: '', keywords: [], accessible: false, id: md5($defaultId), entityId: $defaultId, isDefaultIdp: true, discoveryHash: null),
148+
new WayfIdp(name: null, logo: '', keywords: [], accessible: true, id: md5($otherId), entityId: $otherId, isDefaultIdp: false, discoveryHash: null),
149+
];
150+
151+
$capturedShowIdPBanner = null;
152+
153+
$this->factory->expects($this->once())
154+
->method('create')
155+
->willReturnCallback(function () use (&$capturedShowIdPBanner): WayfViewModel {
156+
$namedArgs = func_get_args();
157+
$capturedShowIdPBanner = $namedArgs[9];
158+
return $this->buildViewModel($namedArgs[9]);
159+
});
160+
161+
$this->twig->method('render')->willReturn('<html>');
162+
163+
$sp = $this->createStub(ServiceProvider::class);
164+
$sp->method('getDisplayName')->willReturn('Test SP');
165+
166+
$this->renderer()->render(
167+
idpList: $idpList,
168+
preferredIdpEntityIds: [$defaultId, $otherId],
169+
action: '/sso',
170+
currentLocale: 'en',
171+
defaultIdpEntityId: $defaultId,
172+
shouldDisplayBanner: true,
173+
backLink: false,
174+
cutoffPoint: 100,
175+
rememberChoice: false,
176+
showRequestAccess: false,
177+
requestId: 'req-1',
178+
serviceProvider: $sp,
179+
);
180+
181+
$this->assertTrue($capturedShowIdPBanner, 'Banner should show: default IdP was in preferred config but dropped by splitter, so it is not visible anywhere');
182+
}
183+
184+
140185
public function testSplitsIdpListBeforePassingToFactory(): void
141186
{
142187
$preferredId = 'https://preferred.example.org';

0 commit comments

Comments
 (0)