@@ -176,6 +176,28 @@ public function testAuthorizeWrongResponseType(): void {
176176 $ this ->assertEquals ($ expected , $ this ->loginRedirectorController ->authorize ('MyClientId ' , 'MyState ' , 'wrongcode ' ));
177177 }
178178
179+ public function testAuthorizeWrongResponseTypePreservesExistingQuery (): void {
180+ $ client = new Client ();
181+ $ client ->setClientIdentifier ('MyClientIdentifier ' );
182+ $ client ->setRedirectUri ('http://foo.bar?hello=world ' );
183+ $ this ->clientMapper
184+ ->expects ($ this ->once ())
185+ ->method ('getByIdentifier ' )
186+ ->with ('MyClientId ' )
187+ ->willReturn ($ client );
188+ $ this ->session
189+ ->expects ($ this ->never ())
190+ ->method ('set ' );
191+ $ this ->config
192+ ->expects ($ this ->once ())
193+ ->method ('getSystemValueBool ' )
194+ ->with ('oauth2.enable_oc_clients ' , false )
195+ ->willReturn (false );
196+
197+ $ expected = new RedirectResponse ('http://foo.bar?hello=world&error=unsupported_response_type&state=MyState ' );
198+ $ this ->assertEquals ($ expected , $ this ->loginRedirectorController ->authorize ('MyClientId ' , 'MyState ' , 'wrongcode ' ));
199+ }
200+
179201 public function testAuthorizeRejectsCodeChallengeMethodWithoutChallenge (): void {
180202 $ client = new Client ();
181203 $ client ->setClientIdentifier ('MyClientIdentifier ' );
@@ -207,10 +229,38 @@ public function testAuthorizeRejectsPkceWithoutMethodBecausePlainIsUnsupported()
207229 ->method ('set ' );
208230
209231 $ codeChallenge = str_repeat ('a ' , 43 );
232+ $ this ->config
233+ ->expects ($ this ->once ())
234+ ->method ('getSystemValueBool ' )
235+ ->with ('oauth2.enable_oc_clients ' , false )
236+ ->willReturn (false );
210237 $ expected = new RedirectResponse ('http://foo.bar?error=invalid_request&error_description=Transform+algorithm+not+supported&state=MyState ' );
211238 $ this ->assertEquals ($ expected , $ this ->loginRedirectorController ->authorize ('MyClientId ' , 'MyState ' , 'code ' , '' , $ codeChallenge ));
212239 }
213240
241+ public function testAuthorizeRejectsPkceWithoutMethodForLegacyOcClientUsingProvidedRedirectUri (): void {
242+ $ client = new Client ();
243+ $ client ->setClientIdentifier ('MyClientIdentifier ' );
244+ $ client ->setRedirectUri ('http://localhost:* ' );
245+ $ this ->clientMapper
246+ ->expects ($ this ->once ())
247+ ->method ('getByIdentifier ' )
248+ ->with ('MyClientId ' )
249+ ->willReturn ($ client );
250+ $ this ->session
251+ ->expects ($ this ->never ())
252+ ->method ('set ' );
253+ $ this ->config
254+ ->expects ($ this ->once ())
255+ ->method ('getSystemValueBool ' )
256+ ->with ('oauth2.enable_oc_clients ' , false )
257+ ->willReturn (true );
258+
259+ $ codeChallenge = str_repeat ('a ' , 43 );
260+ $ expected = new RedirectResponse ('http://localhost:30000?error=invalid_request&error_description=Transform+algorithm+not+supported&state=MyState ' );
261+ $ this ->assertEquals ($ expected , $ this ->loginRedirectorController ->authorize ('MyClientId ' , 'MyState ' , 'code ' , 'http://localhost:30000 ' , $ codeChallenge ));
262+ }
263+
214264 public function testAuthorizeRejectsUnsupportedCodeChallengeMethod (): void {
215265 $ client = new Client ();
216266 $ client ->setClientIdentifier ('MyClientIdentifier ' );
@@ -225,6 +275,11 @@ public function testAuthorizeRejectsUnsupportedCodeChallengeMethod(): void {
225275 ->method ('set ' );
226276
227277 $ codeChallenge = str_repeat ('a ' , 43 );
278+ $ this ->config
279+ ->expects ($ this ->once ())
280+ ->method ('getSystemValueBool ' )
281+ ->with ('oauth2.enable_oc_clients ' , false )
282+ ->willReturn (false );
228283 $ expected = new RedirectResponse ('http://foo.bar?error=invalid_request&error_description=Transform+algorithm+not+supported&state=MyState ' );
229284 $ this ->assertEquals ($ expected , $ this ->loginRedirectorController ->authorize ('MyClientId ' , 'MyState ' , 'code ' , '' , $ codeChallenge , 'plain ' ));
230285 }
@@ -241,6 +296,11 @@ public function testAuthorizeRejectsInvalidCodeChallengeFormat(): void {
241296 $ this ->session
242297 ->expects ($ this ->never ())
243298 ->method ('set ' );
299+ $ this ->config
300+ ->expects ($ this ->once ())
301+ ->method ('getSystemValueBool ' )
302+ ->with ('oauth2.enable_oc_clients ' , false )
303+ ->willReturn (false );
244304
245305 $ expected = new RedirectResponse ('http://foo.bar?error=invalid_request&error_description=Invalid+code_challenge&state=MyState ' );
246306 $ this ->assertEquals ($ expected , $ this ->loginRedirectorController ->authorize ('MyClientId ' , 'MyState ' , 'code ' , '' , 'short ' , 'S256 ' ));
0 commit comments