ResetPasswordController { @PostMapping(params = "action=changePassword", produces = APPLICATION_JSON_VALUE) public String changePassword(HttpServletRequest request, @RequestParam(value = "u", required = false) @Nullable String userId, @RequestParam(value = "vc", required = false) @Nullable String vcode) { Optional<User> optional = resetPasswordService.checkVcode(userId, vcode); if (!optional.isPresent()) { throw new BusinessException(BusinessCode.LINK_EXPIRED); } String newPassword = request.getParameter("newPassword"); ValueCheck.checkPassword(newPassword); User user = optional.get(); userMapper.updateSelective(user.getId(), User.builder() .password(passwordEncoder.encode(newPassword)) .build()); resetPasswordService.remove(userId); throw new BusinessException(BusinessCode.MODIFY_PASSWORD_SUCCEED); }  @GetMapping(produces = TEXT_HTML_VALUE) String doGet(
            @RequestParam(value = "u", required = false) @Nullable String userId,
            @RequestParam(value = "vc", required = false) @Nullable String vcode); @PostMapping(produces = APPLICATION_JSON_VALUE) String doPost(HttpServletRequest request,
            @RequestParam(value = "verify", required = false) @Nullable String verify,
            @RequestParam(value = "username", required = false) @Nullable String username,
            @Nullable Locale locale); @PostMapping(params = "action=changePassword", produces = APPLICATION_JSON_VALUE) String changePassword(HttpServletRequest request,
            @RequestParam(value = "u", required = false) @Nullable String userId,
            @RequestParam(value = "vc", required = false) @Nullable String vcode);  }
@Test public void testChangePassword() throws Exception { Locale locale = Locale.getDefault(); MvcResult result = mvc.perform(get("/images/rand.jpg")) .andExpect(content().contentTypeCompatibleWith(MediaType.IMAGE_JPEG)) .andReturn(); HttpSession session = result.getRequest().getSession(false); assertThat(session).isNotNull(); String verify = (String) session.getAttribute(Constants.KAPTCHA_SESSION_KEY); String username = mockDataService.user( builder -> builder.email("admin@local.host") ).getId(); mvc.perform(post("/resetPassword.json") .param("verify", verify + "1") .param("username", username) .locale(locale)) .andExpect(status().isBadRequest()) .andReturn(); mvc.perform(post("/resetPassword.json") .session((MockHttpSession) session) .param("verify", verify + "1") .param("username", username) .locale(locale)) .andExpect(status().isBadRequest()) .andReturn(); assertThat(session.getAttribute(Constants.KAPTCHA_SESSION_KEY)).isNull(); mvc.perform(get("/images/rand.jpg") .session((MockHttpSession) session)) .andExpect(content().contentTypeCompatibleWith(MediaType.IMAGE_JPEG)) .andReturn(); verify = (String) session.getAttribute(Constants.KAPTCHA_SESSION_KEY); mvc.perform(post("/resetPassword.json") .session((MockHttpSession) session) .param("verify", verify) .param("username", username) .locale(locale)) .andExpect(status().isInternalServerError()) .andReturn(); assertThat(session.getAttribute(Constants.KAPTCHA_SESSION_KEY)).isNull(); mvc.perform(post("/resetPassword.json") .param("action", "changePassword")) .andExpect(status().isBadRequest()) .andReturn(); }