@Test public void validateOriginAndExternalIDDuringCreateAndUpdate() { String origin = "test"; String externalId = "testId"; ScimUser user = new ScimUser(null, "*****@*****.**", "Jo", "User"); user.setOrigin(origin); user.setExternalId(externalId); user.addEmail("*****@*****.**"); ScimUser created = db.createUser(user, "j7hyqpassX"); assertEquals("*****@*****.**", created.getUserName()); assertNotNull(created.getId()); assertNotSame(user.getId(), created.getId()); Map<String, Object> map = template.queryForMap("select * from users where id=?", created.getId()); assertEquals(user.getUserName(), map.get("userName")); assertEquals(user.getUserType(), map.get(UaaAuthority.UAA_USER.getUserType())); assertNull(created.getGroups()); assertEquals(origin, created.getOrigin()); assertEquals(externalId, created.getExternalId()); String origin2 = "test2"; String externalId2 = "testId2"; created.setOrigin(origin2); created.setExternalId(externalId2); ScimUser updated = db.update(created.getId(), created); assertEquals(origin2, updated.getOrigin()); assertEquals(externalId2, updated.getExternalId()); }
@Test(expected = InvalidScimResourceException.class) public void updateWithBadUsernameIsError() { ScimUser jo = new ScimUser(null, "jo$ephine", "Jo", "NewUser"); jo.addEmail("*****@*****.**"); jo.setVersion(1); ScimUser joe = db.update(JOE_ID, jo); assertEquals("joe", joe.getUserName()); }
@Test(expected = OptimisticLockingFailureException.class) public void updateWithWrongVersionIsError() { ScimUser jo = new ScimUser(null, "josephine", "Jo", "NewUser"); jo.addEmail("*****@*****.**"); jo.setVersion(1); ScimUser joe = db.update(JOE_ID, jo); assertEquals("joe", joe.getUserName()); }
@Test public void updateWithEmptyPhoneNumberWorks() { ScimUser jo = new ScimUser(null, "josephine", "Jo", "NewUser"); PhoneNumber emptyNumber = new PhoneNumber(); jo.addEmail("*****@*****.**"); jo.setPhoneNumbers(Arrays.asList(emptyNumber)); ScimUser joe = db.update(JOE_ID, jo); }
@Test public void testUserVerifiedThroughUpdate() { String tmpUserIdString = createUserForDelete(); ScimUser user = db.retrieve(tmpUserIdString); assertFalse(user.isVerified()); user.setVerified(true); user = db.update(tmpUserIdString, user); assertTrue(user.isVerified()); removeUser(tmpUserIdString); }
@Test public void updateCannotModifyGroups() { ScimUser jo = new ScimUser(null, "josephine", "Jo", "NewUser"); jo.addEmail("*****@*****.**"); jo.setGroups(Collections.singleton(new Group(null, "dash/user"))); ScimUser joe = db.update(JOE_ID, jo); assertEquals(JOE_ID, joe.getId()); assertNull(joe.getGroups()); }
@Test(expected = ScimResourceNotFoundException.class) public void testUserUpdateInvalidUserId() { String tmpUserIdString = createUserForDelete(); try { ScimUser user = db.retrieve(tmpUserIdString); assertFalse(user.isVerified()); user.setVerified(true); user = db.update("-1-1-1", user); assertTrue(user.isVerified()); } finally { removeUser(tmpUserIdString); } }
@Test public void testCreateUserCheckSalt() throws Exception { ScimUser scimUser = new ScimUser("user-id-3", "*****@*****.**", "User", "Example"); ScimUser.Email email = new ScimUser.Email(); email.setValue("*****@*****.**"); scimUser.setEmails(Arrays.asList(email)); scimUser.setPassword("password"); scimUser.setSalt("salt"); scimUser = db.create(scimUser); assertNotNull(scimUser); assertEquals("salt", scimUser.getSalt()); scimUser.setSalt("newsalt"); scimUser = db.update(scimUser.getId(), scimUser); assertNotNull(scimUser); assertEquals("newsalt", scimUser.getSalt()); }
@Test public void updateModifiesExpectedData() { ScimUser jo = new ScimUser(null, "josephine", "Jo", "NewUser"); jo.addEmail("*****@*****.**"); jo.setUserType(UaaAuthority.UAA_ADMIN.getUserType()); ScimUser joe = db.update(JOE_ID, jo); // Can change username assertEquals("josephine", joe.getUserName()); assertEquals("*****@*****.**", joe.getPrimaryEmail()); assertEquals("Jo", joe.getGivenName()); assertEquals("NewUser", joe.getFamilyName()); assertEquals(1, joe.getVersion()); assertEquals(JOE_ID, joe.getId()); assertNull(joe.getGroups()); }