Search code examples
web-api-testingrest

Stop the authorization header from logging


I have a response log of a Rest Request as shown below:

Request method: DELETE
Request URI:    https://Some_URI
Proxy:          <none>
Request params: <none>
Query params:   <none>
Form params:    <none>
Path params:    <none>
Headers:        Authorization=Bearer AuthenticationTocken
                Accept=*/*
                Content-Type=application/json; charset=UTF-8
Cookies:        <none>
Multiparts:     <none>
Body:           <none>

I Want to log the entire response but not the Authorization part from the header, Result should like.

    Request method: DELETE
    Request URI:    https://Some_URI
    Proxy:          <none>
    Request params: <none>
    Query params:   <none>
    Form params:    <none>
    Path params:    <none>
    Headers:        Accept=*/*
                    Content-Type=application/json; charset=UTF-8
    Cookies:        <none>
    Multiparts:     <none>
    Body:           <none>

Created the Header with the code:

Map<String, Object> headers = new HashMap<>();
        headers.put( HttpHeaders.CONTENT_TYPE,ContentType.JSON);
        headers.put( HttpHeaders.ACCEPT,ContentType.ANY);    
  RequestSpecification requestSpecification = given().log().all()
                .header(HttpHeaders.AUTHORIZATION, BEARER_KEY + getAuthorizationToken())
                .headers(headers);

Solution

  • I believe you are using Rest Assured to test, In that case you cannot remove the header completely but you can hide the details - blacklist-headers-from-logging

    Usage Sample :

    given().config(RestAssuredConfig.config().logConfig(LogConfig.logConfig().blacklistHeader("Set-Cookie"))).when()
                    .get("URL").then().log().all().statusCode(200);
    

    enter image description here