From ad995934b0811385febe3f1bf37727819fc7464c Mon Sep 17 00:00:00 2001 From: mhajas Date: Wed, 2 Nov 2016 11:43:56 +0100 Subject: [PATCH] KEYCLOAK-3728 Test for turned off script based authenticators --- .../admin/authentication/ProvidersTest.java | 6 +++- .../ScriptBasedAuthenticatorTest.java | 31 +++++++++++++++++++ .../forms/ScriptAuthenticatorTest.java | 9 +++--- 3 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/authentication/ScriptBasedAuthenticatorTest.java diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/authentication/ProvidersTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/authentication/ProvidersTest.java index c46a620b61..e226d5016f 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/authentication/ProvidersTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/authentication/ProvidersTest.java @@ -32,6 +32,8 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import static org.keycloak.common.Profile.isPreviewEnabled; + /** * @author Marko Strukelj */ @@ -135,7 +137,9 @@ public class ProvidersTest extends AbstractAuthenticationTest { "Validates a OTP on a separate OTP form. Only shown if required based on the configured conditions."); addProviderInfo(result, "auth-cookie", "Cookie", "Validates the SSO cookie set by the auth server."); addProviderInfo(result, "auth-otp-form", "OTP Form", "Validates a OTP on a separate OTP form."); - addProviderInfo(result, "auth-script-based", "Script", "Script based authentication. Allows to define custom authentication logic via JavaScript."); + if (isPreviewEnabled()) { + addProviderInfo(result, "auth-script-based", "Script", "Script based authentication. Allows to define custom authentication logic via JavaScript."); + } addProviderInfo(result, "auth-spnego", "Kerberos", "Initiates the SPNEGO protocol. Most often used with Kerberos."); addProviderInfo(result, "auth-username-password-form", "Username Password Form", "Validates a username and password from login form."); diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/authentication/ScriptBasedAuthenticatorTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/authentication/ScriptBasedAuthenticatorTest.java new file mode 100644 index 0000000000..3466928a90 --- /dev/null +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/authentication/ScriptBasedAuthenticatorTest.java @@ -0,0 +1,31 @@ +package org.keycloak.testsuite.admin.authentication; + +import org.junit.Assert; +import org.junit.Test; +import org.keycloak.testsuite.ProfileAssume; + +import javax.ws.rs.BadRequestException; +import java.util.HashMap; + +/** + * @author mhajas + */ +public class ScriptBasedAuthenticatorTest extends AbstractAuthenticationTest { + + @Test + public void checkIfTurnedOffWithProductProfile() throws InterruptedException { + ProfileAssume.assumePreviewDisabled(); + + HashMap params = new HashMap<>(); + params.put("newName", "Copy-of-browser"); + authMgmtResource.copy("browser", params); + + params.put("provider", "auth-script-based"); + try { + authMgmtResource.addExecution("Copy-of-browser", params); + Assert.fail("Adding script based authenticator should fail with product profile"); + } catch (BadRequestException ex) { + //Expected + } + } +} diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/forms/ScriptAuthenticatorTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/forms/ScriptAuthenticatorTest.java index 61cc47c94b..34113d811c 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/forms/ScriptAuthenticatorTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/forms/ScriptAuthenticatorTest.java @@ -18,10 +18,7 @@ package org.keycloak.testsuite.forms; import org.apache.commons.io.IOUtils; import org.jboss.arquillian.graphene.page.Page; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.*; import org.keycloak.authentication.authenticators.browser.ScriptBasedAuthenticatorFactory; import org.keycloak.authentication.authenticators.browser.UsernamePasswordFormFactory; import org.keycloak.events.Details; @@ -34,6 +31,7 @@ import org.keycloak.representations.idm.AuthenticatorConfigRepresentation; import org.keycloak.representations.idm.RealmRepresentation; import org.keycloak.representations.idm.UserRepresentation; import org.keycloak.testsuite.AssertEvents; +import org.keycloak.testsuite.ProfileAssume; import org.keycloak.testsuite.pages.LoginPage; import org.keycloak.testsuite.util.ExecutionBuilder; import org.keycloak.testsuite.util.FlowBuilder; @@ -62,6 +60,9 @@ public class ScriptAuthenticatorTest extends AbstractFlowTest { private AuthenticationFlowRepresentation flow; + @BeforeClass + public static void enabled() { ProfileAssume.assumePreview(); } + @Override public void configureTestRealm(RealmRepresentation testRealm) {