Search in sources :

Example 26 with KcAdmExec

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

the class KcAdmTest method testBadOption.

@Test
public void testBadOption() {
    /*
         *  Test sub-command execution with non-existent option
         */
    KcAdmExec exe = KcAdmExec.execute("get users --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));
    // set-password doesn't use @Arguments injection thus unsupported options are handled by Aesh
    exe = KcAdmExec.execute("set-password --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 set-password' for more information", exe.stderrLines().get(1));
}
Also used : KcAdmExec(org.keycloak.testsuite.cli.KcAdmExec) Test(org.junit.Test)

Example 27 with KcAdmExec

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

the class KcAdmTest method testCRUDWithOnTheFlyUserAuthWithSignedJwtClient.

@Test
public void testCRUDWithOnTheFlyUserAuthWithSignedJwtClient() 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 JWT signature.
         */
    File keystore = new File(System.getProperty("user.dir") + "/src/test/resources/cli/kcadm/admin-cli-keystore.jks");
    Assert.assertTrue("admin-cli-keystore.jks exists", keystore.isFile());
    // try client without direct grants enabled
    KcAdmExec exe = KcAdmExec.execute("get clients --no-config --server " + serverUrl + " --realm test" + " --user user1 --password userpass --client admin-cli-jwt --keystore '" + keystore.getAbsolutePath() + "'" + " --storepass storepass --keypass keypass --alias admin-cli");
    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 = KcAdmExec.execute("get clients --no-config --server " + serverUrl + " --realm test" + " --user user1 --password wrong --client admin-cli-jwt-direct --keystore '" + keystore.getAbsolutePath() + "'" + " --storepass storepass --keypass keypass --alias admin-cli");
    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 storepass
    exe = KcAdmExec.execute("get clients --no-config --server " + serverUrl + " --realm test" + " --user user1 --password userpass --client admin-cli-jwt-direct --keystore '" + keystore.getAbsolutePath() + "'" + " --storepass wrong --keypass keypass --alias admin-cli");
    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", "Failed to load private key: Keystore was tampered with, or password was incorrect", exe.stderrLines().get(1));
    // try whole CRUD
    testCRUDWithOnTheFlyAuth(serverUrl, "--user user1 --password userpass  --client admin-cli-jwt-direct --keystore '" + keystore.getAbsolutePath() + "'" + " --storepass storepass --keypass keypass --alias admin-cli", "", "Logging into " + serverUrl + " as user user1 of realm test");
}
Also used : 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