mirror of
https://github.com/keycloak/keycloak.git
synced 2026-01-09 23:12:06 -03:30
Updating a client with rollback in a test doesn't reset all values (#38244)
Closes #38243 Signed-off-by: stianst <stianst@gmail.com>
This commit is contained in:
parent
be818502ad
commit
3cdb8d12ae
@ -34,7 +34,11 @@ public class ManagedClient extends ManagedTestResource {
|
||||
|
||||
public void updateWithCleanup(ManagedClient.ClientUpdate... updates) {
|
||||
ClientRepresentation rep = admin().toRepresentation();
|
||||
cleanup().resetToOriginalRepresentation(rep);
|
||||
|
||||
// TODO Admin v2 - Setting a field to `null` is ignored when updating the client (for example `adminUrl`), which
|
||||
// makes it impossible to reset to the original. For now we are just re-creating the client by marking it as dirty
|
||||
// cleanup().resetToOriginalRepresentation(rep);
|
||||
dirty();
|
||||
|
||||
ClientConfigBuilder configBuilder = ClientConfigBuilder.update(rep);
|
||||
for (ManagedClient.ClientUpdate update : updates) {
|
||||
@ -44,8 +48,10 @@ public class ManagedClient extends ManagedTestResource {
|
||||
ClientRepresentation updated = configBuilder.build();
|
||||
admin().update(updated);
|
||||
|
||||
ClientRepresentation original = cleanup().getOriginalRepresentation();
|
||||
updated.getAttributes().keySet().stream().filter(k -> !original.getAttributes().containsKey(k)).forEach(k -> original.getAttributes().put(k, ""));
|
||||
// TODO It's possible to delete attributes by setting their value to an empty string, but due to the above this
|
||||
// is not a complete solution to resetting to the original
|
||||
// ClientRepresentation original = cleanup().getOriginalRepresentation();
|
||||
// updated.getAttributes().keySet().stream().filter(k -> !original.getAttributes().containsKey(k)).forEach(k -> original.getAttributes().put(k, ""));
|
||||
}
|
||||
|
||||
public ManagedClientCleanup cleanup() {
|
||||
|
||||
@ -11,6 +11,8 @@ import org.keycloak.testframework.realm.ClientConfig;
|
||||
import org.keycloak.testframework.realm.ClientConfigBuilder;
|
||||
import org.keycloak.testframework.realm.ManagedClient;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@KeycloakIntegrationTest
|
||||
@TestMethodOrder(MethodOrderer.MethodName.class)
|
||||
public class ClientRollbackTest {
|
||||
@ -19,19 +21,22 @@ public class ClientRollbackTest {
|
||||
ManagedClient client;
|
||||
|
||||
@Test
|
||||
public void testAddAttributeWithRollback() {
|
||||
public void test1UpdateWithRollback() {
|
||||
client.updateWithCleanup(u -> u.attribute("one", "two").attribute("two", "two"));
|
||||
|
||||
ClientRepresentation rep = client.admin().toRepresentation();
|
||||
Assertions.assertEquals("two", rep.getAttributes().get("one"));
|
||||
Assertions.assertTrue(rep.getAttributes().containsKey("two"));
|
||||
client.updateWithCleanup(u -> u.adminUrl("http://something"));
|
||||
client.updateWithCleanup(u -> u.redirectUris("http://something"));
|
||||
client.updateWithCleanup(u -> u.attribute("three", "three"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttributeNotSet() {
|
||||
ClientRepresentation rep = client.admin().toRepresentation();
|
||||
Assertions.assertEquals("one", rep.getAttributes().get("one"));
|
||||
Assertions.assertFalse(rep.getAttributes().containsKey("two"));
|
||||
public void test2CheckRollback() {
|
||||
ClientRepresentation current = client.admin().toRepresentation();
|
||||
|
||||
Assertions.assertEquals("one", current.getAttributes().get("one"));
|
||||
Assertions.assertFalse(current.getAttributes().containsKey("two"));
|
||||
Assertions.assertFalse(current.getAttributes().containsKey("three"));
|
||||
Assertions.assertNull(current.getAdminUrl());
|
||||
Assertions.assertTrue(current.getRedirectUris().isEmpty());
|
||||
}
|
||||
|
||||
public static class ClientWithSingleAttribute implements ClientConfig {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user