Skip to content

Commit

Permalink
disable create account post request for selfServiceDisabled flag
Browse files Browse the repository at this point in the history
[#141508943] https://www.pivotaltracker.com/story/show/141508943

Signed-off-by: Priyata Agrawal <pagrawal@pivotal.io>
  • Loading branch information
Jeremy Coffield authored and Priyata25 committed Mar 21, 2017
1 parent 6a4ed11 commit 6af44c9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Expand Up @@ -57,9 +57,7 @@ public String activationEmail(Model model,
@RequestParam(value = "redirect_uri", required = false) String redirectUri,
HttpServletResponse response) {
if(!IdentityZoneHolder.get().getConfig().getLinks().getSelfService().isSelfServiceLinksEnabled()) {
model.addAttribute("error_message_code", "self_service_disabled");
response.setStatus(HttpStatus.NOT_FOUND.value());
return "error";
return handleSelfServiceDisabled(model, response, "error_message_code", "self_service_disabled");
}
model.addAttribute("client_id", clientId);
model.addAttribute("redirect_uri", redirectUri);
Expand All @@ -73,6 +71,9 @@ public String sendActivationEmail(Model model, HttpServletResponse response,
@Valid @ModelAttribute("email") ValidEmail email, BindingResult result,
@RequestParam("password") String password,
@RequestParam("password_confirmation") String passwordConfirmation) {
if(!IdentityZoneHolder.get().getConfig().getLinks().getSelfService().isSelfServiceLinksEnabled()) {
return handleSelfServiceDisabled(model, response, "error_message_code", "self_service_disabled");
}
if(result.hasErrors()) {
return handleUnprocessableEntity(model, response, "error_message_code", "invalid_email");
}
Expand Down Expand Up @@ -128,6 +129,12 @@ private String handleUnprocessableEntity(Model model, HttpServletResponse respon
return "accounts/new_activation_email";
}

private String handleSelfServiceDisabled(Model model, HttpServletResponse response, String attributeKey, String attributeValue) {
model.addAttribute(attributeKey, attributeValue);
response.setStatus(HttpStatus.NOT_FOUND.value());
return "error";
}

public static class ValidEmail {
@Email
String email;
Expand Down
Expand Up @@ -180,6 +180,24 @@ public void testCreateAccountWithdisableSelfService() throws Exception {
.andExpect(status().isNotFound());
}

@Test
public void testDisableSelfServiceCreateAccountPost() throws Exception {
String subdomain = generator.generate();
IdentityZone zone = MultitenancyFixture.identityZone(subdomain, subdomain);
zone.getConfig().getLinks().getSelfService().setSelfServiceLinksEnabled(false);

MockMvcUtils.createOtherIdentityZoneAndReturnResult(getMockMvc(), getWebApplicationContext(), getBaseClientDetails() ,zone);

getMockMvc().perform(post("/create_account.do")
.with(new SetServerNameRequestPostProcessor(subdomain + ".localhost"))
.param("email", userEmail)
.param("password", "secr3T")
.param("password_confirmation", "secr3T"))
.andExpect(model().attribute("error_message_code", "self_service_disabled"))
.andExpect(view().name("error"))
.andExpect(status().isNotFound());
}

@Test
public void defaultZoneLogoNull_useAssetBaseUrlImage() throws Exception {
((MockEnvironment) getWebApplicationContext().getEnvironment()).setProperty("assetBaseUrl", "/resources/oss");
Expand Down

0 comments on commit 6af44c9

Please sign in to comment.