-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support email validation and email case-insensitive matching for user…
… admin (#2642) * Support email validation and email case-insensitive matching * One more email comparison case
- Loading branch information
1 parent
a81bf1e
commit d126c98
Showing
5 changed files
with
98 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -500,10 +500,20 @@ public void testAddAndRemoveUser() { | |
|
||
String user = "[email protected]"; | ||
String userName = "test_user6"; | ||
|
||
UserAdminService service = new UserAdminService(Integer.toString(operatorId), TEST_GROUP); | ||
UserRequest badUserRequest = new UserRequest(List.of(new UserRequest.User(user, userName, null, | ||
List.of("bad_role"))), null); | ||
try { | ||
service.addAndRemoveUsers(badUserRequest); | ||
Assert.fail("UserAdminService.addUser should fail with bad role names"); | ||
} catch (Exception e) { | ||
Assert.assertTrue(e.getMessage().contains("Invalid roles for study group")); | ||
} | ||
|
||
UserRequest userRequest = new UserRequest(List.of(new UserRequest.User(user, userName, null, | ||
List.of(role1))), null); | ||
|
||
UserAdminService service = new UserAdminService(Integer.toString(operatorId), TEST_GROUP); | ||
try { | ||
service.addAndRemoveUsers(userRequest); | ||
} catch (Exception e) { | ||
|
@@ -564,12 +574,12 @@ public void testAddAndRemoveUser() { | |
try { | ||
service.addAndRemoveUsers(removeReq); | ||
} catch (Exception e) { | ||
Assert.fail("Exception from UserAdminService.removeUser: " + getStackTrace(e)); | ||
Assert.fail("Exception from UserAdminService.addAndRemoveUsers: " + getStackTrace(e)); | ||
} | ||
|
||
try { | ||
UserAdminService.verifyUserByEmail(user, groupId); | ||
Assert.fail("UserAdminService.removeUser failed to remove user"); | ||
Assert.fail("UserAdminService.addAndRemoveUsers failed to remove user"); | ||
} catch (Exception e) { | ||
Assert.assertTrue(e.getMessage().contains("Invalid user")); | ||
} | ||
|
@@ -598,6 +608,7 @@ public void testAddExistingUser() { | |
int operatorId = setupAdmin("[email protected]", new ArrayList<>(rolesToId.values()), groupId); | ||
|
||
String user = "[email protected]"; | ||
String userVariation = "[email protected]"; | ||
String userName = "test_user7"; | ||
UserRequest addUserRequest = new UserRequest(List.of(new UserRequest.User(user, userName, null, | ||
roles)), null); | ||
|
@@ -606,27 +617,27 @@ public void testAddExistingUser() { | |
try { | ||
service.addAndRemoveUsers(addUserRequest); | ||
} catch (Exception e) { | ||
Assert.fail("Exception from UserAdminService.addUser: " + getStackTrace(e)); | ||
Assert.fail("Exception from UserAdminService.addAndRemoveUsers: " + getStackTrace(e)); | ||
} | ||
|
||
UserRequest removeReq = new UserRequest(null, List.of(user)); | ||
try { | ||
service.addAndRemoveUsers(removeReq); | ||
} catch (Exception e) { | ||
Assert.fail("Exception from UserAdminService.removeUser: " + getStackTrace(e)); | ||
Assert.fail("Exception from UserAdminService.addAndRemoveUsers: " + getStackTrace(e)); | ||
} | ||
|
||
// add user back to test the inactive to active transition | ||
try { | ||
service.addAndRemoveUsers(addUserRequest); | ||
} catch (Exception e) { | ||
Assert.fail("Exception from UserAdminService.addUser: " + getStackTrace(e)); | ||
Assert.fail("Exception from UserAdminService.addAndRemoveUsers: " + getStackTrace(e)); | ||
} | ||
|
||
// try to add again | ||
try { | ||
service.addAndRemoveUsers(addUserRequest); | ||
Assert.fail("UserAdminService.addUser should fail to add an existing study user"); | ||
Assert.fail("UserAdminService.addAndRemoveUsers should fail to add an existing study user"); | ||
} catch (Exception e) { | ||
Assert.assertTrue(e.getMessage().contains("Already has roles in study")); | ||
} | ||
|
@@ -640,14 +651,22 @@ public void testAddExistingUser() { | |
try { | ||
service.addAndRemoveUsers(addUserRequest); | ||
} catch (Exception e) { | ||
Assert.fail("Exception from UserAdminService.addUser: " + getStackTrace(e)); | ||
Assert.fail("Exception from UserAdminService.addAndRemoveUsers: " + getStackTrace(e)); | ||
} | ||
|
||
// cleanup | ||
// cleanup (with case variation on email address) | ||
UserRequest removeReq2 = new UserRequest(null, List.of(userVariation)); | ||
try { | ||
service.addAndRemoveUsers(removeReq); | ||
service.addAndRemoveUsers(removeReq2); | ||
} catch (Exception e) { | ||
Assert.fail("Exception from UserAdminService.removeUser: " + getStackTrace(e)); | ||
Assert.fail("Exception from UserAdminService.addAndRemoveUsers: " + getStackTrace(e)); | ||
} | ||
|
||
try { | ||
service.addAndRemoveUsers(removeReq2); | ||
Assert.fail("UserAdminService.addAndRemoveUsers should fail to a remove study user that does not exist"); | ||
} catch (Exception e) { | ||
Assert.assertTrue(e.getMessage().contains("Invalid user for study group")); | ||
} | ||
} | ||
|
||
|
@@ -693,6 +712,27 @@ public void testGetStudyGroup() { | |
} | ||
} | ||
|
||
@Test | ||
public void testValidateEmailFormat() { | ||
try { | ||
UserAdminService.validateEmailFormat("[email protected]"); | ||
} catch (Exception e) { | ||
Assert.fail("Exception from UserAdminService.validateEmailFormat: " + e.toString()); | ||
} | ||
try { | ||
UserAdminService.validateEmailFormat("justjoe"); | ||
Assert.fail("UserAdminService.validateEmailFormat should fail with bad email address: justjoe"); | ||
} catch (Exception e) { | ||
Assert.assertTrue(e.getMessage().contains("Invalid email address format")); | ||
} | ||
try { | ||
UserAdminService.validateEmailFormat("joe@gmail"); | ||
Assert.fail("UserAdminService.validateEmailFormat should fail with bad email address: joe@gmail"); | ||
} catch (Exception e) { | ||
Assert.assertTrue(e.getMessage().contains("Invalid email address format")); | ||
} | ||
} | ||
|
||
private int createAdminUser(String email, int adminRoleId) { | ||
int userId = createTestUser(email, adminRoleId); | ||
int groupId = UserAdminService.verifyStudyGroup(TEST_GROUP); | ||
|