4
4
5
5
namespace League \Bundle \OAuth2ServerBundle \Tests \Acceptance ;
6
6
7
+ use League \Bundle \OAuth2ServerBundle \Event \TokenRequestResolveEvent ;
7
8
use League \Bundle \OAuth2ServerBundle \Event \UserResolveEvent ;
8
9
use League \Bundle \OAuth2ServerBundle \Manager \AccessTokenManagerInterface ;
9
10
use League \Bundle \OAuth2ServerBundle \Manager \AuthorizationCodeManagerInterface ;
@@ -37,6 +38,13 @@ public function testSuccessfulClientCredentialsRequest(): void
37
38
'grant_type ' => 'client_credentials ' ,
38
39
]);
39
40
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
+
40
48
$ response = $ this ->client ->getResponse ();
41
49
42
50
$ this ->assertSame (200 , $ response ->getStatusCode ());
@@ -48,6 +56,7 @@ public function testSuccessfulClientCredentialsRequest(): void
48
56
$ this ->assertLessThanOrEqual (3600 , $ jsonResponse ['expires_in ' ]);
49
57
$ this ->assertGreaterThan (0 , $ jsonResponse ['expires_in ' ]);
50
58
$ this ->assertNotEmpty ($ jsonResponse ['access_token ' ]);
59
+ $ this ->assertEmpty ($ response ->headers ->get ('foo ' ), 'bar ' );
51
60
}
52
61
53
62
public function testSuccessfulPasswordRequest (): void
@@ -59,6 +68,13 @@ public function testSuccessfulPasswordRequest(): void
59
68
$ event ->setUser (FixtureFactory::createUser ());
60
69
});
61
70
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
+
62
78
$ this ->client ->request ('POST ' , '/token ' , [
63
79
'client_id ' => 'foo ' ,
64
80
'client_secret ' => 'secret ' ,
@@ -79,6 +95,7 @@ public function testSuccessfulPasswordRequest(): void
79
95
$ this ->assertGreaterThan (0 , $ jsonResponse ['expires_in ' ]);
80
96
$ this ->assertNotEmpty ($ jsonResponse ['access_token ' ]);
81
97
$ this ->assertNotEmpty ($ jsonResponse ['refresh_token ' ]);
98
+ $ this ->assertSame ($ response ->headers ->get ('foo ' ), 'bar ' );
82
99
}
83
100
84
101
public function testSuccessfulRefreshTokenRequest (): void
@@ -95,6 +112,13 @@ public function testSuccessfulRefreshTokenRequest(): void
95
112
'refresh_token ' => TestHelper::generateEncryptedPayload ($ refreshToken ),
96
113
]);
97
114
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
+
98
122
$ response = $ this ->client ->getResponse ();
99
123
100
124
$ this ->assertSame (200 , $ response ->getStatusCode ());
@@ -107,6 +131,7 @@ public function testSuccessfulRefreshTokenRequest(): void
107
131
$ this ->assertGreaterThan (0 , $ jsonResponse ['expires_in ' ]);
108
132
$ this ->assertNotEmpty ($ jsonResponse ['access_token ' ]);
109
133
$ this ->assertNotEmpty ($ jsonResponse ['refresh_token ' ]);
134
+ $ this ->assertEmpty ($ response ->headers ->get ('foo ' ), 'bar ' );
110
135
}
111
136
112
137
public function testSuccessfulAuthorizationCodeRequest (): void
@@ -124,6 +149,13 @@ public function testSuccessfulAuthorizationCodeRequest(): void
124
149
'code ' => TestHelper::generateEncryptedAuthCodePayload ($ authCode ),
125
150
]);
126
151
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
+
127
159
$ response = $ this ->client ->getResponse ();
128
160
129
161
$ this ->assertSame (200 , $ response ->getStatusCode ());
@@ -135,6 +167,7 @@ public function testSuccessfulAuthorizationCodeRequest(): void
135
167
$ this ->assertLessThanOrEqual (3600 , $ jsonResponse ['expires_in ' ]);
136
168
$ this ->assertGreaterThan (0 , $ jsonResponse ['expires_in ' ]);
137
169
$ this ->assertNotEmpty ($ jsonResponse ['access_token ' ]);
170
+ $ this ->assertEmpty ($ response ->headers ->get ('foo ' ), 'bar ' );
138
171
}
139
172
140
173
public function testSuccessfulAuthorizationCodeRequestWithPublicClient (): void
@@ -144,6 +177,13 @@ public function testSuccessfulAuthorizationCodeRequestWithPublicClient(): void
144
177
->get (AuthorizationCodeManagerInterface::class)
145
178
->find (FixtureFactory::FIXTURE_AUTH_CODE_PUBLIC_CLIENT );
146
179
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
+
147
187
$ this ->client ->request ('POST ' , '/token ' , [
148
188
'client_id ' => FixtureFactory::FIXTURE_PUBLIC_CLIENT ,
149
189
'grant_type ' => 'authorization_code ' ,
@@ -162,6 +202,7 @@ public function testSuccessfulAuthorizationCodeRequestWithPublicClient(): void
162
202
$ this ->assertLessThanOrEqual (3600 , $ jsonResponse ['expires_in ' ]);
163
203
$ this ->assertGreaterThan (0 , $ jsonResponse ['expires_in ' ]);
164
204
$ this ->assertNotEmpty ($ jsonResponse ['access_token ' ]);
205
+ $ this ->assertSame ($ response ->headers ->get ('foo ' ), 'bar ' );
165
206
}
166
207
167
208
public function testFailedTokenRequest (): void
@@ -188,6 +229,13 @@ public function testFailedClientCredentialsTokenRequest(): void
188
229
'grant_type ' => 'client_credentials ' ,
189
230
]);
190
231
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
+
191
239
$ response = $ this ->client ->getResponse ();
192
240
193
241
$ this ->assertSame (401 , $ response ->getStatusCode ());
@@ -197,5 +245,6 @@ public function testFailedClientCredentialsTokenRequest(): void
197
245
198
246
$ this ->assertSame ('invalid_client ' , $ jsonResponse ['error ' ]);
199
247
$ this ->assertSame ('Client authentication failed ' , $ jsonResponse ['message ' ]);
248
+ $ this ->assertEmpty ($ response ->headers ->get ('foo ' ), 'bar ' );
200
249
}
201
250
}
0 commit comments