@@ -114,14 +114,26 @@ public function testValidateClaimsSuccess(): void
114114 $ claims ->name = 'Test Tester ' ;
115115 $ stubProvider ->method ('validateIdToken ' )->willReturn ($ claims );
116116
117- $ this ->stubProviderManager ->method ('getProvider ' )->willReturn ($ stubProvider );
117+ // Expect the exact provider key from the session, so a lookup with a
118+ // mangled key fails the test instead of silently matching any key.
119+ $ mockProviderManager = $ this ->createMock (OpenIdConfigurationProviderManager::class);
120+ $ mockProviderManager ->expects ($ this ->once ())
121+ ->method ('getProvider ' )
122+ ->with ('test_provider_1 ' )
123+ ->willReturn ($ stubProvider );
124+ $ authenticator = new TestAuthenticator ($ mockProviderManager );
118125
119126 $ request = new Request (query: ['state ' => 'test_state ' , 'code ' => 'test_code ' ]);
120127 $ this ->setSessionOnRequest ($ request );
121128
122- $ passport = $ this -> authenticator ->authenticate ($ request );
129+ $ passport = $ authenticator ->authenticate ($ request );
123130
124131 $ this ->assertSame ('test@test.com ' , $ passport ->getUser ()->getUserIdentifier ());
132+
133+ // The claims contract: the IdP claims plus the provider key that
134+ // authenticated the user.
135+ $ this ->assertSame ('Test Tester ' , $ authenticator ->lastClaims ['name ' ] ?? null );
136+ $ this ->assertSame ('test_provider_1 ' , $ authenticator ->lastClaims ['open_id_connect_provider ' ] ?? null );
125137 }
126138
127139 private function setSessionOnRequest (Request $ request , ?string $ nonce = 'test_nonce ' ): void
0 commit comments