Skip to content

Commit

Permalink
[Task 71627] addressed feedback on the new registration functionaliity
Browse files Browse the repository at this point in the history
  • Loading branch information
Raf-atmire committed Jun 30, 2020
1 parent 32a03ee commit 0555644
Show file tree
Hide file tree
Showing 3 changed files with 208 additions and 174 deletions.
Expand Up @@ -199,7 +199,7 @@ private void checkRequiredProperties(EPersonRest epersonRest) {
List<MetadataValueRest> epersonLastName = metadataRest.getMap().get("eperson.lastname");
if (epersonFirstName == null || epersonLastName == null ||
epersonFirstName.isEmpty() || epersonLastName.isEmpty()) {
throw new DSpaceBadRequestException("The eperson.firstname and eperson.lastname values need to be " +
throw new UnprocessableEntityException("The eperson.firstname and eperson.lastname values need to be " +
"filled in");
}
}
Expand Down
Expand Up @@ -2044,22 +2044,24 @@ public void registerNewAccountPatchUpdatePasswordRandomUserUuidFail() throws Exc
accountService.sendRegistrationInfo(context, ePerson.getEmail());
String newRegisterToken = registrationDataService.findByEmail(context, newRegisterEmail).getToken();
PasswordHash oldPassword = ePersonService.getPasswordHash(ePerson);
// updates password
getClient().perform(patch("/api/eperson/epersons/" + ePerson.getID())
.content(patchBody)
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON)
.param("token", newRegisterToken))
.andExpect(status().isUnauthorized());

PasswordHash newPasswordHash = ePersonService.getPasswordHash(ePerson);
assertTrue(StringUtils.equalsIgnoreCase(oldPassword.getHashString(),newPasswordHash.getHashString()));
assertFalse(registrationDataService.findByEmail(context, ePerson.getEmail()) == null);
assertFalse(registrationDataService.findByEmail(context, newRegisterEmail) == null);
try {
// updates password
getClient().perform(patch("/api/eperson/epersons/" + ePerson.getID())
.content(patchBody)
.contentType(MediaType.APPLICATION_JSON_PATCH_JSON)
.param("token", newRegisterToken))
.andExpect(status().isUnauthorized());

context.turnOffAuthorisationSystem();
registrationDataService.delete(context, registrationDataService.findByEmail(context, ePerson.getEmail()));
registrationDataService.deleteByToken(context, newRegisterToken);
context.restoreAuthSystemState();
PasswordHash newPasswordHash = ePersonService.getPasswordHash(ePerson);
assertTrue(StringUtils.equalsIgnoreCase(oldPassword.getHashString(),newPasswordHash.getHashString()));
assertFalse(registrationDataService.findByEmail(context, ePerson.getEmail()) == null);
assertFalse(registrationDataService.findByEmail(context, newRegisterEmail) == null);
} finally {
context.turnOffAuthorisationSystem();
registrationDataService.delete(context, registrationDataService.findByEmail(context, ePerson.getEmail()));
registrationDataService.deleteByToken(context, newRegisterToken);
context.restoreAuthSystemState();
}
}

@Test
Expand Down Expand Up @@ -2118,10 +2120,10 @@ public void postEPersonWithTokenWithoutEmailProperty() throws Exception {

assertNull(registrationDataService.findByToken(context, newRegisterToken));

} finally {
context.turnOffAuthorisationSystem();
registrationDataService.deleteByToken(context, newRegisterToken);
context.restoreAuthSystemState();
} finally {
EPersonBuilder.deleteEPerson(idRef.get());
}
}
Expand Down Expand Up @@ -2179,10 +2181,10 @@ public void postEPersonWithTokenWithEmailProperty() throws Exception {
assertTrue(ePersonService.checkPassword(context, createdEPerson, "somePassword"));
assertNull(registrationDataService.findByToken(context, newRegisterToken));

} finally {
context.turnOffAuthorisationSystem();
registrationDataService.deleteByToken(context, newRegisterToken);
context.restoreAuthSystemState();
} finally {
EPersonBuilder.deleteEPerson(idRef.get());
}

Expand Down Expand Up @@ -2245,10 +2247,10 @@ public void postEPersonWithTokenWithEmailAndSelfRegisteredProperty() throws Exce
assertTrue(ePersonService.checkPassword(context, createdEPerson, "somePassword"));
assertNull(registrationDataService.findByToken(context, newRegisterToken));

} finally {
context.turnOffAuthorisationSystem();
registrationDataService.deleteByToken(context, newRegisterToken);
context.restoreAuthSystemState();
} finally {
EPersonBuilder.deleteEPerson(idRef.get());
}

Expand Down Expand Up @@ -2293,21 +2295,24 @@ public void postEPersonWithTokenWithTwoTokensDifferentEmailProperty() throws Exc

mapper.setAnnotationIntrospector(new IgnoreJacksonWriteOnlyAccess());

