44
55namespace League \Bundle \OAuth2ServerBundle \Tests \Acceptance ;
66
7+ use League \Bundle \OAuth2ServerBundle \Event \TokenRequestResolveEvent ;
78use League \Bundle \OAuth2ServerBundle \Event \UserResolveEvent ;
89use League \Bundle \OAuth2ServerBundle \Manager \AccessTokenManagerInterface ;
910use League \Bundle \OAuth2ServerBundle \Manager \AuthorizationCodeManagerInterface ;
@@ -37,6 +38,13 @@ public function testSuccessfulClientCredentialsRequest(): void
3738 'grant_type ' => 'client_credentials ' ,
3839 ]);
3940
41+ $ this ->client
42+ ->getContainer ()
43+ ->get ('event_dispatcher ' )
44+ ->addListener (OAuth2Events::TOKEN_REQUEST_RESOLVE , static function (TokenRequestResolveEvent $ event ): void {
45+ $ event ->getResponse ()->headers ->set ('foo ' , 'bar ' );
46+ });
47+
4048 $ response = $ this ->client ->getResponse ();
4149
4250 $ this ->assertSame (200 , $ response ->getStatusCode ());
@@ -48,6 +56,7 @@ public function testSuccessfulClientCredentialsRequest(): void
4856 $ this ->assertLessThanOrEqual (3600 , $ jsonResponse ['expires_in ' ]);
4957 $ this ->assertGreaterThan (0 , $ jsonResponse ['expires_in ' ]);
5058 $ this ->assertNotEmpty ($ jsonResponse ['access_token ' ]);
59+ $ this ->assertEmpty ($ response ->headers ->get ('foo ' ), 'bar ' );
5160 }
5261
5362 public function testSuccessfulPasswordRequest (): void
@@ -59,6 +68,13 @@ public function testSuccessfulPasswordRequest(): void
5968 $ event ->setUser (FixtureFactory::createUser ());
6069 });
6170
71+ $ this ->client
72+ ->getContainer ()
73+ ->get ('event_dispatcher ' )
74+ ->addListener (OAuth2Events::TOKEN_REQUEST_RESOLVE , static function (TokenRequestResolveEvent $ event ): void {
75+ $ event ->getResponse ()->headers ->set ('foo ' , 'bar ' );
76+ });
77+
6278 $ this ->client ->request ('POST ' , '/token ' , [
6379 'client_id ' => 'foo ' ,
6480 'client_secret ' => 'secret ' ,
@@ -79,6 +95,7 @@ public function testSuccessfulPasswordRequest(): void
7995 $ this ->assertGreaterThan (0 , $ jsonResponse ['expires_in ' ]);
8096 $ this ->assertNotEmpty ($ jsonResponse ['access_token ' ]);
8197 $ this ->assertNotEmpty ($ jsonResponse ['refresh_token ' ]);
98+ $ this ->assertSame ($ response ->headers ->get ('foo ' ), 'bar ' );
8299 }
83100
84101 public function testSuccessfulRefreshTokenRequest (): void
@@ -95,6 +112,13 @@ public function testSuccessfulRefreshTokenRequest(): void
95112 'refresh_token ' => TestHelper::generateEncryptedPayload ($ refreshToken ),
96113 ]);
97114
115+ $ this ->client
116+ ->getContainer ()
117+ ->get ('event_dispatcher ' )
118+ ->addListener (OAuth2Events::TOKEN_REQUEST_RESOLVE , static function (TokenRequestResolveEvent $ event ): void {
119+ $ event ->getResponse ()->headers ->set ('foo ' , 'bar ' );
120+ });
121+
98122 $ response = $ this ->client ->getResponse ();
99123
100124 $ this ->assertSame (200 , $ response ->getStatusCode ());
@@ -107,6 +131,7 @@ public function testSuccessfulRefreshTokenRequest(): void
107131 $ this ->assertGreaterThan (0 , $ jsonResponse ['expires_in ' ]);
108132 $ this ->assertNotEmpty ($ jsonResponse ['access_token ' ]);
109133 $ this ->assertNotEmpty ($ jsonResponse ['refresh_token ' ]);
134+ $ this ->assertEmpty ($ response ->headers ->get ('foo ' ), 'bar ' );
110135 }
111136
112137 public function testSuccessfulAuthorizationCodeRequest (): void
@@ -124,6 +149,13 @@ public function testSuccessfulAuthorizationCodeRequest(): void
124149 'code ' => TestHelper::generateEncryptedAuthCodePayload ($ authCode ),
125150 ]);
126151
152+ $ this ->client
153+ ->getContainer ()
154+ ->get ('event_dispatcher ' )
155+ ->addListener (OAuth2Events::TOKEN_REQUEST_RESOLVE , static function (TokenRequestResolveEvent $ event ): void {
156+ $ event ->getResponse ()->headers ->set ('foo ' , 'bar ' );
157+ });
158+
127159 $ response = $ this ->client ->getResponse ();
128160
129161 $ this ->assertSame (200 , $ response ->getStatusCode ());
@@ -135,6 +167,7 @@ public function testSuccessfulAuthorizationCodeRequest(): void
135167 $ this ->assertLessThanOrEqual (3600 , $ jsonResponse ['expires_in ' ]);
136168 $ this ->assertGreaterThan (0 , $ jsonResponse ['expires_in ' ]);
137169 $ this ->assertNotEmpty ($ jsonResponse ['access_token ' ]);
170+ $ this ->assertEmpty ($ response ->headers ->get ('foo ' ), 'bar ' );
138171 }
139172
140173 public function testSuccessfulAuthorizationCodeRequestWithPublicClient (): void
@@ -144,6 +177,13 @@ public function testSuccessfulAuthorizationCodeRequestWithPublicClient(): void
144177 ->get (AuthorizationCodeManagerInterface::class)
145178 ->find (FixtureFactory::FIXTURE_AUTH_CODE_PUBLIC_CLIENT );
146179
180+ $ this ->client
181+ ->getContainer ()
182+ ->get ('event_dispatcher ' )
183+ ->addListener (OAuth2Events::TOKEN_REQUEST_RESOLVE , static function (TokenRequestResolveEvent $ event ): void {
184+ $ event ->getResponse ()->headers ->set ('foo ' , 'bar ' );
185+ });
186+
147187 $ this ->client ->request ('POST ' , '/token ' , [
148188 'client_id ' => FixtureFactory::FIXTURE_PUBLIC_CLIENT ,
149189 'grant_type ' => 'authorization_code ' ,
@@ -162,6 +202,7 @@ public function testSuccessfulAuthorizationCodeRequestWithPublicClient(): void
162202 $ this ->assertLessThanOrEqual (3600 , $ jsonResponse ['expires_in ' ]);
163203 $ this ->assertGreaterThan (0 , $ jsonResponse ['expires_in ' ]);
164204 $ this ->assertNotEmpty ($ jsonResponse ['access_token ' ]);
205+ $ this ->assertSame ($ response ->headers ->get ('foo ' ), 'bar ' );
165206 }
166207
167208 public function testFailedTokenRequest (): void
@@ -188,6 +229,13 @@ public function testFailedClientCredentialsTokenRequest(): void
188229 'grant_type ' => 'client_credentials ' ,
189230 ]);
190231
232+ $ this ->client
233+ ->getContainer ()
234+ ->get ('event_dispatcher ' )
235+ ->addListener (OAuth2Events::TOKEN_REQUEST_RESOLVE , static function (TokenRequestResolveEvent $ event ): void {
236+ $ event ->getResponse ()->headers ->set ('foo ' , 'bar ' );
237+ });
238+
191239 $ response = $ this ->client ->getResponse ();
192240
193241 $ this ->assertSame (401 , $ response ->getStatusCode ());
@@ -197,5 +245,6 @@ public function testFailedClientCredentialsTokenRequest(): void
197245
198246 $ this ->assertSame ('invalid_client ' , $ jsonResponse ['error ' ]);
199247 $ this ->assertSame ('Client authentication failed ' , $ jsonResponse ['message ' ]);
248+ $ this ->assertEmpty ($ response ->headers ->get ('foo ' ), 'bar ' );
200249 }
201250}
0 commit comments