Skip to content

Commit

Permalink
On BuiltinUser create, also show AuthenticatedUser JSON #2418
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed May 17, 2016
1 parent 7fe7040 commit cbe51bc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
3 changes: 3 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/api/BuiltinUsers.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import edu.harvard.iq.dataverse.authorization.providers.builtin.PasswordEncryption;
import edu.harvard.iq.dataverse.authorization.users.ApiToken;
import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser;
import edu.harvard.iq.dataverse.util.json.JsonPrinter;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.logging.Level;
Expand All @@ -24,6 +25,7 @@
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import static edu.harvard.iq.dataverse.util.json.JsonPrinter.json;
import static edu.harvard.iq.dataverse.util.json.JsonPrinter.jsonForAuthUser;

/**
* REST API bean for managing {@link BuiltinUser}s.
Expand Down Expand Up @@ -134,6 +136,7 @@ private Response internalSave(BuiltinUser user, String password, String key) {

JsonObjectBuilder resp = Json.createObjectBuilder();
resp.add("user", json(user));
resp.add("authenticatedUser", jsonForAuthUser(au));
resp.add("apiToken", token.getTokenString());

alr.setInfo("builtinUser:" + user.getUserName() + " authenticatedUser:" + au.getIdentifier() );
Expand Down
8 changes: 1 addition & 7 deletions src/test/java/edu/harvard/iq/dataverse/api/AdminIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static void setUp() {
Response createUserToConvert = UtilIT.createRandomUser();
createUserToConvert.prettyPrint();

idOfUserToConvert = createUserToConvert.body().jsonPath().getLong("data.user.id");
idOfUserToConvert = createUserToConvert.body().jsonPath().getLong("data.authenticatedUser.id");
emailOfUserToConvert = createUserToConvert.body().jsonPath().getString("data.user.email");
usernameOfUserToConvert = UtilIT.getUsernameFromResponse(createUserToConvert);

Expand Down Expand Up @@ -97,12 +97,6 @@ public void testConvertShibUserToBuiltin() throws Exception {

Response infoOfUserToConvert = UtilIT.getAuthenticatedUser(usernameOfUserToConvert, superuserApiToken);
infoOfUserToConvert.prettyPrint();
/**
* https://github.com/IQSS/dataverse/issues/2418 is cropping up again in
* that if we try to reuse this ID below it's the wrong ID (off by one).
* Weird and troubling.
*/
idOfUserToConvert = infoOfUserToConvert.body().jsonPath().getLong("data.id");

String invalidEmailAddress = "invalidEmailAddress";
Response invalidEmailFail = UtilIT.migrateShibToBuiltin(idOfUserToConvert, invalidEmailAddress, superuserApiToken);
Expand Down
14 changes: 5 additions & 9 deletions src/test/java/edu/harvard/iq/dataverse/api/BuiltinUsersIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public void testUserId() {
assertEquals(200, createUserResponse.getStatusCode());

JsonPath createdUser = JsonPath.from(createUserResponse.body().asString());
int userIdFromJsonCreateResponse = createdUser.getInt("data.user." + idKey);
int builtInUserIdFromJsonCreateResponse = createdUser.getInt("data.user." + idKey);
int authenticatedUserIdFromJsonCreateResponse = createdUser.getInt("data.authenticatedUser." + idKey);
String username = createdUser.getString("data.user." + usernameKey);

Response getUserResponse = getUserFromDatabase(username);
Expand All @@ -43,14 +44,9 @@ public void testUserId() {
deleteUserResponse.prettyPrint();

System.out.println(userIdFromDatabase + " was the id from the database");
System.out.println(userIdFromJsonCreateResponse + " was the id from JSON response on create");
/**
* This test is expected to pass on a clean, fresh database but for an
* unknown reason it fails when you load it up with a production
* database from dataverse.harvard.edu. Why? This is what
* https://github.com/IQSS/dataverse/issues/2418 is about.
*/
assertEquals(userIdFromDatabase, userIdFromJsonCreateResponse);
System.out.println(builtInUserIdFromJsonCreateResponse + " was the id of the BuiltinUser from JSON response on create");
System.out.println(authenticatedUserIdFromJsonCreateResponse + " was the id of the AuthenticatedUser from JSON response on create");
assertEquals(userIdFromDatabase, authenticatedUserIdFromJsonCreateResponse);
}

@Test
Expand Down

0 comments on commit cbe51bc

Please sign in to comment.