Skip to content

Commit

Permalink
Merge pull request #2441 from opencb/TASK-6183
Browse files Browse the repository at this point in the history
TASK-6183 - Email can't be used as a userId
  • Loading branch information
pfurio authored May 7, 2024
2 parents f8b7020 + 4451b13 commit abe1a4d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ public static void checkValidUserId(String userId) throws CatalogParameterExcept
if (userId.equals(ParamConstants.ANONYMOUS_USER_ID) || userId.equals(ParamConstants.REGISTERED_USERS)) {
throw new CatalogParameterException("User id cannot be one of the reserved OpenCGA users.");
}
if (!userId.matches("^[A-Za-z0-9]([-_.]?[A-Za-z0-9])*$")) {
if (!userId.matches("^[A-Za-z0-9]([-_.@]?[A-Za-z0-9])*$")) {
throw new CatalogParameterException("Invalid user id. Id needs to start by any character and might contain single '-', '_', "
+ "'.', symbols followed by any character or number.");
+ "'.' or '@' symbols followed by any character or number.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.opencb.opencga.core.models.sample.*;
import org.opencb.opencga.core.models.study.*;
import org.opencb.opencga.core.models.user.Account;
import org.opencb.opencga.core.models.user.AuthenticationResponse;
import org.opencb.opencga.core.models.user.User;
import org.opencb.opencga.core.response.OpenCGAResult;
import org.opencb.opencga.core.testclassification.duration.MediumTests;
Expand Down Expand Up @@ -276,6 +277,16 @@ private String getAdminToken() throws CatalogException, IOException {
return catalogManager.getUserManager().loginAsAdmin("admin").getToken();
}

@Test
public void createUserUsingMailAsId() throws CatalogException {
catalogManager.getUserManager().create(new User().setId("hello.mail@mymail.org").setName("Hello")
.setAccount(new Account().setType(Account.AccountType.GUEST)), TestParamConstants.PASSWORD, opencgaToken);
AuthenticationResponse login = catalogManager.getUserManager().login("hello.mail@mymail.org", TestParamConstants.PASSWORD);
assertNotNull(login);
User user = catalogManager.getUserManager().get("hello.mail@mymail.org", new QueryOptions(), login.getToken()).first();
assertEquals("hello.mail@mymail.org", user.getId());
}

@Test
public void getGroupsTest() throws CatalogException {
Group group = new Group("groupId", Arrays.asList("user2", "user3")).setSyncedFrom(new Group.Sync("ldap", "bio"));
Expand Down

0 comments on commit abe1a4d

Please sign in to comment.