From d534860e2bf4fd908502c39ce0fddf0377cc92e8 Mon Sep 17 00:00:00 2001 From: Steven Hawkins Date: Fri, 28 Jun 2024 09:56:07 -0400 Subject: [PATCH] fix: admin cli client should set the content when performing a merge (#30539) closes: #29878 Signed-off-by: Steve Hawkins --- .../admin/cli/commands/AbstractRequestCmd.java | 6 ++++++ .../testsuite/cli/admin/KcAdmUpdateTest.java | 17 ++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/integration/client-cli/admin-cli/src/main/java/org/keycloak/client/admin/cli/commands/AbstractRequestCmd.java b/integration/client-cli/admin-cli/src/main/java/org/keycloak/client/admin/cli/commands/AbstractRequestCmd.java index ca166d3fe8..8e4dddcfbd 100644 --- a/integration/client-cli/admin-cli/src/main/java/org/keycloak/client/admin/cli/commands/AbstractRequestCmd.java +++ b/integration/client-cli/admin-cli/src/main/java/org/keycloak/client/admin/cli/commands/AbstractRequestCmd.java @@ -29,6 +29,7 @@ import org.keycloak.client.cli.util.HeadersBodyStatus; import org.keycloak.client.cli.util.HttpUtil; import org.keycloak.client.cli.util.OutputFormat; import org.keycloak.client.cli.util.ReturnFields; +import org.keycloak.util.JsonSerialization; import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; @@ -265,6 +266,11 @@ public abstract class AbstractRequestCmd extends AbstractAuthOptionsCmd { ReflectionUtil.merge(ctx.getResult(), (ObjectNode) ctxremote.getResult()); } ctx = ctxremote; + try { + ctx.setContent(JsonSerialization.writeValueAsString(ctxremote.getResult())); + } catch (IOException e) { + throw new RuntimeException("Could not convert merge result to string " + e.getMessage(), e); + } } if (attrs.size() > 0) { diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/cli/admin/KcAdmUpdateTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/cli/admin/KcAdmUpdateTest.java index f6fd3dd079..0dc59fd09c 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/cli/admin/KcAdmUpdateTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/cli/admin/KcAdmUpdateTest.java @@ -162,17 +162,28 @@ public class KcAdmUpdateTest extends AbstractAdmCliTest { // test using merge with file exe = KcAdmExec.newBuilder() .argsLine("update clients/" + client.getId() + " --config '" + configFile.getName() + - "' -o -s enabled=true -m -f -") + "' -o -m -f -") .stdin(new ByteArrayInputStream("{ \"webOrigins\": [\"http://localhost:8980/myapp\"] }".getBytes())) .execute(); assertExitCodeAndStdErrSize(exe, 0, 0); - client = JsonSerialization.readValue(exe.stdout(), ClientRepresentation.class); Assert.assertEquals("webOrigins", Arrays.asList("http://localhost:8980/myapp"), client.getWebOrigins()); - Assert.assertTrue("enabled is true", client.isEnabled()); + Assert.assertFalse("enabled is false", client.isEnabled()); Assert.assertEquals("redirectUris", Arrays.asList("http://localhost:8980/myapp/*"), client.getRedirectUris()); + + exe = KcAdmExec.newBuilder() + .argsLine("update clients/" + client.getId() + " --config '" + configFile.getName() + + "' -o -s enabled=true -m -f -") + .stdin(new ByteArrayInputStream("{ \"webOrigins\": [\"http://localhost:8980/myapp1\"] }".getBytes())) + .execute(); + + assertExitCodeAndStdErrSize(exe, 0, 0); + + client = JsonSerialization.readValue(exe.stdout(), ClientRepresentation.class); + Assert.assertEquals("webOrigins", Arrays.asList("http://localhost:8980/myapp1"), client.getWebOrigins()); + Assert.assertTrue("enabled is true", client.isEnabled()); } } }