getClient().perform(post("/api/eperson/epersons")
.param("token", newRegisterToken)
.content(mapper.writeValueAsBytes(ePersonRest))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest());
try {
getClient().perform(post("/api/eperson/epersons")
.param("token", newRegisterToken)
.content(mapper.writeValueAsBytes(ePersonRest))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest());

EPerson createdEPerson = ePersonService.findByEmail(context, newRegisterEmailTwo);
assertNull(createdEPerson);
assertNotNull(registrationDataService.findByToken(context, newRegisterToken));
assertNotNull(registrationDataService.findByToken(context, newRegisterTokenTwo));
EPerson createdEPerson = ePersonService.findByEmail(context, newRegisterEmailTwo);
assertNull(createdEPerson);
assertNotNull(registrationDataService.findByToken(context, newRegisterToken));
assertNotNull(registrationDataService.findByToken(context, newRegisterTokenTwo));
} finally {
context.turnOffAuthorisationSystem();
registrationDataService.deleteByToken(context, newRegisterToken);
registrationDataService.deleteByToken(context, newRegisterTokenTwo);
context.restoreAuthSystemState();

context.turnOffAuthorisationSystem();
registrationDataService.deleteByToken(context, newRegisterToken);
registrationDataService.deleteByToken(context, newRegisterTokenTwo);
context.restoreAuthSystemState();
}
}

@Test
Expand Down Expand Up @@ -2340,19 +2345,22 @@ public void postEPersonWithRandomTokenWithEmailProperty() throws Exception {

mapper.setAnnotationIntrospector(new IgnoreJacksonWriteOnlyAccess());

getClient().perform(post("/api/eperson/epersons")
.param("token", "randomToken")
.content(mapper.writeValueAsBytes(ePersonRest))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest());
try {
getClient().perform(post("/api/eperson/epersons")
.param("token", "randomToken")
.content(mapper.writeValueAsBytes(ePersonRest))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest());

EPerson createdEPerson = ePersonService.findByEmail(context, newRegisterEmail);
assertNull(createdEPerson);
assertNotNull(registrationDataService.findByToken(context, newRegisterToken));
EPerson createdEPerson = ePersonService.findByEmail(context, newRegisterEmail);
assertNull(createdEPerson);
assertNotNull(registrationDataService.findByToken(context, newRegisterToken));
} finally {
context.turnOffAuthorisationSystem();
registrationDataService.deleteByToken(context, newRegisterToken);
context.restoreAuthSystemState();
}

context.turnOffAuthorisationSystem();
registrationDataService.deleteByToken(context, newRegisterToken);
context.restoreAuthSystemState();
}

@Test
Expand Down Expand Up @@ -2386,19 +2394,22 @@ public void postEPersonWithTokenWithEmailAndSelfRegisteredFalseProperty() throws

mapper.setAnnotationIntrospector(new IgnoreJacksonWriteOnlyAccess());

getClient().perform(post("/api/eperson/epersons")
.param("token", newRegisterToken)
.content(mapper.writeValueAsBytes(ePersonRest))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest());
try {
getClient().perform(post("/api/eperson/epersons")
.param("token", newRegisterToken)
.content(mapper.writeValueAsBytes(ePersonRest))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest());

EPerson createdEPerson = ePersonService.findByEmail(context, newRegisterEmail);
assertNull(createdEPerson);
assertNotNull(registrationDataService.findByToken(context, newRegisterToken));
EPerson createdEPerson = ePersonService.findByEmail(context, newRegisterEmail);
assertNull(createdEPerson);
assertNotNull(registrationDataService.findByToken(context, newRegisterToken));
} finally {
context.turnOffAuthorisationSystem();
registrationDataService.deleteByToken(context, newRegisterToken);
context.restoreAuthSystemState();
}

context.turnOffAuthorisationSystem();
registrationDataService.deleteByToken(context, newRegisterToken);
context.restoreAuthSystemState();
}

@Test
Expand Down Expand Up @@ -2429,19 +2440,22 @@ public void postEPersonWithTokenWithoutLastNameProperty() throws Exception {

mapper.setAnnotationIntrospector(new IgnoreJacksonWriteOnlyAccess());

getClient().perform(post("/api/eperson/epersons")
.param("token", newRegisterToken)
.content(mapper.writeValueAsBytes(ePersonRest))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest());

EPerson createdEPerson = ePersonService.findByEmail(context, newRegisterEmail);
assertNull(createdEPerson);
assertNotNull(registrationDataService.findByToken(context, newRegisterToken));
try {
getClient().perform(post("/api/eperson/epersons")
.param("token", newRegisterToken)
.content(mapper.writeValueAsBytes(ePersonRest))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isUnprocessableEntity());

EPerson createdEPerson = ePersonService.findByEmail(context, newRegisterEmail);
assertNull(createdEPerson);
assertNotNull(registrationDataService.findByToken(context, newRegisterToken));
} finally {
context.turnOffAuthorisationSystem();
registrationDataService.deleteByToken(context, newRegisterToken);
context.restoreAuthSystemState();
}

context.turnOffAuthorisationSystem();
registrationDataService.deleteByToken(context, newRegisterToken);
context.restoreAuthSystemState();
}

