Search in sources :

Example 11 with KcRegExec

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

the class KcRegTest method testUserLoginWithDefaultConfig.

@Test
@AuthServerContainerExclude(AuthServer.REMOTE)
public void testUserLoginWithDefaultConfig() {
    /*
         *  Test most basic user login, using the default admin-cli as a client
         */
    KcRegExec exe = execute("config credentials --server " + serverUrl + " --realm master --user admin --password admin");
    assertExitCodeAndStreamSizes(exe, 0, 0, 1);
    Assert.assertEquals("stderr first line", "Logging into " + serverUrl + " as user admin of realm master", exe.stderrLines().get(0));
}
Also used : KcRegExec(org.keycloak.testsuite.cli.KcRegExec) AuthServerContainerExclude(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude) Test(org.junit.Test)

Example 12 with KcRegExec

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

the class KcRegTest method testUserLoginWithDefaultConfigInteractive.

@Test
public void testUserLoginWithDefaultConfigInteractive() throws IOException {
    if (!runIntermittentlyFailingTests()) {
        System.out.println("TEST SKIPPED - This test currently suffers from intermittent failures. Use -Dtest.intermittent=true to run it.");
        return;
    }
    KcRegExec exe = KcRegExec.newBuilder().argsLine("config credentials --server " + serverUrl + " --realm master --user admin").executeAsync();
    exe.waitForStdout("Enter password: ");
    exe.sendToStdin("admin" + EOL);
    exe.waitCompletion();
    assertExitCodeAndStreamSizes(exe, 0, 1, 1);
    Assert.assertEquals("stderr first line", "Logging into " + serverUrl + " as user admin of realm master", exe.stderrLines().get(0));
    /*
         *  Run the test one more time with stdin redirect
         */
    File tmpFile = new File(KcRegExec.WORK_DIR + "/" + UUID.randomUUID().toString() + ".tmp");
    try {
        FileOutputStream tmpos = new FileOutputStream(tmpFile);
        tmpos.write("admin".getBytes());
        tmpos.write(EOL.getBytes());
        tmpos.close();
        exe = execute("config credentials --server " + serverUrl + " --realm master --user admin < '" + tmpFile.getName() + "'");
        assertExitCodeAndStreamSizes(exe, 0, 1, 1);
        Assert.assertTrue("Enter password prompt", exe.stdoutLines().get(0).startsWith("Enter password: "));
        Assert.assertEquals("stderr first line", "Logging into " + serverUrl + " as user admin of realm master", exe.stderrLines().get(0));
    } finally {
        tmpFile.delete();
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) KcRegExec(org.keycloak.testsuite.cli.KcRegExec) File(java.io.File) Test(org.junit.Test)

Example 13 with KcRegExec

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

the class KcRegTest method testClientLoginWithDefaultConfigInteractive.

@Test
public void testClientLoginWithDefaultConfigInteractive() throws IOException {
    if (!runIntermittentlyFailingTests()) {
        System.out.println("TEST SKIPPED - This test currently suffers from intermittent failures. Use -Dtest.intermittent=true to run it.");
        return;
    }
    // use -Dtest.intermittent=true to run this test
    KcRegExec exe = KcRegExec.newBuilder().argsLine("config credentials --server " + serverUrl + " --realm test --client reg-cli-secret").executeAsync();
    exe.waitForStdout("Enter client secret: ");
    exe.sendToStdin("password" + EOL);
    exe.waitCompletion();
    assertExitCodeAndStreamSizes(exe, 0, 1, 1);
    Assert.assertEquals("stderr first line", "Logging into " + serverUrl + " as service-account-reg-cli-secret of realm test", exe.stderrLines().get(0));
    /*
         *  Run the test one more time with stdin redirect
         */
    File tmpFile = new File(KcRegExec.WORK_DIR + "/" + UUID.randomUUID().toString() + ".tmp");
    try {
        FileOutputStream tmpos = new FileOutputStream(tmpFile);
        tmpos.write("password".getBytes());
        tmpos.write(EOL.getBytes());
        tmpos.close();
        exe = KcRegExec.newBuilder().argsLine("config credentials --server " + serverUrl + " --realm test --client reg-cli-secret < '" + tmpFile.getName() + "'").execute();
        assertExitCodeAndStreamSizes(exe, 0, 1, 1);
        Assert.assertTrue("Enter client secret prompt", exe.stdoutLines().get(0).startsWith("Enter client secret: "));
        Assert.assertEquals("stderr first line", "Logging into " + serverUrl + " as service-account-reg-cli-secret of realm test", exe.stderrLines().get(0));
    } finally {
        tmpFile.delete();
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) KcRegExec(org.keycloak.testsuite.cli.KcRegExec) File(java.io.File) Test(org.junit.Test)

Example 14 with KcRegExec

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

the class KcRegTest method testCRUDWithOnTheFlyUserAuthWithClientSecret.

@Test
@AuthServerContainerExclude(AuthServer.REMOTE)
public void testCRUDWithOnTheFlyUserAuthWithClientSecret() throws IOException {
    /*
         *  Test create, get, update, and delete using on-the-fly authentication - without using any config file.
         *  Login is performed by each operation again, and again using username, password, and client secret.
         */
    // try client without direct grants enabled
    KcRegExec exe = execute("get test-client --no-config --server " + serverUrl + " --realm test" + " --user user1 --password userpass --client reg-cli-secret --secret password");
    assertExitCodeAndStreamSizes(exe, 1, 0, 2);
    Assert.assertEquals("login message", "Logging into " + serverUrl + " as user user1 of realm test", exe.stderrLines().get(0));
    Assert.assertEquals("error message", "Client not allowed for direct access grants [unauthorized_client]", exe.stderrLines().get(1));
    // try wrong user password
    exe = execute("get test-client --no-config --server " + serverUrl + " --realm test" + " --user user1 --password wrong --client reg-cli-secret-direct --secret password");
    assertExitCodeAndStreamSizes(exe, 1, 0, 2);
    Assert.assertEquals("login message", "Logging into " + serverUrl + " as user user1 of realm test", exe.stderrLines().get(0));
    Assert.assertEquals("error message", "Invalid user credentials [invalid_grant]", exe.stderrLines().get(1));
    // try wrong client secret
    exe = execute("get test-client --no-config --server " + serverUrl + " --realm test" + " --user user1 --password userpass --client reg-cli-secret-direct --secret wrong");
    assertExitCodeAndStreamSizes(exe, 1, 0, 2);
    Assert.assertEquals("login message", "Logging into " + serverUrl + " as user user1 of realm test", exe.stderrLines().get(0));
    Assert.assertEquals("error message", "Invalid client secret [unauthorized_client]", exe.stderrLines().get(1));
    // try whole CRUD
    testCRUDWithOnTheFlyAuth(serverUrl, "--user user1 --password userpass --client reg-cli-secret-direct --secret password", "", "Logging into " + serverUrl + " as user user1 of realm test");
}
Also used : KcRegExec(org.keycloak.testsuite.cli.KcRegExec) AuthServerContainerExclude(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude) Test(org.junit.Test)

Example 15 with KcRegExec

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

the class KcRegTest method testCredentialsNoServerWithDefaultConfig.

@Test
public void testCredentialsNoServerWithDefaultConfig() {
    /*
         *  Test without --server specified
         */
    KcRegExec exe = 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 : 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