fix: admin cli client should set the content when performing a merge (#30539)

closes: #29878

Signed-off-by: Steve Hawkins <shawkins@redhat.com>
This commit is contained in:
Steven Hawkins 2024-06-28 09:56:07 -04:00 committed by GitHub
parent cc2ccc87b0
commit d534860e2b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 3 deletions

View file

@ -29,6 +29,7 @@ import org.keycloak.client.cli.util.HeadersBodyStatus;
import org.keycloak.client.cli.util.HttpUtil; import org.keycloak.client.cli.util.HttpUtil;
import org.keycloak.client.cli.util.OutputFormat; import org.keycloak.client.cli.util.OutputFormat;
import org.keycloak.client.cli.util.ReturnFields; import org.keycloak.client.cli.util.ReturnFields;
import org.keycloak.util.JsonSerialization;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -265,6 +266,11 @@ public abstract class AbstractRequestCmd extends AbstractAuthOptionsCmd {
ReflectionUtil.merge(ctx.getResult(), (ObjectNode) ctxremote.getResult()); ReflectionUtil.merge(ctx.getResult(), (ObjectNode) ctxremote.getResult());
} }
ctx = ctxremote; 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) { if (attrs.size() > 0) {

View file

@ -162,17 +162,28 @@ public class KcAdmUpdateTest extends AbstractAdmCliTest {
// test using merge with file // test using merge with file
exe = KcAdmExec.newBuilder() exe = KcAdmExec.newBuilder()
.argsLine("update clients/" + client.getId() + " --config '" + configFile.getName() + .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())) .stdin(new ByteArrayInputStream("{ \"webOrigins\": [\"http://localhost:8980/myapp\"] }".getBytes()))
.execute(); .execute();
assertExitCodeAndStdErrSize(exe, 0, 0); assertExitCodeAndStdErrSize(exe, 0, 0);
client = JsonSerialization.readValue(exe.stdout(), ClientRepresentation.class); client = JsonSerialization.readValue(exe.stdout(), ClientRepresentation.class);
Assert.assertEquals("webOrigins", Arrays.asList("http://localhost:8980/myapp"), client.getWebOrigins()); 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()); 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());
} }
} }
} }