Source:
<code>public void updateUserPassword() throws Exception { <START> HudsonPrivateSecurityRealm securityRealm = new HudsonPrivateSecurityRealm(true, false, null); <END> j.jenkins.setSecurityRealm(securityRealm); WebClient wc = j.createWebClient(); spySecurityListener.usersWithPasswordUpdate.clear(); assertTrue(spySecurityListener.usersWithPasswordUpdate.isEmpty()); SignupPage signup = new SignupPage(wc.goTo("signup")); signup.enterUsername("debbie"); signup.enterPassword("debbie"); signup.enterFullName(StringUtils.capitalize("debbie user")); signup.enterEmail("debbie" + "@" + "debbie" + ".com"); HtmlPage p = signup.submit(j); assertEquals(200, p.getWebResponse().getStatusCode()); User debbie = User.getById("debbie", false); URL configPage = wc.createCrumbedUrl(debbie.getUrl() + "/" + "configSubmit"); String formData = "{\"fullName\": \"debbie user\", \"description\": \"\", \"userProperty3\": {\"primaryViewName\": \"\"}, \"userProperty5\": {\"password\": \"admin\", \"$redact\": [\"password\", \"password2\"], \"password2\": \"admin\"}, \"userProperty6\": {\"authorizedKeys\": \"\"}, \"userProperty8\": {\"insensitiveSearch\": true}, \"core:apply\": \"true\"}"; WebRequest request = new WebRequest(configPage, HttpMethod.POST); request.setAdditionalHeader("Content-Type", "application/x-www-form-urlencoded"); request.setRequestBody("json=" + URLEncoder.encode(formData, StandardCharsets.UTF_8.name())); Page page = wc.getPage(request); assertTrue(spySecurityListener.usersWithPasswordUpdate.get(0).equals("debbie")); assertEquals(200, page.getWebResponse().getStatusCode()); }</code><technical_language>if before, simplify tests a bit JenkinsRule.createDummySecurityRealm()? I myself, I tests it</technical_language>

Target:
public void updateUserPassword() throws Exception { HudsonPrivateSecurityRealm securityRealm = new HudsonPrivateSecurityRealm(true, false, null); j.jenkins.setSecurityRealm(securityRealm); WebClient wc = j.createWebClient(); spyPasswordListener.usersWithPasswordUpdate.clear(); assertTrue(spyPasswordListener.usersWithPasswordUpdate.isEmpty()); SignupPage signup = new SignupPage(wc.goTo("signup")); signup.enterUsername("debbie"); signup.enterPassword("debbie"); signup.enterFullName(StringUtils.capitalize("debbie user")); signup.enterEmail("debbie" + "@" + "debbie" + ".com"); HtmlPage p = signup.submit(j); assertEquals(200, p.getWebResponse().getStatusCode()); User debbie = User.getById("debbie", false); URL configPage = wc.createCrumbedUrl(debbie.getUrl() + "/" + "configSubmit"); String formData = "{\"fullName\": \"debbie user\", \"description\": \"\", \"userProperty3\": {\"primaryViewName\": \"\"}, \"userProperty5\": {\"user.password\": \"admin\", \"$redact\": [\"user.password\", \"user.password2\"], \"user.password2\": \"admin\"}, \"userProperty6\": {\"authorizedKeys\": \"\"}, \"userProperty8\": {\"insensitiveSearch\": true}, \"core:apply\": \"true\"}"; WebRequest request = new WebRequest(configPage, HttpMethod.POST); request.setAdditionalHeader("Content-Type", "application/x-www-form-urlencoded"); request.setRequestBody("json=" + URLEncoder.encode(formData, StandardCharsets.UTF_8.name())); Page page = wc.getPage(request); assertEquals(200, page.getWebResponse().getStatusCode()); assertTrue(spyPasswordListener.usersWithPasswordUpdate.get(0).equals("debbie")); }