Skip to content

Commit

Permalink
do not hide registration errors (login/email already used)
Browse files Browse the repository at this point in the history
relates to #21731
  • Loading branch information
atomfrede committed Oct 22, 2023
1 parent 1da7aa1 commit d6df316
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,10 @@ _%>

private ProblemDetailWithCause getProblemDetailWithCause(Throwable ex) {
<%_ if (!skipUserManagement) { _%>
if(ex instanceof <%= packageName %>.service.EmailAlreadyUsedException ||
ex instanceof <%= packageName %>.service.UsernameAlreadyUsedException) {
// return 201 - CREATED on purpose to not reveal information to potential attackers
// see https://github.com/jhipster/generator-jhipster/issues/21731
return ProblemDetailWithCauseBuilder.instance()
.withStatus(201).build();
}
if(ex instanceof <%= packageName %>.service.UsernameAlreadyUsedException )
return (ProblemDetailWithCause) new LoginAlreadyUsedException().getBody();
if(ex instanceof <%= packageName %>.service.EmailAlreadyUsedException )
return (ProblemDetailWithCause) new EmailAlreadyUsedException().getBody();
if(ex instanceof <%= packageName %>.service.InvalidPasswordException )
return (ProblemDetailWithCause) new InvalidPasswordException().getBody();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,14 +529,14 @@ class AccountResourceIT {
.contentType(MediaType.APPLICATION_JSON)
.bodyValue(TestUtil.convertObjectToJsonBytes(secondUser))
.exchange()
.expectStatus().isCreated();
.expectStatus().isBadRequest();
<%_ } else { _%>
restAccountMockMvc.perform(
post("/api/register")
.contentType(MediaType.APPLICATION_JSON)
.content(TestUtil.convertObjectToJsonBytes(secondUser))<% if (authenticationUsesCsrf) { %>
.with(csrf())<% } %>)
.andExpect(status().isCreated());
.andExpect(status().is4xxClientError());
<%_ } _%>
}

Expand Down Expand Up @@ -632,14 +632,14 @@ class AccountResourceIT {
.contentType(MediaType.APPLICATION_JSON)
.bodyValue(TestUtil.convertObjectToJsonBytes(userWithUpperCaseEmail))
.exchange()
.expectStatus().isCreated();
.expectStatus().is4xxClientError();
<%_ } else { _%>
restAccountMockMvc.perform(
post("/api/register")
.contentType(MediaType.APPLICATION_JSON)
.content(TestUtil.convertObjectToJsonBytes(userWithUpperCaseEmail))<% if (authenticationUsesCsrf) { %>
.with(csrf())<% } %>)
.andExpect(status().isCreated());
.andExpect(status().is4xxClientError());
<%_ } _%>

Optional<<%= user.persistClass %>> testUser4 = userRepository.findOneByLogin("test-register-duplicate-email-3")<% if (reactive) { %>.blockOptional()<% } %>;
Expand All @@ -655,14 +655,14 @@ class AccountResourceIT {
.contentType(MediaType.APPLICATION_JSON)
.bodyValue(TestUtil.convertObjectToJsonBytes(secondUser))
.exchange()
.expectStatus().isCreated();
.expectStatus().is4xxClientError();
<%_ } else { _%>
restAccountMockMvc.perform(
post("/api/register")
.contentType(MediaType.APPLICATION_JSON)
.content(TestUtil.convertObjectToJsonBytes(secondUser))<% if (authenticationUsesCsrf) { %>
.with(csrf())<% } %>)
.andExpect(status().isCreated());
.andExpect(status().is4xxClientError());
<%_ } _%>
}

Expand Down

0 comments on commit d6df316

Please sign in to comment.