Search in sources :

Example 26 with KcRegExec

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

the class KcRegTest method testUserLoginWithCustomConfig.

@Test
@AuthServerContainerExclude(AuthServer.REMOTE)
public void testUserLoginWithCustomConfig() {
    /*
         *  Test user login using a custom config file
         */
    FileConfigHandler handler = initCustomConfigFile();
    File configFile = new File(handler.getConfigFile());
    try {
        KcRegExec exe = 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());
        Assert.assertTrue("clients is empty", realmcfg.getClients().isEmpty());
    } finally {
        configFile.delete();
    }
}
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) File(java.io.File) AuthServerContainerExclude(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude) Test(org.junit.Test)

Example 27 with KcRegExec

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

the class KcRegTest method testCredentialsServerAndRealmWithDefaultConfig.

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

Example 28 with KcRegExec

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

the class KcRegTest method testBadOption.

@Test
public void testBadOption() {
    /*
         *  Test sub-command execution with non-existent option
         */
    KcRegExec exe = execute("get my_client --nonexistent");
    assertExitCodeAndStreamSizes(exe, 1, 0, 2);
    Assert.assertEquals("stderr first line", "Invalid option: --nonexistent", exe.stderrLines().get(0));
    Assert.assertEquals("try help", "Try '" + CMD + " help get' for more information", exe.stderrLines().get(1));
}
Also used : KcRegExec(org.keycloak.testsuite.cli.KcRegExec) Test(org.junit.Test)

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