停止记录授权标头 [英] Stop the authorization header from logging
本文介绍了停止记录授权标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 Rest Request 的响应日志,如下所示:
请求方式:DELETE请求 URI:https://Some_URI代理:<无>请求参数:查询参数:表单参数:<none>路径参数:<无>标头:Authorization=Bearer AuthenticationTocken接受=*/*内容类型=应用程序/json;字符集=UTF-8Cookie:<无>多部分:<none>正文:<无>
我想记录整个响应而不是标头中的授权部分,结果应该是这样.
请求方法:DELETE请求 URI:https://Some_URI代理:<无>请求参数:查询参数:表单参数:<none>路径参数:<无>标题:接受=*/*内容类型=应用程序/json;字符集=UTF-8Cookie:<无>多部分:<none>正文:<无>
使用代码创建标题:
Mapheaders = 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(标题);
解决方案
我相信您正在使用 Rest Assured 进行测试,在这种情况下,您无法完全删除标题,但可以隐藏详细信息 -
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);
解决方案
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);
这篇关于停止记录授权标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文