Skip to content

Commit

Permalink
Improve scim2 Users patch
Browse files Browse the repository at this point in the history
  • Loading branch information
ShehanDinuka committed Aug 11, 2023
1 parent acf7e1d commit 62b3a44
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,8 @@ public SCIMResponse updateWithPATCH(String existingId, String scimObjectString,
List<String> allSimpleMultiValuedAttributes = ResourceManagerUtil.getAllSimpleMultiValuedAttributes(schema);

//get the user from the user core
User oldUser = userManager.getUser(existingId, ResourceManagerUtil.getAllAttributeURIs(schema));
User oldUser = userManager.getUser(existingId, ResourceManagerUtil.getOnlyRequiredAttributesURIs(schema,
SCIMConstants.UserSchemaConstants.USER_NAME, null));
if (oldUser == null) {
throw new NotFoundException("No user with the id : " + existingId + " in the user store.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,9 @@ public void testUpdateWithPATCH(String existingId, String scimObjectString, Stri
abstractResourceManager.when(() -> AbstractResourceManager.getResourceEndpointURL(SCIMConstants.USER_ENDPOINT))
.thenReturn(SCIM2_USER_ENDPOINT);
abstractResourceManager.when(() -> userManager.getUser(existingId,
ResourceManagerUtil.getAllAttributeURIs(schema))).thenReturn(userOld);
ResourceManagerUtil.getOnlyRequiredAttributesURIs(
schema, SCIMConstants.UserSchemaConstants.USER_NAME, null)))
.thenReturn(userOld);
User validatedUser = (User) ServerSideValidator.validateUpdatedSCIMObject(userOld, userNew, schema);
Mockito.when(userManager.updateUser(any(User.class), anyMap(), anyList())).thenReturn(validatedUser);
SCIMResponse scimResponse = userResourceManager.updateWithPATCH(existingId, scimObjectString,
Expand Down Expand Up @@ -1125,7 +1127,9 @@ public void testUpdateWithPATCHProvidedUserManagerHandlerIsNull(String existingI
-> AbstractResourceManager.encodeSCIMException(any(InternalErrorException.class)))
.thenReturn(getEncodeSCIMExceptionObject(new InternalErrorException()));
Mockito.when(userManager.getUser(existingId,
ResourceManagerUtil.getAllAttributeURIs(schema))).thenReturn(userOld);
ResourceManagerUtil.getOnlyRequiredAttributesURIs(
schema, SCIMConstants.UserSchemaConstants.USER_NAME, null)))
.thenReturn(userOld);
User validatedUser = (User) ServerSideValidator.validateUpdatedSCIMObject(userOld, userNew, schema);
Mockito.when(userManager.updateUser(any(User.class), anyMap(), anyList())).thenReturn(validatedUser);
SCIMResponse scimResponse = userResourceManager.updateWithPATCH(existingId, scimObjectString,
Expand Down Expand Up @@ -1165,7 +1169,9 @@ public void testUpdateWithPATCHNoAssociatedUserExitsInTheUserStore(String existi
-> AbstractResourceManager.encodeSCIMException(any(NotFoundException.class)))
.thenReturn(getEncodeSCIMExceptionObject(new NotFoundException()));
Mockito.when(userManager.getUser(existingId,
ResourceManagerUtil.getAllAttributeURIs(schema))).thenReturn(null);
ResourceManagerUtil.getOnlyRequiredAttributesURIs(
schema, SCIMConstants.UserSchemaConstants.USER_NAME, null)))
.thenReturn(null);
User validatedUser = (User) ServerSideValidator.validateUpdatedSCIMObject(userOld, userNew, schema);
Mockito.when(userManager.updateUser(any(User.class), anyMap(), anyList())).thenReturn(validatedUser);
SCIMResponse scimResponse = userResourceManager.updateWithPATCH(existingId, scimObjectString,
Expand Down Expand Up @@ -1200,7 +1206,9 @@ public void testUpdateWithPATCHUpdatedUserResourceIsNull(String existingId, Stri
abstractResourceManager.when(() -> AbstractResourceManager.encodeSCIMException(any(CharonException.class)))
.thenReturn(getEncodeSCIMExceptionObject(new CharonException()));
Mockito.when(userManager.getUser(existingId,
ResourceManagerUtil.getAllAttributeURIs(schema))).thenReturn(userOld);
ResourceManagerUtil.getOnlyRequiredAttributesURIs(
schema, SCIMConstants.UserSchemaConstants.USER_NAME, null)))
.thenReturn(userOld);
Mockito.when(userManager.updateUser(any(User.class), anyMap(), anyList())).thenReturn(null);
SCIMResponse scimResponse = userResourceManager.updateWithPATCH(existingId, scimObjectString,
userManager, attributes, excludeAttributes);
Expand Down Expand Up @@ -1232,8 +1240,9 @@ public void testUpdateWithPATCHBadRequestException(String existingId, String sci
.thenReturn(SCIM2_USER_ENDPOINT);
abstractResourceManager.when(() -> AbstractResourceManager.encodeSCIMException(any(BadRequestException.class)))
.thenReturn(getEncodeSCIMExceptionObject(new BadRequestException()));
Mockito.when(userManager.getUser(existingId,
ResourceManagerUtil.getAllAttributeURIs(schema))).thenThrow(BadRequestException.class);
Mockito.when(userManager.getUser(existingId, ResourceManagerUtil.getOnlyRequiredAttributesURIs(schema,
SCIMConstants.UserSchemaConstants.USER_NAME, null)))
.thenThrow(BadRequestException.class);
SCIMResponse scimResponse = userResourceManager.updateWithPATCH(existingId, scimObjectString,
userManager, attributes, excludeAttributes);
Assert.assertEquals(scimResponse.getResponseStatus(), expectedScimResponseStatus);
Expand Down Expand Up @@ -1306,7 +1315,9 @@ public void testUpdateWithPATCHReplace(String existingId, String scimObjectStrin
abstractResourceManager.when(() -> AbstractResourceManager.getResourceEndpointURL(SCIMConstants.USER_ENDPOINT))
.thenReturn(SCIM2_USER_ENDPOINT);
Mockito.when(userManager.getUser(existingId,
ResourceManagerUtil.getAllAttributeURIs(schema))).thenReturn(userOld);
ResourceManagerUtil.getOnlyRequiredAttributesURIs(
schema, SCIMConstants.UserSchemaConstants.USER_NAME, null)))
.thenReturn(userOld);
User validatedUser = (User) ServerSideValidator.validateUpdatedSCIMObject(userOld, userNew, schema);
Mockito.when(userManager.updateUser(any(User.class), anyMap(), anyList())).thenReturn(validatedUser);
SCIMResponse scimResponse = userResourceManager.updateWithPATCH(existingId, scimObjectString,
Expand Down Expand Up @@ -1348,7 +1359,9 @@ public void testUpdateWithPATCHRemove(String existingId, String scimObjectString
abstractResourceManager.when(() -> AbstractResourceManager.getResourceEndpointURL(SCIMConstants.USER_ENDPOINT))
.thenReturn(SCIM2_USER_ENDPOINT);
Mockito.when(userManager.getUser(existingId,
ResourceManagerUtil.getAllAttributeURIs(schema))).thenReturn(userOld);
ResourceManagerUtil.getOnlyRequiredAttributesURIs(
schema, SCIMConstants.UserSchemaConstants.USER_NAME, null)))
.thenReturn(userOld);
User validatedUser = (User) ServerSideValidator.validateUpdatedSCIMObject(userOld, userNew, schema);
Mockito.when(userManager.updateUser(any(User.class), anyMap(), anyList())).thenReturn(validatedUser);
SCIMResponse scimResponse = userResourceManager.updateWithPATCH(existingId, scimObjectString,
Expand Down

0 comments on commit 62b3a44

Please sign in to comment.