From 8926837a3e76b373fb91f07b96ddfc0895518fb2 Mon Sep 17 00:00:00 2001 From: Bill Burke Date: Mon, 19 Mar 2018 16:47:13 -0400 Subject: [PATCH] tests --- .../adapters/installed/KcinitDriver.java | 45 +++++++++---------- .../adapters/installed/KeycloakInstalled.java | 3 +- .../oidc/endpoints/LogoutEndpoint.java | 3 +- .../keycloak/testsuite/cli/KcinitTest.java | 20 ++++----- .../base/login/login-config-totp-text.ftl | 4 ++ 5 files changed, 36 insertions(+), 39 deletions(-) diff --git a/adapters/oidc/installed/src/main/java/org/keycloak/adapters/installed/KcinitDriver.java b/adapters/oidc/installed/src/main/java/org/keycloak/adapters/installed/KcinitDriver.java index 790cbcd49a..4693f62512 100644 --- a/adapters/oidc/installed/src/main/java/org/keycloak/adapters/installed/KcinitDriver.java +++ b/adapters/oidc/installed/src/main/java/org/keycloak/adapters/installed/KcinitDriver.java @@ -84,38 +84,19 @@ public class KcinitDriver { public void mainCmd(String[] args) throws Exception { - this.args = Arrays.copyOf(args, args.length); - for (String arg : args) { - if (!arg.startsWith("-")) break; - if (arg.equals("-f") || arg.equals("-force")) { - forceLogin = true; - this.args = Arrays.copyOfRange(this.args, 1, this.args.length); - } else if (arg.equals("-browser") || arg.equals("-b")) { - browserLogin = true; - this.args = Arrays.copyOfRange(this.args, 1, this.args.length); - } else { - System.err.println("Illegal argument: " + arg); - printHelp(); - System.exit(1); - } - } - this.args = args; if (args.length == 0) { - login(); - return; - } - - if (args[0].startsWith("-")) { - login(); + printHelp(); return; } if (args[0].equalsIgnoreCase("token")) { //System.err.println("executing token"); token(); + } else if (args[0].equalsIgnoreCase("login")) { + login(); } else if (args[0].equalsIgnoreCase("logout")) { logout(); } else if (args[0].equalsIgnoreCase("env")) { @@ -402,8 +383,7 @@ public class KcinitDriver { public void printHelp() { KeycloakInstalled.console().writer().println("Commands:"); - KeycloakInstalled.console().writer().println(" no arguments is a login"); - KeycloakInstalled.console().writer().println(" no argument with -f forces login"); + KeycloakInstalled.console().writer().println(" login [-f] -f forces login"); KeycloakInstalled.console().writer().println(" logout"); KeycloakInstalled.console().writer().println(" token [client] - print access token of desired client. Defaults to default master client. Will print either 'error', 'not-allowed', or 'login-required' on error."); KeycloakInstalled.console().writer().println(" install - Install this utility. Will store in $HOME/.keycloak/kcinit unless " + KC_LOGIN_CONFIG_PATH + " env var is set"); @@ -647,8 +627,23 @@ public class KcinitDriver { public void login() throws Exception { checkEnv(); + this.args = Arrays.copyOfRange(this.args, 1, this.args.length); + for (String arg : args) { + if (arg.equals("-f") || arg.equals("-force")) { + forceLogin = true; + this.args = Arrays.copyOfRange(this.args, 1, this.args.length); + } else if (arg.equals("-browser") || arg.equals("-b")) { + browserLogin = true; + this.args = Arrays.copyOfRange(this.args, 1, this.args.length); + } else { + System.err.println("Illegal argument: " + arg); + printHelp(); + System.exit(1); + } + } + String masterClient = getMasterClient(); - if (!forceLogin() && readToken(masterClient) != null) { + if (!forceLogin && readToken(masterClient) != null) { KeycloakInstalled.console().writer().println("Already logged in. `kcinit -f` to force relogin"); return; } diff --git a/adapters/oidc/installed/src/main/java/org/keycloak/adapters/installed/KeycloakInstalled.java b/adapters/oidc/installed/src/main/java/org/keycloak/adapters/installed/KeycloakInstalled.java index b0b8d0e003..4f311c223f 100644 --- a/adapters/oidc/installed/src/main/java/org/keycloak/adapters/installed/KeycloakInstalled.java +++ b/adapters/oidc/installed/src/main/java/org/keycloak/adapters/installed/KeycloakInstalled.java @@ -462,8 +462,6 @@ public class KeycloakInstalled { //System.err.println("initial request"); Response response = client.target(authUrl).request().get(); while (true) { - System.err.println("looping"); - if (response.getStatus() == 403) { if (response.getMediaType() != null) { String splash = response.readEntity(String.class); @@ -471,6 +469,7 @@ public class KeycloakInstalled { } else { System.err.println("Forbidden to login"); } + return false; } else if (response.getStatus() == 401) { String authenticationHeader = response.getHeaderString(HttpHeaders.WWW_AUTHENTICATE); if (authenticationHeader == null) { diff --git a/services/src/main/java/org/keycloak/protocol/oidc/endpoints/LogoutEndpoint.java b/services/src/main/java/org/keycloak/protocol/oidc/endpoints/LogoutEndpoint.java index 7f5048a92e..406202102e 100755 --- a/services/src/main/java/org/keycloak/protocol/oidc/endpoints/LogoutEndpoint.java +++ b/services/src/main/java/org/keycloak/protocol/oidc/endpoints/LogoutEndpoint.java @@ -164,12 +164,11 @@ public class LogoutEndpoint { * * returns 204 if successful, 400 if not with a json error response. * - * @param authorizationHeader * @return */ @POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - public Response logoutToken(final @HeaderParam(HttpHeaders.AUTHORIZATION) String authorizationHeader) { + public Response logoutToken() { MultivaluedMap form = request.getDecodedFormParameters(); checkSsl(); diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/cli/KcinitTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/cli/KcinitTest.java index e54aee7ec1..288816f74d 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/cli/KcinitTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/cli/KcinitTest.java @@ -125,7 +125,7 @@ public class KcinitTest extends AbstractTestRealmKeycloakTest { UserModel user = session.users().addUser(realm, "bburke"); session.userCredentialManager().updateCredential(realm, user, UserCredentialModel.password("password")); user.setEnabled(true); - user.setEmail("patriot1burke@gmail.com"); + user.setEmail("p@p.com"); user.addRequiredAction(UserModel.RequiredAction.UPDATE_PASSWORD); user.addRequiredAction(UserModel.RequiredAction.CONFIGURE_TOTP); user.addRequiredAction(UserModel.RequiredAction.VERIFY_EMAIL); @@ -151,7 +151,7 @@ public class KcinitTest extends AbstractTestRealmKeycloakTest { smtp.put("replyTo", "reply-to@keycloak.org"); smtp.put("ssl", "true"); smtp.put("auth", "true"); - smtp.put("user", "****"); + smtp.put("user", "*****"); smtp.put("password", "****"); realm.setSmtpConfig(smtp); @@ -194,7 +194,7 @@ public class KcinitTest extends AbstractTestRealmKeycloakTest { testInstall(); // login KcinitExec exe = KcinitExec.newBuilder() - .argsLine("") + .argsLine("login") .executeAsync(); exe.waitForStderr("Username:"); exe.sendLine("wburke"); @@ -258,7 +258,7 @@ public class KcinitTest extends AbstractTestRealmKeycloakTest { testInstall(); KcinitExec exe = KcinitExec.newBuilder() - .argsLine("") + .argsLine("login") .executeAsync(); exe.waitForStderr("Username:"); exe.sendLine("wburke"); @@ -288,7 +288,7 @@ public class KcinitTest extends AbstractTestRealmKeycloakTest { //Thread.sleep(100000000); KcinitExec exe = KcinitExec.newBuilder() - .argsLine("") + .argsLine("login") .executeAsync(); try { exe.waitForStderr("Username:"); @@ -327,7 +327,7 @@ public class KcinitTest extends AbstractTestRealmKeycloakTest { testInstall(); KcinitExec exe = KcinitExec.newBuilder() - .argsLine("") + .argsLine("login") .executeAsync(); exe.waitForStderr("Username:"); exe.sendLine("wburke"); @@ -343,7 +343,7 @@ public class KcinitTest extends AbstractTestRealmKeycloakTest { Assert.assertEquals(0, exe.stdoutLines().size()); exe = KcinitExec.newBuilder() - .argsLine("-f") + .argsLine("login -f") .executeAsync(); exe.waitForStderr("Username:"); exe.sendLine("wburke"); @@ -383,7 +383,7 @@ public class KcinitTest extends AbstractTestRealmKeycloakTest { testInstall(); KcinitExec exe = KcinitExec.newBuilder() - .argsLine("") + .argsLine("login") .executeAsync(); exe.waitForStderr("Username:"); exe.sendLine("wburke"); @@ -427,7 +427,7 @@ public class KcinitTest extends AbstractTestRealmKeycloakTest { Assert.assertEquals(0, exe.exitCode()); exe = KcinitExec.newBuilder() - .argsLine("") + .argsLine("login") .executeAsync(); exe.waitForStderr("Username:"); exe.sendLine("wburke"); @@ -465,7 +465,7 @@ public class KcinitTest extends AbstractTestRealmKeycloakTest { testInstall(); KcinitExec exe = KcinitExec.newBuilder() - .argsLine("") + .argsLine("login") .executeAsync(); exe.waitForStderr("Username:"); exe.sendLine("test-user@localhost"); diff --git a/themes/src/main/resources/theme/base/login/login-config-totp-text.ftl b/themes/src/main/resources/theme/base/login/login-config-totp-text.ftl index 22360f39b3..d609182edf 100755 --- a/themes/src/main/resources/theme/base/login/login-config-totp-text.ftl +++ b/themes/src/main/resources/theme/base/login/login-config-totp-text.ftl @@ -25,3 +25,7 @@ ${msg("loginTotpManualStep3")} +Enter in your one time password so we can verify you have installed it correctly. + + +