2626use Surfnet \StepupGateway \GatewayBundle \Entity \InstitutionConfiguration ;
2727use Surfnet \StepupGateway \GatewayBundle \Entity \InstitutionConfigurationRepository ;
2828use Surfnet \StepupGateway \GatewayBundle \Entity \SecondFactorRepository ;
29+ use Surfnet \StepupGateway \GatewayBundle \Exception \InstitutionConfigurationNotFoundException ;
2930use Surfnet \StepupGateway \GatewayBundle \Saml \Proxy \ProxyStateHandler ;
3031use Surfnet \StepupGateway \GatewayBundle \Service \WhitelistService ;
3132use Surfnet \StepupGateway \GatewayBundle \Tests \TestCase \GatewaySamlTestCase ;
@@ -299,4 +300,53 @@ public function it_can_create_a_gssp_fallback_token(): void
299300 $ this ->assertSame ($ locale , $ token ->getDisplayLocale ());
300301 }
301302
303+ /**
304+ * @test
305+ */
306+ public function it_treats_missing_institution_configuration_as_default (): void
307+ {
308+ $ subject = 'urn:collab:person:dev.openconext.local:john_haack ' ;
309+ $ gsspSubject = 'john_haack@dev.openconext.local ' ;
310+ $ gsspInstitution = 'dev.openconext.local ' ;
311+ $ locale = 'en_GB ' ;
312+ $ preferredLoa = 1.5 ;
313+ $ authenticationMode = SecondFactorController::MODE_SFO ;
314+
315+ $ this ->stateHandler ->shouldReceive ('getGsspUserAttributeSubject ' )
316+ ->once ()
317+ ->andReturn ($ gsspSubject );
318+
319+ $ this ->stateHandler ->shouldReceive ('getGsspUserAttributeInstitution ' )
320+ ->once ()
321+ ->andReturn ($ gsspInstitution );
322+
323+ $ this ->institutionConfiguration ->shouldReceive ('getInstitutionConfiguration ' )
324+ ->with ($ gsspInstitution )
325+ ->andThrow (new InstitutionConfigurationNotFoundException ());
326+
327+ $ whitelistService = m::mock (WhitelistService::class);
328+ $ whitelistService ->shouldReceive ('contains ' )
329+ ->once ()
330+ ->with ($ gsspInstitution )
331+ ->andReturn (true );
332+
333+ // When institution configuration is not found, it means default config
334+ // So the fallback should not be started
335+ $ this ->stateHandler ->shouldReceive ('setSecondFactorIsFallback ' )
336+ ->with (false )
337+ ->once ();
338+
339+ $ this ->stateHandler ->shouldNotReceive ('setPreferredLocale ' );
340+
341+ $ result = $ this ->service ->determineGsspFallbackNeeded (
342+ $ subject ,
343+ $ authenticationMode ,
344+ new Loa ($ preferredLoa , 'example.org:loa-level ' ),
345+ $ whitelistService ,
346+ $ this ->logger ,
347+ $ locale ,
348+ );
349+
350+ $ this ->assertFalse ($ result );
351+ }
302352}
0 commit comments