【发布时间】:2015-10-22 12:52:19
【问题描述】:
在我的单元测试中我们发现
this.mockMvc
.perform(post("/authenticate")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.param("username", "user@example.com")
.param("password", "superSecretPassword"))
.andExpect(status().isOk())
.andDo(document("preprocessed-request",
preprocessRequest(replacePattern(Pattern.compile("superSecretPassword"), "XXX"))));
参见。 Spring REST Docs documentation
这会生成带有内容的build/generated-snippets/preprocessed-request/http-request.adoc
[source,http]
----
POST /authenticate HTTP/1.1
Content-Type: application/x-www-form-urlencoded
username=user%40example.com&password=superSecretPassword
----
但我希望密码会因为 replacePattern() 而被屏蔽:
[source,http]
----
POST /authenticate HTTP/1.1
Content-Type: application/x-www-form-urlencoded
username=user%40example.com&password=XXX
----
我能做什么?
【问题讨论】:
标签: java spring spring-mvc spring-restdocs