Skip to content

Commit

Permalink
fix: PR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
anku255 committed Feb 28, 2024
1 parent 9967d6d commit 0574bfe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static BulkImportUser createBulkImportUserFromJSON(Main main, AppIdentifi
}

private static List<String> getParsedUserRoles(JsonObject userData, String[] allUserRoles, List<String> errors) {
JsonArray jsonUserRoles = parseAndValidateFieldType(userData, "roles", ValueType.ARRAY_OF_STRING,
JsonArray jsonUserRoles = parseAndValidateFieldType(userData, "userRoles", ValueType.ARRAY_OF_STRING,
false,
JsonArray.class, errors, ".");

Expand All @@ -80,12 +80,12 @@ private static List<String> getParsedUserRoles(JsonObject userData, String[] all

// We already know that the jsonUserRoles is an array of non-empty strings, we will normalise each role now
List<String> userRoles = new ArrayList<>();
jsonUserRoles.forEach(role -> validateAndNormaliseUserRole(role.getAsString(), allUserRoles, errors));
jsonUserRoles.forEach(role -> userRoles.add(validateAndNormaliseUserRole(role.getAsString(), allUserRoles, errors)));
return userRoles;
}

private static List<TotpDevice> getParsedTotpDevices(JsonObject userData, List<String> errors) {
JsonArray jsonTotpDevices = parseAndValidateFieldType(userData, "totp", ValueType.ARRAY_OF_OBJECT, false, JsonArray.class, errors, ".");
JsonArray jsonTotpDevices = parseAndValidateFieldType(userData, "totpDevices", ValueType.ARRAY_OF_OBJECT, false, JsonArray.class, errors, ".");
if (jsonTotpDevices == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void shouldThrow400Error() throws Exception {
{
try {
JsonObject request = new JsonParser()
.parse("{\"users\":[{\"externalUserId\":[],\"userMetaData\":[],\"roles\":{},\"totp\":{}}]}")
.parse("{\"users\":[{\"externalUserId\":[],\"userMetaData\":[],\"userRoles\":{},\"totpDevices\":{}}]}")
.getAsJsonObject();
HttpRequestForTesting.sendJsonPOSTRequest(process.getProcess(), "",
"http://localhost:3567/bulk-import/users",
Expand All @@ -150,12 +150,12 @@ public void shouldThrow400Error() throws Exception {
String responseString = getResponseMessageFromError(e.getMessage());
assertEquals(400, e.statusCode);
assertEquals(responseString,
"{\"error\":\"" + genericErrMsg + "\",\"users\":[{\"index\":0,\"errors\":[\"externalUserId should be of type string.\",\"roles should be of type array of string.\",\"totp should be of type array of object.\",\"loginMethods is required.\"]}]}");
"{\"error\":\"" + genericErrMsg + "\",\"users\":[{\"index\":0,\"errors\":[\"externalUserId should be of type string.\",\"userRoles should be of type array of string.\",\"totpDevices should be of type array of object.\",\"loginMethods is required.\"]}]}");
}
// Invalid role (does not exist)
try {
JsonObject request = new JsonParser()
.parse("{\"users\":[{\"roles\":[\"role5\"]}]}")
.parse("{\"users\":[{\"userRoles\":[\"role5\"]}]}")
.getAsJsonObject();
HttpRequestForTesting.sendJsonPOSTRequest(process.getProcess(), "",
"http://localhost:3567/bulk-import/users",
Expand Down

0 comments on commit 0574bfe

Please sign in to comment.