在我的单元测试中,我们发现
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"))));
这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
----
我能做些什么?