@Test
Expand Down Expand Up @@ -2472,19 +2486,22 @@ public void postEPersonWithTokenWithoutFirstNameProperty() throws Exception {

mapper.setAnnotationIntrospector(new IgnoreJacksonWriteOnlyAccess());

getClient().perform(post("/api/eperson/epersons")
.param("token", newRegisterToken)
.content(mapper.writeValueAsBytes(ePersonRest))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest());

EPerson createdEPerson = ePersonService.findByEmail(context, newRegisterEmail);
assertNull(createdEPerson);
assertNotNull(registrationDataService.findByToken(context, newRegisterToken));
try {
getClient().perform(post("/api/eperson/epersons")
.param("token", newRegisterToken)
.content(mapper.writeValueAsBytes(ePersonRest))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isUnprocessableEntity());

EPerson createdEPerson = ePersonService.findByEmail(context, newRegisterEmail);
assertNull(createdEPerson);
assertNotNull(registrationDataService.findByToken(context, newRegisterToken));
} finally {
context.turnOffAuthorisationSystem();
registrationDataService.deleteByToken(context, newRegisterToken);
context.restoreAuthSystemState();
}

context.turnOffAuthorisationSystem();
registrationDataService.deleteByToken(context, newRegisterToken);
context.restoreAuthSystemState();
}

@Test
Expand Down Expand Up @@ -2516,19 +2533,21 @@ public void postEPersonWithTokenWithoutPasswordProperty() throws Exception {

mapper.setAnnotationIntrospector(new IgnoreJacksonWriteOnlyAccess());

getClient().perform(post("/api/eperson/epersons")
.param("token", newRegisterToken)
.content(mapper.writeValueAsBytes(ePersonRest))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest());

EPerson createdEPerson = ePersonService.findByEmail(context, newRegisterEmail);
assertNull(createdEPerson);
assertNotNull(registrationDataService.findByToken(context, newRegisterToken));
try {
getClient().perform(post("/api/eperson/epersons")
.param("token", newRegisterToken)
.content(mapper.writeValueAsBytes(ePersonRest))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest());

context.turnOffAuthorisationSystem();
registrationDataService.deleteByToken(context, newRegisterToken);
context.restoreAuthSystemState();
EPerson createdEPerson = ePersonService.findByEmail(context, newRegisterEmail);
assertNull(createdEPerson);
assertNotNull(registrationDataService.findByToken(context, newRegisterToken));
} finally {
context.turnOffAuthorisationSystem();
registrationDataService.deleteByToken(context, newRegisterToken);
context.restoreAuthSystemState();
}

}

Expand Down Expand Up @@ -2562,19 +2581,22 @@ public void postEPersonWithWrongToken() throws Exception {

mapper.setAnnotationIntrospector(new IgnoreJacksonWriteOnlyAccess());

getClient().perform(post("/api/eperson/epersons")
.param("token", forgotPasswordToken)
.content(mapper.writeValueAsBytes(ePersonRest))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest());
try {
getClient().perform(post("/api/eperson/epersons")
.param("token", forgotPasswordToken)
.content(mapper.writeValueAsBytes(ePersonRest))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest());

EPerson createdEPerson = ePersonService.findByEmail(context, newEmail);
assertNull(createdEPerson);
assertNotNull(registrationDataService.findByToken(context, forgotPasswordToken));
EPerson createdEPerson = ePersonService.findByEmail(context, newEmail);
assertNull(createdEPerson);
assertNotNull(registrationDataService.findByToken(context, forgotPasswordToken));
} finally {
context.turnOffAuthorisationSystem();
registrationDataService.deleteByToken(context, forgotPasswordToken);
context.restoreAuthSystemState();
}

context.turnOffAuthorisationSystem();
registrationDataService.deleteByToken(context, forgotPasswordToken);
context.restoreAuthSystemState();

}

Expand Down Expand Up @@ -2633,11 +2655,10 @@ public void postEPersonWithTokenWithEmailPropertyAnonUser() throws Exception {
EPerson createdEPerson = ePersonService.find(context, UUID.fromString(epersonUuid));
assertTrue(ePersonService.checkPassword(context, createdEPerson, "somePassword"));
assertNull(registrationDataService.findByToken(context, newRegisterToken));

} finally {
context.turnOffAuthorisationSystem();
registrationDataService.deleteByToken(context, newRegisterToken);
context.restoreAuthSystemState();
} finally {
EPersonBuilder.deleteEPerson(idRef.get());
}
}
Expand Down

0 comments on commit 0555644

Please sign in to comment.