2121use SimpleSAML \Module \oidc \Services \AuthenticationService ;
2222use SimpleSAML \Module \oidc \Services \ErrorResponder ;
2323use SimpleSAML \Module \oidc \Services \LoggerService ;
24+ use Symfony \Bridge \PsrHttpMessage \Factory \HttpFoundationFactory ;
25+ use Symfony \Component \HttpFoundation \Request ;
26+ use Symfony \Component \HttpFoundation \ResponseHeaderBag ;
2427
2528/**
2629 * @covers \SimpleSAML\Module\oidc\Controllers\AuthorizationController
@@ -57,6 +60,11 @@ class AuthorizationControllerTest extends TestCase
5760
5861 protected static array $ sampleRequestedAcrs = ['values ' => ['1 ' , '0 ' ], 'essential ' => false ];
5962
63+ protected MockObject $ symfonyRequestMock ;
64+ protected MockObject $ symfonyResponseMock ;
65+ protected MockObject $ responseHeaderBagMock ;
66+ protected MockObject $ httpFoundationFactoryMock ;
67+
6068 /**
6169 * @throws \Exception
6270 */
@@ -84,6 +92,15 @@ public function setUp(): void
8492 ],
8593 'authorizationRequest ' => $ this ->authorizationRequestMock ,
8694 ];
95+
96+ $ this ->symfonyRequestMock = $ this ->createMock (Request::class);
97+ $ this ->symfonyResponseMock = $ this ->createMock (\Symfony \Component \HttpFoundation \Response::class);
98+ $ this ->responseHeaderBagMock = $ this ->createMock (ResponseHeaderBag::class);
99+ $ this ->symfonyResponseMock ->headers = $ this ->responseHeaderBagMock ;
100+
101+ $ this ->httpFoundationFactoryMock = $ this ->createMock (HttpFoundationFactory::class);
102+ $ this ->httpFoundationFactoryMock ->method ('createResponse ' )->willReturn ($ this ->symfonyResponseMock );
103+ $ this ->psrHttpBridgeMock ->method ('getHttpFoundationFactory ' )->willReturn ($ this ->httpFoundationFactoryMock );
87104 }
88105
89106 public static function queryParameterValues (): array
@@ -98,6 +115,31 @@ public static function queryParameterValues(): array
98115 ];
99116 }
100117
118+ protected function mock (
119+ ?AuthenticationService $ authenticationService = null ,
120+ ?AuthorizationServer $ authorizationServer = null ,
121+ ?ModuleConfig $ moduleConfig = null ,
122+ ?LoggerService $ loggerService = null ,
123+ ?PsrHttpBridge $ psrHttpBridge = null ,
124+ ?ErrorResponder $ errorResponder = null ,
125+ ): AuthorizationController {
126+ $ authenticationService ??= $ this ->authenticationServiceStub ;
127+ $ authorizationServer ??= $ this ->authorizationServerStub ;
128+ $ moduleConfig ??= $ this ->moduleConfigStub ;
129+ $ loggerService ??= $ this ->loggerServiceMock ;
130+ $ psrHttpBridge ??= $ this ->psrHttpBridgeMock ;
131+ $ errorResponder ??= $ this ->errorResponderMock ;
132+
133+ return new AuthorizationController (
134+ $ authenticationService ,
135+ $ authorizationServer ,
136+ $ moduleConfig ,
137+ $ loggerService ,
138+ $ psrHttpBridge ,
139+ $ errorResponder ,
140+ );
141+ }
142+
101143 /**
102144 * @throws \SimpleSAML\Error\AuthSource
103145 * @throws \SimpleSAML\Error\BadRequest
@@ -128,6 +170,7 @@ public function testReturnsResponseWhenInvoked(array $queryParameters): void
128170 ->method ('getAuthorizationRequestFromState ' )
129171 ->willReturn ($ this ->authorizationRequestMock );
130172
173+ // TODO mivanci Move to mock() method.
131174 $ controller = new AuthorizationController (
132175 $ this ->authenticationServiceStub ,
133176 $ this ->authorizationServerStub ,
@@ -486,4 +529,17 @@ public function testValidateAcrLogsWarningIfNoAcrsConfigured(): void
486529 $ this ->errorResponderMock ,
487530 ))($ this ->serverRequestStub );
488531 }
532+
533+ public function testItAlwaysReturnsAccessControlAllowOrigin (): void
534+ {
535+ $ this ->authorizationServerStub
536+ ->method ('completeAuthorizationRequest ' )
537+ ->willReturn ($ this ->responseStub );
538+
539+ $ this ->responseHeaderBagMock ->expects ($ this ->once ())
540+ ->method ('set ' )
541+ ->with ('Access-Control-Allow-Origin ' , '* ' );
542+
543+ $ this ->mock ()->authorization ($ this ->symfonyRequestMock );
544+ }
489545}
0 commit comments