keycloak-memoizeit

Merge pull request #2278 from mbaluch/master KPR-147 - Initial

2/26/2016 9:46:52 AM

Details

diff --git a/testsuite/integration-arquillian/README.md b/testsuite/integration-arquillian/README.md
index 39168de..1adc054 100644
--- a/testsuite/integration-arquillian/README.md
+++ b/testsuite/integration-arquillian/README.md
@@ -152,6 +152,7 @@ integration-arquillian
       │
       ├──console          (activated by -Pconsole-ui-tests)
       ├──mod_auth_mellon  (activated by -Pmod_auth_mellon)
+      ├──console_no_users (activated by -Pconsole-ui-no-users-tests)
       └──...
 ```
 
diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/auth/page/WelcomePage.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/auth/page/WelcomePage.java
index 72d389c..9f34a40 100644
--- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/auth/page/WelcomePage.java
+++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/auth/page/WelcomePage.java
@@ -17,6 +17,7 @@
 
 package org.keycloak.testsuite.auth.page;
 
+import org.openqa.selenium.By;
 import org.openqa.selenium.WebElement;
 import org.openqa.selenium.support.FindBy;
 
@@ -38,7 +39,8 @@ public class WelcomePage extends AuthServer {
     private WebElement createButton;
 
     public boolean isPasswordSet() {
-        return !driver.getPageSource().contains("Please create an initial admin user to get started.");
+        return !(driver.getPageSource().contains("Please create an initial admin user to get started.") ||
+                 driver.getPageSource().contains("You need local access to create the initial admin user."));
     }
 
     public void setPassword(String username, String password) {
@@ -58,4 +60,8 @@ public class WelcomePage extends AuthServer {
         }
     }
 
+    public void navigateToAdminConsole() {
+        driver.findElement(By.linkText("Administration Console")).click();
+    }
+    
 }
diff --git a/testsuite/integration-arquillian/tests/base/src/test/resources/arquillian.xml b/testsuite/integration-arquillian/tests/base/src/test/resources/arquillian.xml
index d267f06..e0cfefd 100644
--- a/testsuite/integration-arquillian/tests/base/src/test/resources/arquillian.xml
+++ b/testsuite/integration-arquillian/tests/base/src/test/resources/arquillian.xml
@@ -60,7 +60,7 @@
             <property name="enabled">${auth.server.wildfly}</property>
             <property name="adapterImplClass">org.jboss.as.arquillian.container.managed.ManagedDeployableContainer</property>
             <property name="jbossHome">${keycloak.home}</property>
-            <property name="javaVmArguments">-Djboss.socket.binding.port-offset=${auth.server.port.offset} -Xms64m -Xmx512m -XX:MaxPermSize=256m ${adapter.test.props}</property>
+            <property name="javaVmArguments">-Djboss.socket.binding.port-offset=${auth.server.port.offset} -Djboss.bind.address=0.0.0.0 -Xms64m -Xmx512m -XX:MaxPermSize=256m ${adapter.test.props}</property>
             <property name="managementPort">${auth.server.management.port}</property>
             <property name="startupTimeoutInSeconds">${startup.timeout.sec}</property>
         </configuration>
@@ -131,7 +131,7 @@
             <property name="enabled">${auth.server.eap7}</property>
             <property name="adapterImplClass">org.jboss.as.arquillian.container.managed.ManagedDeployableContainer</property>
             <property name="jbossHome">${keycloak.home}</property>
-            <property name="javaVmArguments">-Djboss.socket.binding.port-offset=${auth.server.port.offset} -Xms64m -Xmx512m -XX:MaxPermSize=256m ${adapter.test.props}</property>
+            <property name="javaVmArguments">-Djboss.socket.binding.port-offset=${auth.server.port.offset} -Djboss.bind.address=0.0.0.0 -Xms64m -Xmx512m -XX:MaxPermSize=256m ${adapter.test.props}</property>
             <property name="startupTimeoutInSeconds">${startup.timeout.sec}</property>
             <property name="managementPort">${auth.server.management.port}</property>
         </configuration>
diff --git a/testsuite/integration-arquillian/tests/other/console_no_users/pom.xml b/testsuite/integration-arquillian/tests/other/console_no_users/pom.xml
new file mode 100644
index 0000000..220a10b
--- /dev/null
+++ b/testsuite/integration-arquillian/tests/other/console_no_users/pom.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0"?>
+<!--
+  ~ Copyright 2016 Red Hat, Inc. and/or its affiliates
+  ~ and other contributors as indicated by the @author tags.
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~ http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.keycloak.testsuite</groupId>
+        <artifactId>integration-arquillian-tests-other</artifactId>
+        <version>1.9.1.Final-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>integration-arquillian-tests-console-no-users</artifactId>
+
+    <name>Admin Console UI Tests - Without pre-configured accounts</name>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-resources-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>copy-admin-user-json-file</id>
+                        <phase>none</phase>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
diff --git a/testsuite/integration-arquillian/tests/other/console_no_users/src/test/java/org/keycloak/testsuite/console/pages/WelcomePageTest.java b/testsuite/integration-arquillian/tests/other/console_no_users/src/test/java/org/keycloak/testsuite/console/pages/WelcomePageTest.java
new file mode 100644
index 0000000..1051bb1
--- /dev/null
+++ b/testsuite/integration-arquillian/tests/other/console_no_users/src/test/java/org/keycloak/testsuite/console/pages/WelcomePageTest.java
@@ -0,0 +1,112 @@
+package org.keycloak.testsuite.console.pages;
+
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.URL;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+import org.jboss.arquillian.graphene.page.Page;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+import org.keycloak.representations.idm.RealmRepresentation;
+import org.keycloak.testsuite.AbstractKeycloakTest;
+import org.keycloak.testsuite.auth.page.WelcomePage;
+import org.keycloak.testsuite.auth.page.login.OIDCLogin;
+
+/**
+ *
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class WelcomePageTest extends AbstractKeycloakTest {
+
+    @Page
+    private WelcomePage welcomePage;
+
+    @Page
+    protected OIDCLogin loginPage;
+    
+    @Override
+    public void addTestRealms(List<RealmRepresentation> testRealms) {
+        // no operation
+    }
+
+    /*
+     * Leave out client initialization and creation of a user account. We
+     * don't need those.
+     */
+    @Before
+    @Override
+    public void beforeAbstractKeycloakTest() {
+        setDefaultPageUriParameters();
+        driverSettings();
+    }
+
+    /**
+     * Attempt to resolve the floating IP address. This is where EAP/WildFly
+     * will be accessible. See "-Djboss.bind.address=0.0.0.0".
+     * 
+     * @return
+     * @throws Exception 
+     */
+    private String getFloatingIpAddress() throws Exception {
+        Enumeration<NetworkInterface> netInterfaces = NetworkInterface.getNetworkInterfaces();
+        for (NetworkInterface ni : Collections.list(netInterfaces)) {
+            Enumeration<InetAddress> inetAddresses = ni.getInetAddresses();
+            for (InetAddress a : Collections.list(inetAddresses)) {
+                if (!a.isLoopbackAddress() && a.isSiteLocalAddress()) {
+                    return a.getHostAddress();
+                }
+            }
+        }
+        return null;
+    }
+
+    private URL getPublicServerUrl() throws Exception {
+        String floatingIp = getFloatingIpAddress();
+        if (floatingIp == null) {
+            throw new RuntimeException("Could not determine floating IP address.");
+        }
+        return new URL("http", floatingIp, welcomePage.getInjectedUrl().getPort(), "");
+    }
+    
+    @Test
+    public void test_1_LocalAccessNoAdmin() throws Exception {
+        welcomePage.navigateTo();
+        Assert.assertFalse("Welcome page did not ask to create a new admin user.", welcomePage.isPasswordSet());
+    }
+
+    @Test
+    public void test_2_RemoteAccessNoAdmin() throws Exception {
+        driver.navigate().to(getPublicServerUrl());
+        Assert.assertFalse("Welcome page did not ask to create a new admin user.", welcomePage.isPasswordSet());
+    }
+
+    @Test
+    public void test_3_LocalAccessWithAdmin() throws Exception {
+        welcomePage.navigateTo();
+        welcomePage.setPassword("admin", "admin");
+        Assert.assertTrue(driver.getPageSource().contains("User created"));
+
+        welcomePage.navigateTo();
+        Assert.assertTrue("Welcome page asked to set admin password.", welcomePage.isPasswordSet());
+    }
+
+    @Test
+    public void test_4_RemoteAccessWithAdmin() throws Exception {
+        driver.navigate().to(getPublicServerUrl());
+        Assert.assertTrue("Welcome page asked to set admin password.", welcomePage.isPasswordSet());
+    }
+
+    @Test
+    public void test_5_AccessCreatedAdminAccount() throws Exception {
+        welcomePage.navigateToAdminConsole();
+        loginPage.form().login("admin", "admin");
+        Assert.assertFalse("Login with 'admin:admin' failed", 
+                driver.getPageSource().contains("Invalid username or password."));
+    }
+
+}
diff --git a/testsuite/integration-arquillian/tests/other/pom.xml b/testsuite/integration-arquillian/tests/other/pom.xml
index 19648b7..8b04c07 100644
--- a/testsuite/integration-arquillian/tests/other/pom.xml
+++ b/testsuite/integration-arquillian/tests/other/pom.xml
@@ -135,6 +135,12 @@
             </modules>
         </profile>
         <profile>
+            <id>console-ui-no-users-tests</id>
+            <modules>
+                <module>console_no_users</module>
+            </modules>
+        </profile>
+        <profile>
             <id>mod_auth_mellon</id>
             <modules>
                 <module>mod_auth_mellon</module>