Search in sources :

Example 16 with KcAdmExec

use of org.keycloak.testsuite.cli.KcAdmExec in project keycloak by keycloak.

the class KcAdmTest method testCustomConfigLoginCreateDelete.

@Test
public void testCustomConfigLoginCreateDelete() throws IOException {
    /*
         *  Test user login, create, delete session using a custom config file
         */
    // prepare for loading a config file
    FileConfigHandler handler = initCustomConfigFile();
    try (TempFileResource configFile = new TempFileResource(handler.getConfigFile())) {
        KcAdmExec exe = KcAdmExec.execute("config credentials --server " + serverUrl + " --realm master --user admin --password admin --config '" + configFile.getName() + "'");
        assertExitCodeAndStreamSizes(exe, 0, 0, 1);
        // remember the state of config file
        ConfigData config1 = handler.loadConfig();
        exe = KcAdmExec.execute("create --config '" + configFile.getName() + "' clients -s clientId=test-client -o");
        assertExitCodeAndStdErrSize(exe, 0, 0);
        // check changes to config file
        ConfigData config2 = handler.loadConfig();
        assertFieldsEqualWithExclusions(config1, config2);
        ClientRepresentation client = JsonSerialization.readValue(exe.stdout(), ClientRepresentation.class);
        Assert.assertEquals("clientId", "test-client", client.getClientId());
        exe = KcAdmExec.execute("delete clients/" + client.getId() + " --config '" + configFile.getName() + "'");
        assertExitCodeAndStreamSizes(exe, 0, 0, 0);
        // check changes to config file
        ConfigData config3 = handler.loadConfig();
        assertFieldsEqualWithExclusions(config2, config3);
    }
}
Also used : FileConfigHandler(org.keycloak.client.admin.cli.config.FileConfigHandler) RealmConfigData(org.keycloak.client.admin.cli.config.RealmConfigData) ConfigData(org.keycloak.client.admin.cli.config.ConfigData) KcAdmExec(org.keycloak.testsuite.cli.KcAdmExec) TempFileResource(org.keycloak.testsuite.util.TempFileResource) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) Test(org.junit.Test)

Example 17 with KcAdmExec

use of org.keycloak.testsuite.cli.KcAdmExec in project keycloak by keycloak.

the class KcAdmTest method testCredentialsNoServerWithDefaultConfig.

@Test
public void testCredentialsNoServerWithDefaultConfig() {
    /*
         *  Test without --server specified
         */
    KcAdmExec exe = KcAdmExec.execute("config credentials --realm master --user admin --password admin");
    assertExitCodeAndStreamSizes(exe, 1, 0, 2);
    Assert.assertEquals("stderr first line", "Required option not specified: --server", exe.stderrLines().get(0));
    Assert.assertEquals("try help", "Try '" + CMD + " help config credentials' for more information", exe.stderrLines().get(1));
}
Also used : KcAdmExec(org.keycloak.testsuite.cli.KcAdmExec) Test(org.junit.Test)

Example 18 with KcAdmExec

use of org.keycloak.testsuite.cli.KcAdmExec in project keycloak by keycloak.

the class KcAdmTest method testCredentialsWithNoConfig.

@Test
public void testCredentialsWithNoConfig() {
    /*
         *  Test with --no-config specified which is not supported
         */
    KcAdmExec exe = KcAdmExec.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 : KcAdmExec(org.keycloak.testsuite.cli.KcAdmExec) Test(org.junit.Test)

Example 19 with KcAdmExec

use of org.keycloak.testsuite.cli.KcAdmExec in project keycloak by keycloak.

the class KcAdmTest method testCredentialsServerAndRealmWithDefaultConfig.

@Test
public void testCredentialsServerAndRealmWithDefaultConfig() {
    /*
         *  Test without --server specified
         */
    KcAdmExec exe = KcAdmExec.execute("config credentials --server " + serverUrl + " --realm master");
    assertExitCodeAndStreamSizes(exe, 0, 0, 0);
}
Also used : KcAdmExec(org.keycloak.testsuite.cli.KcAdmExec) Test(org.junit.Test)

Example 20 with KcAdmExec

use of org.keycloak.testsuite.cli.KcAdmExec in project keycloak by keycloak.

the class KcAdmTest method testUserLoginWithCustomConfig.

@Test
public void testUserLoginWithCustomConfig() {
    /*
         *  Test user login using a custom config file
         */
    FileConfigHandler handler = initCustomConfigFile();
    File configFile = new File(handler.getConfigFile());
    try {
        KcAdmExec exe = KcAdmExec.execute("config credentials --server " + serverUrl + " --realm master" + " --user admin --password admin --config '" + configFile.getName() + "'");
        assertExitCodeAndStreamSizes(exe, 0, 0, 1);
        Assert.assertEquals("stderr first line", "Logging into " + serverUrl + " as user admin of realm master", exe.stderrLines().get(0));
        // make sure the config file exists, and has the right content
        ConfigData config = handler.loadConfig();
        Assert.assertEquals("serverUrl", serverUrl, config.getServerUrl());
        Assert.assertEquals("realm", "master", config.getRealm());
        RealmConfigData realmcfg = config.sessionRealmConfigData();
        Assert.assertNotNull("realm config data no null", realmcfg);
        Assert.assertEquals("realm cfg serverUrl", serverUrl, realmcfg.serverUrl());
        Assert.assertEquals("realm cfg realm", "master", realmcfg.realm());
        Assert.assertEquals("client id", "admin-cli", realmcfg.getClientId());
        Assert.assertNotNull("token not null", realmcfg.getToken());
        Assert.assertNotNull("refresh token not null", realmcfg.getRefreshToken());
        Assert.assertNotNull("token expires not null", realmcfg.getExpiresAt());
        Assert.assertNotNull("token expires in future", realmcfg.getExpiresAt() > System.currentTimeMillis());
        Assert.assertNotNull("refresh token expires not null", realmcfg.getRefreshExpiresAt());
        Assert.assertNotNull("refresh token expires in future", realmcfg.getRefreshExpiresAt() > System.currentTimeMillis());
    } finally {
        configFile.delete();
    }
}
Also used : RealmConfigData(org.keycloak.client.admin.cli.config.RealmConfigData) FileConfigHandler(org.keycloak.client.admin.cli.config.FileConfigHandler) RealmConfigData(org.keycloak.client.admin.cli.config.RealmConfigData) ConfigData(org.keycloak.client.admin.cli.config.ConfigData) KcAdmExec(org.keycloak.testsuite.cli.KcAdmExec) File(java.io.File) Test(org.junit.Test)

Aggregations

KcAdmExec (org.keycloak.testsuite.cli.KcAdmExec)27 Test (org.junit.Test)25 FileConfigHandler (org.keycloak.client.admin.cli.config.FileConfigHandler)10 TempFileResource (org.keycloak.testsuite.util.TempFileResource)9 File (java.io.File)8 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)4 ConfigData (org.keycloak.client.admin.cli.config.ConfigData)3 FileOutputStream (java.io.FileOutputStream)2 RealmResource (org.keycloak.admin.client.resource.RealmResource)2 RealmConfigData (org.keycloak.client.admin.cli.config.RealmConfigData)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 StreamSupport (java.util.stream.StreamSupport)1 Matchers.equalTo (org.hamcrest.Matchers.equalTo)1