use of org.cloudfoundry.identity.uaa.scim.ScimMeta in project uaa by cloudfoundry.
the class PasswordResetEndpointTest method changePassword_Returns422UnprocessableEntity_NewPasswordSameAsOld.
@Test
void changePassword_Returns422UnprocessableEntity_NewPasswordSameAsOld() throws Exception {
Mockito.reset(mockPasswordValidator);
when(mockExpiringCodeStore.retrieveCode("emailed_code", currentZoneId)).thenReturn(new ExpiringCode("emailed_code", new Timestamp(System.currentTimeMillis() + UaaResetPasswordService.PASSWORD_RESET_LIFETIME), "{\"user_id\":\"eyedee\",\"username\":\"user@example.com\",\"passwordModifiedTime\":null,\"client_id\":\"\",\"redirect_uri\":\"\"}", null));
ScimUser scimUser = new ScimUser("eyedee", "user@example.com", "User", "Man");
scimUser.setMeta(new ScimMeta(new Date(System.currentTimeMillis() - (1000 * 60 * 60 * 24)), new Date(System.currentTimeMillis() - (1000 * 60 * 60 * 24)), 0));
scimUser.addEmail("user@example.com");
scimUser.setVerified(true);
when(mockScimUserProvisioning.retrieve("eyedee", currentZoneId)).thenReturn(scimUser);
when(mockScimUserProvisioning.checkPasswordMatches("eyedee", "new_secret", currentZoneId)).thenReturn(true);
MockHttpServletRequestBuilder post = post("/password_change").contentType(APPLICATION_JSON).content("{\"code\":\"emailed_code\",\"new_password\":\"new_secret\"}").accept(APPLICATION_JSON);
SecurityContextHolder.getContext().setAuthentication(new MockAuthentication());
mockMvc.perform(post).andExpect(status().isUnprocessableEntity()).andExpect(content().string(JsonObjectMatcherUtils.matchesJsonObject(new JSONObject().put("error_description", "Your new password cannot be the same as the old password.").put("message", "Your new password cannot be the same as the old password.").put("error", "invalid_password"))));
}
use of org.cloudfoundry.identity.uaa.scim.ScimMeta in project uaa by cloudfoundry.
the class UaaResetPasswordServiceTests method resetPassword_ForcedChange.
@Test
void resetPassword_ForcedChange() {
String userId = "user-id";
ScimUser user = new ScimUser(userId, "username", "firstname", "lastname");
user.setMeta(new ScimMeta(new Date(), new Date(), 0));
user.setPrimaryEmail("foo@example.com");
when(scimUserProvisioning.retrieve(userId, currentZoneId)).thenReturn(user);
uaaResetPasswordService.resetUserPassword(userId, "password");
verify(scimUserProvisioning, times(1)).updatePasswordChangeRequired(userId, false, currentZoneId);
verify(scimUserProvisioning, times(1)).changePassword(userId, null, "password", currentZoneId);
}
use of org.cloudfoundry.identity.uaa.scim.ScimMeta in project uaa by cloudfoundry.
the class UaaResetPasswordServiceTests method setupResetPassword.
private ExpiringCode setupResetPassword(String clientId, String redirectUri) {
ScimUser user = new ScimUser("usermans-id", "userman", "firstName", "lastName");
user.setMeta(new ScimMeta(new Date(System.currentTimeMillis() - (1000 * 60 * 60 * 24)), new Date(System.currentTimeMillis() - (1000 * 60 * 60 * 24)), 0));
user.setPrimaryEmail("user@example.com");
String zoneId = currentZoneId;
when(scimUserProvisioning.retrieve(eq("usermans-id"), eq(zoneId))).thenReturn(user);
ExpiringCode code = new ExpiringCode("code", new Timestamp(System.currentTimeMillis()), "{\"user_id\":\"usermans-id\",\"username\":\"userman\",\"passwordModifiedTime\":null,\"client_id\":\"" + clientId + "\",\"redirect_uri\":\"" + redirectUri + "\"}", null);
when(codeStore.retrieveCode(eq("secret_code"), anyString())).thenReturn(code);
SecurityContext securityContext = mock(SecurityContext.class);
when(securityContext.getAuthentication()).thenReturn(new MockAuthentication());
SecurityContextHolder.setContext(securityContext);
return code;
}
use of org.cloudfoundry.identity.uaa.scim.ScimMeta in project uaa by cloudfoundry.
the class UaaResetPasswordServiceTests method resetPassword_InvalidPasswordException_NewPasswordSameAsOld.
@Test
void resetPassword_InvalidPasswordException_NewPasswordSameAsOld() {
ScimUser user = new ScimUser("user-id", "username", "firstname", "lastname");
user.setMeta(new ScimMeta(new Date(), new Date(), 0));
user.setPrimaryEmail("foo@example.com");
ExpiringCode expiringCode = new ExpiringCode("good_code", new Timestamp(System.currentTimeMillis() + UaaResetPasswordService.PASSWORD_RESET_LIFETIME), "{\"user_id\":\"user-id\",\"username\":\"username\",\"passwordModifiedTime\":null,\"client_id\":\"\",\"redirect_uri\":\"\"}", null);
when(codeStore.retrieveCode("good_code", currentZoneId)).thenReturn(expiringCode);
when(scimUserProvisioning.retrieve("user-id", currentZoneId)).thenReturn(user);
when(scimUserProvisioning.checkPasswordMatches("user-id", "Passwo3dAsOld", currentZoneId)).thenThrow(new InvalidPasswordException("Your new password cannot be the same as the old password.", UNPROCESSABLE_ENTITY));
SecurityContext securityContext = mock(SecurityContext.class);
when(securityContext.getAuthentication()).thenReturn(new MockAuthentication());
SecurityContextHolder.setContext(securityContext);
try {
uaaResetPasswordService.resetPassword(expiringCode, "Passwo3dAsOld");
fail();
} catch (InvalidPasswordException e) {
assertEquals("Your new password cannot be the same as the old password.", e.getMessage());
assertEquals(UNPROCESSABLE_ENTITY, e.getStatus());
}
}
use of org.cloudfoundry.identity.uaa.scim.ScimMeta in project uaa by cloudfoundry.
the class ScimUserEndpointsTests method deleteIsNotAllowedWithWrongVersionInEtag.
@Test
void deleteIsNotAllowedWithWrongVersionInEtag() {
ScimUser exGuy = new ScimUser(null, "deleteme2", "Expendable", "Guy");
exGuy.addEmail("exguy2@imonlyheretobedeleted.com");
exGuy = jdbcScimUserProvisioning.createUser(exGuy, "exguyspassword", identityZone.getId());
final String exGuyId = exGuy.getId();
final ScimMeta exGuyMeta = exGuy.getMeta();
assertThrows(OptimisticLockingFailureException.class, () -> scimUserEndpoints.deleteUser(exGuyId, Integer.toString(exGuyMeta.getVersion() + 1), new MockHttpServletRequest(), new MockHttpServletResponse()));
}
Aggregations