use of org.keycloak.testsuite.cli.KcRegExec in project keycloak by keycloak.
the class KcRegTest method testCredentialsWithNoConfig.
@Test
public void testCredentialsWithNoConfig() {
/*
* Test with --no-config specified which is not supported
*/
KcRegExec exe = KcRegExec.execute("config credentials --no-config --server " + serverUrl + " --realm master --user admin --password admin");
assertExitCodeAndStreamSizes(exe, 1, 0, 2);
Assert.assertEquals("stderr first line", "Unsupported option: --no-config", exe.stderrLines().get(0));
Assert.assertEquals("try help", "Try '" + CMD + " help config credentials' for more information", exe.stderrLines().get(1));
}
use of org.keycloak.testsuite.cli.KcRegExec in project keycloak by keycloak.
the class KcRegUpdateTokenTest method testUpdateToken.
@Test
public void testUpdateToken() throws IOException {
FileConfigHandler handler = initCustomConfigFile();
ConfigUtil.setHandler(handler);
try (TempFileResource configFile = new TempFileResource(handler.getConfigFile())) {
KcRegExec exe = execute("config credentials --config '" + configFile.getName() + "' --server " + serverUrl + " --realm master --user admin --password admin");
assertExitCodeAndStreamSizes(exe, 0, 0, 1);
// read current registration access token
ConfigData data = ConfigUtil.loadConfig();
RealmConfigData rdata = data.getRealmConfigData(serverUrl, "test");
Assert.assertNull("realm info set", rdata);
// update registration access token
exe = execute("update-token --config '" + configFile.getName() + "' reg-cli-secret-direct --server " + serverUrl + " --realm test --user user1 --password userpass");
assertExitCodeAndStreamSizes(exe, 0, 0, 1);
// read current registration token
data = ConfigUtil.loadConfig();
rdata = data.getRealmConfigData(serverUrl, "test");
Assert.assertEquals("current session realm unchanged", "master", data.getRealm());
Assert.assertNotNull("realm info set", rdata);
Assert.assertNull("on the fly login was transient", rdata.getToken());
Assert.assertNotNull("client info has registration access token", rdata.getClients().get("reg-cli-secret-direct"));
// use --no-config and on-the-fly auth
exe = execute("update-token reg-cli-secret-direct --no-config --server " + serverUrl + " --realm test --user user1 --password userpass");
assertExitCodeAndStreamSizes(exe, 0, 1, 1);
// save the token
String token = exe.stdoutLines().get(0);
// test that the token works
exe = execute("get reg-cli-secret-direct --no-config --server " + serverUrl + " --realm test -t " + token);
assertExitCodeAndStdErrSize(exe, 0, 0);
ClientRepresentation client = JsonSerialization.readValue(exe.stdout(), ClientRepresentation.class);
Assert.assertEquals("client representation returned", "reg-cli-secret-direct", client.getClientId());
}
}
use of org.keycloak.testsuite.cli.KcRegExec in project keycloak by keycloak.
the class KcRegConfigTest method testNoConfigOption.
@Test
public void testNoConfigOption() throws IOException {
KcRegExec exe = execute("config registration-token --no-config --server http://localhost:8080/auth --realm test --client my_client --delete");
assertExitCodeAndStreamSizes(exe, 1, 0, 2);
Assert.assertEquals("stderr first line", "Unsupported option: --no-config", exe.stderrLines().get(0));
Assert.assertEquals("try help", "Try '" + CMD + " help config registration-token' for more information", exe.stderrLines().get(1));
exe = execute("config initial-token --no-config --server http://localhost:8080/auth --realm test --delete");
assertExitCodeAndStreamSizes(exe, 1, 0, 2);
Assert.assertEquals("stderr first line", "Unsupported option: --no-config", exe.stderrLines().get(0));
Assert.assertEquals("try help", "Try '" + CMD + " help config initial-token' for more information", exe.stderrLines().get(1));
}
use of org.keycloak.testsuite.cli.KcRegExec in project keycloak by keycloak.
the class KcRegTest method testCredentialsNoRealmWithDefaultConfig.
@Test
public void testCredentialsNoRealmWithDefaultConfig() {
/*
* Test without --server specified
*/
KcRegExec exe = execute("config credentials --server " + serverUrl + " --user admin --password admin");
assertExitCodeAndStreamSizes(exe, 1, 0, 2);
Assert.assertEquals("stderr first line", "Required option not specified: --realm", exe.stderrLines().get(0));
Assert.assertEquals("try help", "Try '" + CMD + " help config credentials' for more information", exe.stderrLines().get(1));
}
use of org.keycloak.testsuite.cli.KcRegExec in project keycloak by keycloak.
the class KcRegTest method testCreateWithAllowedHostsWithoutAuthentication.
private void testCreateWithAllowedHostsWithoutAuthentication(String realm, boolean useConfig) throws IOException {
addLocalhostToAllowedHosts(realm);
FileConfigHandler handler = initCustomConfigFile();
try (TempFileResource configFile = new TempFileResource(handler.getConfigFile())) {
KcRegExec exe = execute("create " + (useConfig ? ("--config '" + configFile.getAbsolutePath()) + "'" : "--no-config") + " --server " + serverUrl + " --realm " + realm + " -s clientId=test-client -o");
assertExitCodeAndStdErrSize(exe, 0, 0);
ClientRepresentation client = JsonSerialization.readValue(exe.stdout(), ClientRepresentation.class);
Assert.assertEquals("clientId", "test-client", client.getClientId());
Assert.assertNotNull("registrationAccessToken", client.getRegistrationAccessToken());
exe = execute("delete test-client " + (useConfig ? ("--config '" + configFile.getAbsolutePath()) + "'" : "--no-config") + " --server " + serverUrl + " --realm " + realm + " -t " + client.getRegistrationAccessToken());
assertExitCodeAndStreamSizes(exe, 0, 0, 0);
}
}
Aggregations