Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Get custom schema fix #225

Merged
merged 3 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ default String removeValueFilterFromAttributeNotation(final String fullAttribute
}

static boolean isCustomSchema(final String schemaId) {
return schemaId.matches(SCHEMA_PATTERN.toString());
return !isCoreSchema(schemaId) && schemaId.matches(SCHEMA_PATTERN.toString());
}

static boolean isCoreSchema(final String schemaId) {
Expand Down
69 changes: 66 additions & 3 deletions scimono-server/src/test/java/com/sap/scimono/api/UsersTest.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,52 @@
package com.sap.scimono.api;

import com.sap.scimono.SCIMApplication;
import com.sap.scimono.exception.InvalidInputException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;

import java.util.UUID;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sap.scimono.SCIMApplication;
import com.sap.scimono.callback.schemas.SchemasCallback;
import com.sap.scimono.callback.users.UsersCallback;
import com.sap.scimono.entity.patch.PatchBody;
import com.sap.scimono.entity.patch.PatchOperation;
import com.sap.scimono.exception.InvalidInputException;

public class UsersTest {

private Users users;

private ObjectMapper mapper;
private SchemasCallback schemasCallbackMock = Mockito.mock(SchemasCallback.class, Mockito.CALLS_REAL_METHODS);
private UsersCallback usersCallbackMock = Mockito.mock(UsersCallback.class, Mockito.CALLS_REAL_METHODS);

ArgumentCaptor<String> userIdCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<PatchBody> patchBodyCaptor = ArgumentCaptor.forClass(PatchBody.class);
private final String PATCH_OP_SCHEMA = "urn:ietf:params:scim:api:messages:2.0:PatchOp";

@Before
public void setup() {
mapper = new ObjectMapper();
SCIMApplication scimApplication = new SCIMApplication() {

@Override
public SchemasCallback getSchemasCallback() {
return schemasCallbackMock;
}

@Override
public UsersCallback getUsersCallback() {
return usersCallbackMock;
}
};
users = new Users(scimApplication, null);
}
Expand All @@ -31,4 +63,35 @@ public void testPatchUserWithEmptyBody() {
users.patchUser(userId, null);
}

@Test
public void testPatchUserActivate() throws JsonProcessingException {
Mockito.doNothing().when(usersCallbackMock).patchUser(Mockito.any(), Mockito.any(), Mockito.any());
Mockito.doReturn(new ArrayList<>()).when(schemasCallbackMock).getCustomSchemas();
String userId = String.valueOf(UUID.randomUUID());
Set<String> schemas = new HashSet<>();
schemas.add(PATCH_OP_SCHEMA);


JsonNode valueTrue = getValueTrue();
PatchOperation patchOperation1 = new PatchOperation.Builder()
.setOp(PatchOperation.Type.ADD)
.setPath("active")
.setValue(valueTrue)
.build();
PatchBody patchBody = new PatchBody.Builder()
.addOperation(patchOperation1)
.setSchemas(schemas)
.build();
users.patchUser(userId, patchBody);

Mockito.verify(usersCallbackMock).patchUser(userIdCaptor.capture(), patchBodyCaptor.capture(), Mockito.any());
Assert.assertEquals(userId, userIdCaptor.getValue());
Assert.assertEquals(patchBody, patchBodyCaptor.getValue());
}

private JsonNode getValueTrue() throws JsonProcessingException {
JsonNode boolValue = mapper.readTree("true");
return boolValue;
}

}
Loading