8000 SCIM: PATCH on a group does not update meta.lastModified by martin-kanis · Pull Request #54990 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Open
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 @@ -63,6 +63,7 @@ public void patch(R existing, List<PatchOperation> operations) {
}

applyPatch(existing, model, operations);
onUpdate(model, existing);
}

protected void applyPatch(R existing, M model, List<PatchOperation> operations) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.keycloak.testframework.annotations.KeycloakIntegrationTest;
import org.keycloak.testframework.events.AdminEventAssertion;
import org.keycloak.testframework.realm.ClientBuilder;
import org.keycloak.testframework.remote.timeoffset.InjectTimeOffSet;
import org.keycloak.testframework.remote.timeoffset.TimeOffSet;
import org.keycloak.testframework.util.ApiUtil;

import org.junit.jupiter.api.Test;
Expand All @@ -38,6 +40,7 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -50,6 +53,9 @@
@KeycloakIntegrationTest
public class GroupTest extends AbstractScimTest {

@InjectTimeOffSet
TimeOffSet timeOffSet;

@Test
public void testCreate() {
Group expected = new Group();
Expand Down Expand Up @@ -416,6 +422,33 @@ public void testMetaTimestamps() {
}


@Test
public void testPatchUpdatesMetaTimestamps() {
Group group = new Group();
group.setDisplayName(KeycloakModelUtils.generateId());
group = client.groups().create(group);
User user = createScimUser();

Instant lastModifiedBeforePatch = Instant.parse(group.getMeta().getLastModified());

timeOffSet.set(10);
client.groups().patch(group.getId(), PatchRequest.create()
.add("members", "[{\"value\":\"" + user.getId() + "\"}]").build());

Group afterPatch = client.groups().get(group.getId(), List.of("displayName", "members"));
assertEquals(1, afterPatch.getMembers().size());
assertMember(afterPatch.getMembers(), user.getId(), user.getUserName());
assertEquals(group.getMeta().getCreated(), afterPatch.getMeta().getCreated());
assertThat(Instant.parse(afterPatch.getMeta().getLastModified()), greaterThan(lastModifiedBeforePatch));

String filter = ResourceFilter.filter().eq("displayName", afterPatch.getDisplayName()).and()
.gt("meta.lastModified", lastModifiedBeforePatch.toString()).build();
ListResponse<Group> response = client.groups().getAll(filter);
assertEquals(1, response.getTotalResults());
assertEquals(group.getId(), response.getResources().get(0).getId());
assertEquals(afterPatch.getMeta().getLastModified(), response.getResources().get(0).getMeta().getLastModified());
}

@Test
public void testGetWithAttributes() {
Group group = new Group();
Expand Down
Loading
0