@@ -278,6 +278,48 @@ TEST(TracingRestClient, WithRestContextDetails) {
278278 EventNamed (" gl-cpp.curl.ssl.handshake" )))));
279279}
280280
281+ TEST (TracingRestClient, CensorsAuthFields) {
282+ auto span_catcher = InstallSpanCatcher ();
283+
284+ auto impl = std::make_unique<MockRestClient>();
285+ EXPECT_CALL (*impl, Delete).WillOnce ([](RestContext&, RestRequest const &) {
286+ auto response = std::make_unique<MockRestResponse>();
287+ EXPECT_CALL (*response, StatusCode)
288+ .WillRepeatedly (Return (HttpStatusCode::kOk ));
289+ EXPECT_CALL (*response, Headers).WillRepeatedly (Return (MockHeaders ()));
290+ EXPECT_CALL (std::move (*response), ExtractPayload).WillOnce ([] {
291+ return MakeMockHttpPayloadSuccess (MockContents ());
292+ });
293+ return std::unique_ptr<RestResponse>(std::move (response));
294+ });
295+
296+ auto constexpr kUrl = " https://storage.googleapis.com/storage/v1/b/my-bucket" ;
297+ RestRequest request (kUrl );
298+
299+ auto client = MakeTracingRestClient (std::move (impl));
300+ rest_internal::RestContext context;
301+ context.AddHeader (" authorization" , " bearer: ABCDEFGHIJKLMNOPQRSTUVWXYZ" );
302+ context.AddHeader (" x-goog-api-key" , " ABCDEFGHIJKLMNOPQRSTUVWXYZ" );
303+
304+ auto r = client->Delete (context, request);
305+ ASSERT_STATUS_OK (r);
306+ auto response = *std::move (r);
307+ ASSERT_THAT (response, NotNull ());
308+ EXPECT_THAT (response->StatusCode (), Eq (HttpStatusCode::kOk ));
309+ EXPECT_THAT (response->Headers (), ElementsAreArray (MockHeaders ()));
310+ auto contents = ReadAll (std::move (*response).ExtractPayload ());
311+ EXPECT_THAT (contents, IsOkAndHolds (MockContents ()));
312+
313+ auto spans = span_catcher->GetSpans ();
314+ EXPECT_THAT (
315+ spans,
316+ Contains (SpanHasAttributes (
317+ OTelAttribute<std::string>(" http.request.header.authorization" ,
318+ " bearer: ABCDEFGHIJKLMNOPQRSTUVWX" ),
319+ OTelAttribute<std::string>(" http.request.header.x-goog-api-key" ,
320+ " ABCDEFGHIJKL..." ))));
321+ }
322+
281323TEST (TracingRestClient, CachedConnection) {
282324 auto span_catcher = InstallSpanCatcher ();
283325
0 commit comments