@@ -154,11 +154,11 @@ function setupLogger(): MockInterface
154154 ->get ('https://example.com ' );
155155})->with ([true , false ]);
156156
157- it ('obfuscates header and body keys ' , function (string $ body , string $ expected ) {
157+ it ('obfuscates request header and body ' , function (string $ body , string $ expected ) {
158158 $ logger = setupLogger ();
159159
160160 $ logger ->shouldReceive ('info ' )->withArgs (function ($ message ) use ($ expected ) {
161- expect ($ message )->toContain ('REQUEST: GET https://example.com ' )
161+ expect ($ message )->toContain ('REQUEST: POST https://example.com ' )
162162 ->and ($ message )->toContain ('Authorization: ********** ' )
163163 ->and ($ message )->toContain ($ expected );
164164 return true ;
@@ -175,15 +175,47 @@ function setupLogger(): MockInterface
175175 ]),
176176 ])->withHeader ('Authorization ' , 'Bearer 123 ' )
177177 ->withBody ($ body )
178- ->get ('https://example.com ' );
178+ ->post ('https://example.com ' );
179179})->with ([
180180 'json-style ' => [
181181 '{"key":"value","apikey":"s3cr3tK3y","token":"s0meT0k3n"} ' ,
182182 '{"key":"value","apikey":"**********","token":"**********"} ' ,
183183 ],
184184 // OpenID Connect example for POST /token endpoint
185185 // see https://openid.net/specs/openid-connect-core-1_0.html#RefreshingAccessToken
186- 'openid-connect ' => [
186+ 'form-style-openid ' => [
187+ 'grant_type=refresh_token&refresh_token=r3fr3shT0k3n&client_id=1234&client_secret=53cr3t ' ,
188+ 'grant_type=refresh_token&refresh_token=**********&client_id=1234&client_secret=********** ' ,
189+ ],
190+ ]);
191+
192+ it ('obfuscates response body ' , function (string $ body , string $ expected ) {
193+ $ logger = setupLogger ();
194+
195+ $ logger ->shouldReceive ('info ' )->withArgs (function ($ message ) use ($ expected ) {
196+ expect ($ message )->toContain ('REQUEST: POST https://example.com ' )
197+ ->and ($ message )->toContain ($ expected );
198+ return true ;
199+ })->once ();
200+
201+ $ logger ->shouldReceive ('info ' )->withArgs (function ($ message ) use ($ expected ) {
202+ expect ($ message )->toContain ('RESPONSE: HTTP/1.1 200 OK ' )
203+ ->and ($ message )->toContain ($ expected );
204+ return true ;
205+ })->once ();
206+
207+ Http::fake ([
208+ '* ' => Http::response ($ body , 200 , [
209+ 'Content-Type ' => 'application/json ' ,
210+ ]),
211+ ])->withBody ($ body )
212+ ->post ('https://example.com ' );
213+ })->with ([
214+ 'json-style-openid ' => [
215+ '{"access_token":"s0meT0k3n-1","expires_in":300,"refresh_token":"s0meT0k3n-2","token_type":"Bearer","id_token":"s0meT0k3n-3","session_state":"1234-56","scope":"foo bar"} ' ,
216+ '{"access_token":"**********","expires_in":300,"refresh_token":"**********","token_type":"Bearer","id_token":"**********","session_state":"1234-56","scope":"foo bar"} ' ,
217+ ],
218+ 'form-style ' => [
187219 'grant_type=refresh_token&refresh_token=r3fr3shT0k3n&client_id=1234&client_secret=53cr3t ' ,
188220 'grant_type=refresh_token&refresh_token=**********&client_id=1234&client_secret=********** ' ,
189221 ],
0 commit comments