Skip to content

Commit

Permalink
make countOfIdentifier case insensitive #3575
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Apr 25, 2019
1 parent 0a0dc25 commit 392d26e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/main/java/edu/harvard/iq/dataverse/api/BuiltinUsers.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ private Response internalSave(BuiltinUser user, String password, String key) {
user.updateEncryptedPassword(PasswordEncryption.get().encrypt(password), PasswordEncryption.getLatestVersionNumber());
}

// Make sure the identifier is unique
if ( (builtinUserSvc.findByUserName(user.getUserName()) != null)
|| ( authSvc.identifierExists(user.getUserName())) ) {
// Make sure the identifier is unique, case insensitive. "DATAVERSEADMIN" is not allowed to be created if "dataverseAdmin" exists.
if ((builtinUserSvc.findByUserName(user.getUserName()) != null)
|| (authSvc.identifierExists(user.getUserName()))) {
return error(Status.BAD_REQUEST, "username '" + user.getUserName() + "' already exists");
}
user = builtinUserSvc.save(user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
@NamedQuery( name="AuthenticatedUser.findByEmail",
query="select au from AuthenticatedUser au WHERE LOWER(au.email)=LOWER(:email)"),
@NamedQuery( name="AuthenticatedUser.countOfIdentifier",
query="SELECT COUNT(a) FROM AuthenticatedUser a WHERE a.userIdentifier=:identifier"),
query="SELECT COUNT(a) FROM AuthenticatedUser a WHERE LOWER(a.userIdentifier)=LOWER(:identifier)"),
@NamedQuery( name="AuthenticatedUser.filter",
query="select au from AuthenticatedUser au WHERE ("
+ "au.userIdentifier like :query OR "
Expand Down
11 changes: 8 additions & 3 deletions src/test/java/edu/harvard/iq/dataverse/api/UsersIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import javax.json.JsonObjectBuilder;
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
import static javax.ws.rs.core.Response.Status.CREATED;
import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
import static javax.ws.rs.core.Response.Status.NOT_FOUND;
import static javax.ws.rs.core.Response.Status.OK;
import static javax.ws.rs.core.Response.Status.UNAUTHORIZED;
Expand Down Expand Up @@ -338,8 +337,14 @@ public void testUsernameCaseSensitivity() {
Response createUppercaseUser = UtilIT.createUser(uppercaseUsername, randomEmailForUppercaseuser);
createUppercaseUser.prettyPrint();
createUppercaseUser.then().assertThat()
// TODO: consider returning "BAD REQUEST" (400) instead of a 500.
.statusCode(INTERNAL_SERVER_ERROR.getStatusCode());
.statusCode(BAD_REQUEST.getStatusCode())
/**
* Technically, it's the lowercase version that exists but the
* point gets across. There's currently no way to bubble up the
* exact username it's in conflict with, even if we wanted to.
*/
.body("message", equalTo("username '" + uppercaseUsername + "' already exists"));
;
}

private Response convertUserFromBcryptToSha1(long idOfBcryptUserToConvert, String password) {
Expand Down

0 comments on commit 392d26e

Please sign in to comment.