Search in sources :

Example 16 with KcRegExec

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));
}
Also used : KcRegExec(org.keycloak.testsuite.cli.KcRegExec) Test(org.junit.Test)

Example 17 with KcRegExec

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());
    }
}
Also used : RealmConfigData(org.keycloak.client.registration.cli.config.RealmConfigData) FileConfigHandler(org.keycloak.client.registration.cli.config.FileConfigHandler) RealmConfigData(org.keycloak.client.registration.cli.config.RealmConfigData) ConfigData(org.keycloak.client.registration.cli.config.ConfigData) KcRegExec(org.keycloak.testsuite.cli.KcRegExec) TempFileResource(org.keycloak.testsuite.util.TempFileResource) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) Test(org.junit.Test)

Example 18 with KcRegExec

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));
}
Also used : KcRegExec(org.keycloak.testsuite.cli.KcRegExec) Test(org.junit.Test)

Example 19 with KcRegExec

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));
}
Also used : KcRegExec(org.keycloak.testsuite.cli.KcRegExec) Test(org.junit.Test)

Example 20 with KcRegExec

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);
    }
}
Also used : FileConfigHandler(org.keycloak.client.registration.cli.config.FileConfigHandler) KcRegExec(org.keycloak.testsuite.cli.KcRegExec) TempFileResource(org.keycloak.testsuite.util.TempFileResource) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation)

Aggregations

KcRegExec (org.keycloak.testsuite.cli.KcRegExec)28 Test (org.junit.Test)24 FileConfigHandler (org.keycloak.client.registration.cli.config.FileConfigHandler)11 TempFileResource (org.keycloak.testsuite.util.TempFileResource)10 File (java.io.File)8 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)8 ConfigData (org.keycloak.client.registration.cli.config.ConfigData)7 AuthServerContainerExclude (org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude)5 RealmConfigData (org.keycloak.client.registration.cli.config.RealmConfigData)4 FileOutputStream (java.io.FileOutputStream)2 OIDCClientRepresentation (org.keycloak.representations.oidc.OIDCClientRepresentation)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Matchers (org.hamcrest.Matchers)1 Assert (org.junit.Assert)1 Assume (org.junit.Assume)1 Before (org.junit.Before)1 OAuth2Constants (org.keycloak.OAuth2Constants)1