如何解决使用Spring Boot MockMvc测试请求URL中的错误字符
在测试RequestRejectedException时遇到一些困难,当URL包含潜在的恶意String时抛出该异常。使用邮递员发送请求时,状态为500 Internal Server Error
。但是,使用MockMvc编写测试时,相同URL的结果为404 Not Found
。
我的猜测是我必须配置MockMvc-有什么建议吗?
例如请求:
GET http://localhost:8080/users%253Fsort=createdDate,desc
导致:
"status": 500,"error": "Internal Server Error","message": "The request was rejected because the URL contained a potentially malicious String \"%25\""
我的常规测试如下:
def "get users with rejected url"() {
when:
def response = mvc.perform(
get('/users' +
'%253Fsort=createdDate,desc',UUID.randomUUID())
.accept(MediaType.APPLICATION_JSON))
then:
response.andExpect(MockMvcResultMatchers.status().is5xxServerError())
}
常规测试失败,例外:
java.lang.AssertionError: Range for response status value 404 expected:<SERVER_ERROR> but was:<CLIENT_ERROR>
如何配置MockMvc以识别URL并使其行为与我的应用程序相同?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。