Repository: EnMasseProject/enmasse
Pull request #2382 (2019-02-28 12:13:01)

Update travis to use java 11

lulf: @enmasse-ci run tests

Patch:
diff --git a/.jenkins/jenkins-functions.groovy b/.jenkins/jenkins-functions.groovy
index 0df1b42be..d021908fc 100644
--- a/.jenkins/jenkins-functions.groovy
+++ b/.jenkins/jenkins-functions.groovy
@@ -1,6 +1,6 @@
 def storeArtifacts(String artifactDir) {
-    sh "./systemtests/scripts/store_kubernetes_info.sh '${artifactDir}/openshift-info/'"
-    sh "./systemtests/scripts/collect_logs.sh '/tmp/testlogs' '${artifactDir}/openshift-logs'"
+    sh "./systemtests/scripts/store_kubernetes_info.sh '${artifactDir}/openshift-info/' || true"
+    sh "./systemtests/scripts/collect_logs.sh '/tmp/testlogs' '${artifactDir}/openshift-logs' || true"
     sh "cp -rf ${HOME}/.npm/_logs ${artifactDir}/npm-logs || true"
     sh 'rm -rf /tmp/testlogs'
 }
@@ -98,7 +98,6 @@ def postAction(String coresDir, String artifactDir) {
     if (status == null) {
         currentBuild.result = 'SUCCESS'
     }
-    tearDownOpenshift()
     sh "./systemtests/scripts/check_and_clear_cores.sh ${coresDir}"
 }
 
diff --git a/.travis.yml b/.travis.yml
index a307c541b..8a668c54b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -18,7 +18,7 @@ cache:
   directories:
     - "$HOME/.m2"
 jdk:
-- openjdk8
+- openjdk11
 python:
   - "2.7.14"
 go:
diff --git a/.travis/build.sh b/.travis/build.sh
index 271165b53..99ad3fdfc 100755
--- a/.travis/build.sh
+++ b/.travis/build.sh
@@ -21,7 +21,7 @@ fi
 echo "Building EnMasse with tag $TAG, version $VERSION from $BRANCH. PR: $PULL_REQUEST"
 make clean
 
-make
+time make
 
 make docu_html
 
@@ -47,4 +47,4 @@ else
 fi
 
 echo "Running systemtests"
-./systemtests/scripts/run_test_kubernetes.sh templates/build/enmasse-${TAG} ${SYSTEMTEST_PROFILE} ${SYSTEMTEST_ARGS}
+time ./systemtests/scripts/run_test_kubernetes.sh templates/build/enmasse-${TAG} ${SYSTEMTEST_PROFILE} ${SYSTEMTEST_ARGS}
diff --git a/broker-plugin/sasl-delegation/src/main/java/io/enmasse/artemis/sasl_delegation/SaslDelegatingLogin.java b/broker-plugin/sasl-delegation/src/main/java/io/enmasse/artemis/sasl_delegation/SaslDelegatingLogin.java
index b7f6a8b25..e3b7aa40d 100644
--- a/broker-plugin/sasl-delegation/src/main/java/io/enmasse/artemis/sasl_delegation/SaslDelegatingLogin.java
+++ b/broker-plugin/sasl-delegation/src/main/java/io/enmasse/artemis/sasl_delegation/SaslDelegatingLogin.java
@@ -32,6 +32,7 @@ import java.security.NoSuchAlgorithmException;
 import java.security.Principal;
 import java.util.*;
 import java.util.function.BooleanSupplier;
+import java.util.stream.Collectors;
 import javax.naming.InvalidNameException;
 import javax.naming.ldap.LdapName;
 import javax.net.ssl.SSLContext;
@@ -352,9 +353,12 @@ public class SaslDelegatingLogin implements LoginModule {
             roles.addAll(defaultRolesAuthenticated);
 
             if (remoteProperties.get(Symbol.valueOf(GROUPS)) instanceof List) {
-                List<String> groups = (List<String>) remoteProperties.get(Symbol.valueOf(GROUPS));
+                List<String> groups = new ArrayList<>(((List<String>) ((List) remoteProperties.get(Symbol.valueOf(GROUPS)))));
                 groups.retainAll(SPECIAL_AUTHZ_GROUPS);
                 roles.addAll(groups);
+                for (String group : groups) {
+                    roles.add(group + "_#");
+                }
             }
         }
 
@@ -364,7 +368,7 @@ public class SaslDelegatingLogin implements LoginModule {
                 List<String> groups = new ArrayList<>();
                 for(Map.Entry<String, String[]> entry : authz.entrySet()) {
                     for(String permission : entry.getValue()) {
-                        groups.add(permission + "_" + entry.getKey());
+                        groups.add(permission + "_" + entry.getKey().replace('*', '#'));
                     }
                 }
                 roles.addAll(groups);
diff --git a/iot/examples/README.md b/iot/examples/README.md
index 358a1d7f6..a7b25bab5 100644
--- a/iot/examples/README.md
+++ b/iot/examples/README.md
@@ -34,21 +34,21 @@
 * Create Managed IoT Project
 
   ```
+  oc new-project myapp || oc project myapp
   oc create -f iot/examples/iot-project-managed.yaml
   ```
 
 * Create Messaging Consumer User
 
   ```
-  sed -e 's/enmasse-infra/my-iot-1/g' iot/examples/iot-user.yaml | oc apply -f -
+  oc create -f iot/examples/iot-user.yaml
   ```
-  
-  **Note**: If your project name is not `my-iot-1`, then you need to replace this in the previous command accordingly.
 
 * Register a device
 
   ```
-  curl --insecure -X POST -i -H 'Content-Type: application/json' --data-binary '{"device-id": "4711"}' https://$(oc get routes device-registry --template='{{ .spec.host }}')/registration/my-iot-1.managed
+  oc project enmasse-infra
+  curl --insecure -X POST -i -H 'Content-Type: application/json' --data-binary '{"device-id": "4711"}' https://$(oc get routes device-registry --template='{{ .spec.host }}')/registration/myapp.iot
   ```
 
 * Add credentials for a device
@@ -56,22 +56,26 @@
   ```
   PWD_HASH=$(echo -n "hono-secret" | openssl dgst -binary -sha512 | base64 | tr -d '\n')
   
-  curl --insecure -X POST -i -H 'Content-Type: application/json' --data-binary '{"device-id": "4711","type": "hashed-password","auth-id": "sensor1","secrets": [{"hash-function" : "sha-512","pwd-hash":"'$PWD_HASH'"}]}' https://$(oc get routes device-registry --template='{{ .spec.host }}')/credentials/my-iot-1.managed
+  curl --insecure -X POST -i -H 'Content-Type: application/json' --data-binary '{"device-id": "4711","type": "hashed-password","auth-id": "sensor1","secrets": [{"hash-function" : "sha-512","pwd-hash":"'$PWD_HASH'"}]}' https://$(oc get routes device-registry --template='{{ .spec.host }}')/credentials/myapp.iot
   ```
 
 * Start a telemetry consumer
 
+In Hono project run
+
   ```
-  oc get addressspace managed -o jsonpath={.status.endpointStatuses[?\(@.name==\'messaging\'\)].cert} | base64 --decode > target/config/hono-demo-certs-jar/tls.crt
-  
   cd cli
-  mvn spring-boot:run -Drun.arguments=--hono.client.host=$(oc get addressspace managed -o jsonpath={.status.endpointStatuses[?\(@.name==\'messaging\'\)].externalHost}),--hono.client.port=443,--hono.client.username=consumer,--hono.client.password=foobar,--tenant.id=my-iot-1.managed,--hono.client.trustStorePath=target/config/hono-demo-certs-jar/tls.crt
+
+  oc project myapp
+  oc get addressspace iot -o jsonpath={.status.endpointStatuses[?\(@.name==\'messaging\'\)].cert} | base64 --decode > target/config/hono-demo-certs-jar/tls.crt
+
+  mvn spring-boot:run -Drun.arguments=--hono.client.host=$(oc get addressspace iot -o jsonpath={.status.endpointStatuses[?\(@.name==\'messaging\'\)].externalHost}),--hono.client.port=443,--hono.client.username=consumer,--hono.client.password=foobar,--tenant.id=myapp.iot,--hono.client.trustStorePath=target/config/hono-demo-certs-jar/tls.crt
   ```
 
 * Send telemetry message using HTTP
 
   ```
-  curl --insecure -X POST -i -u sensor1@my-iot-1.managed:hono-secret -H 'Content-Type: application/json' --data-binary '{"temp": 5}' https://$(oc get route iot-http-adapter --template='{{.spec.host}}')/telemetry
+  curl --insecure -X POST -i -u sensor1@myapp.iot:hono-secret -H 'Content-Type: application/json' --data-binary '{"temp": 5}' https://$(oc get route iot-http-adapter --template='{{.spec.host}}')/telemetry
   ```
 
 * Send telemetry message using MQTT
@@ -79,7 +83,7 @@
   This is an example using NodePort, so you need to know your cluster IP and use in the command
 
   ```
-  mosquitto_pub -h ${cluster.ip} -p 31883 -u 'sensor1@my-iot-1.managed' -P hono-secret -t telemetry -m '{"temp": 5}'
+  mosquitto_pub -h ${cluster.ip} -p 31883 -u 'sensor1@myapp.iot' -P hono-secret -t telemetry -m '{"temp": 5}'
   ```
 
   In the future, we'll provide a proper examples based on the Openshift route with TLS and remove NodePort.
@@ -90,7 +94,7 @@
 * Create a new context:
 
   ```
-  hat context create my-iot-1 --default-tenant my-iot-1.managed https://$(oc -n enmasse-infra get routes device-registry --template='{{ .spec.host }}')
+  hat context create myapp1 --default-tenant myapp.iot https://$(oc get routes device-registry --template='{{ .spec.host }}')
   ```
 
 * Register a new device
diff --git a/iot/examples/iot-project-managed.yaml b/iot/examples/iot-project-managed.yaml
index 6ac1d754f..2abdb9df2 100644
--- a/iot/examples/iot-project-managed.yaml
+++ b/iot/examples/iot-project-managed.yaml
@@ -1,9 +1,8 @@
----
 kind: IoTProject
 apiVersion: iot.enmasse.io/v1alpha1
 metadata:
-  name: managed
+  name: iot
 spec:
   downstreamStrategy:
     managedStrategy:
-      addressSpaceName: managed
+      addressSpaceName: iot
diff --git a/iot/examples/iot-user.yaml b/iot/examples/iot-user.yaml
index f72a0ac82..580e262ef 100644
--- a/iot/examples/iot-user.yaml
+++ b/iot/examples/iot-user.yaml
@@ -1,14 +1,14 @@
 kind: MessagingUser
 apiVersion: user.enmasse.io/v1beta1
 metadata:
-  name: managed.consumer
+  name: iot.consumer
 spec:
   username: consumer
   authentication:
     type: password
     password: Zm9vYmFy # <- foobar
   authorization:
-  - addresses:  [ "telemetry/enmasse-infra.managed", "telemetry/enmasse-infra.managed/*", "event/enmasse-infra.managed", "event/enmasse-infra.managed/*" ]
+  - addresses:  [ "telemetry/myapp.iot", "telemetry/myapp.iot/*", "event/myapp.iot", "event/myapp.iot/*" ]
     operations: [ "recv" ]
-  - addresses:  [ "command/enmasse-infra.managed", "command/enmasse-infra.managed/*" ]
+  - addresses:  [ "command/myapp.iot", "command/myapp.iot/*" ]
     operations: [ "send", "recv" ]
diff --git a/keycloak-user-api/src/main/java/io/enmasse/user/keycloak/KeycloakUserApi.java b/keycloak-user-api/src/main/java/io/enmasse/user/keycloak/KeycloakUserApi.java
index 648df5b05..832342013 100644
--- a/keycloak-user-api/src/main/java/io/enmasse/user/keycloak/KeycloakUserApi.java
+++ b/keycloak-user-api/src/main/java/io/enmasse/user/keycloak/KeycloakUserApi.java
@@ -16,15 +16,7 @@ import java.nio.charset.StandardCharsets;
 import java.time.Clock;
 import java.time.Duration;
 import java.time.Instant;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
+import java.util.*;
 import java.util.function.Predicate;
 import java.util.stream.Collectors;
 
@@ -325,7 +317,7 @@ public class KeycloakUserApi implements UserApi {
     /**
      * Create the set of desired groups.
      *
-     * @param user The user to create the groups for.
+     * @param authorization The authorization rule list to create the groups for.
      * @return A set of groups.
      */
     static Set<String> createDesiredGroupsSet(final List<UserAuthorization> authorization) {
@@ -338,11 +330,9 @@ public class KeycloakUserApi implements UserApi {
 
                 switch (operation) {
                     case manage:
-                        desiredGroups.add("manage_#");
                         desiredGroups.add("manage");
                         break;
                     case view:
-                        desiredGroups.add("monitor_#");
                         desiredGroups.add("monitor");
                         break;
                     default:
@@ -351,8 +341,6 @@ public class KeycloakUserApi implements UserApi {
                                 String groupName = operation.name() + "_" + encodePart(address);
                                 // normal name
                                 desiredGroups.add(groupName);
-                                // brokered name ( the set will remove duplicates for us)
-                                desiredGroups.add(groupName.replace("*", "#"));
                             }
                         }
                         break;
@@ -582,8 +570,8 @@ public class KeycloakUserApi implements UserApi {
 
     static User buildUser(UserRepresentation userRep, List<GroupRepresentation> groupReps) {
         log.debug("Creating user from user representation id {}, name {} part of groups {}", userRep.getId(), userRep.getUsername(), userRep.getGroups());
-        Map<String, Set<Operation>> operationsByAddress = new HashMap<>();
-        Set<Operation> globalOperations = new HashSet<>();
+        Map<String, Set<Operation>> operationsByAddress = new LinkedHashMap<>();
+        Set<Operation> globalOperations = new LinkedHashSet<>();
         for (GroupRepresentation groupRep : groupReps) {
             log.debug("Checking group id {} name {}", groupRep.getId(), groupRep.getName());
             if (groupRep.getName().startsWith("manage")) {
@@ -594,15 +582,15 @@ public class KeycloakUserApi implements UserApi {
                 String[] parts = groupRep.getName().split("_");
                 Operation operation = Operation.valueOf(parts[0]);
                 String address = decodePart(parts[1]);
-                operationsByAddress.computeIfAbsent(address, k -> new HashSet<>())
+                operationsByAddress.computeIfAbsent(address, k -> new LinkedHashSet<>())
                         .add(operation);
             }
         }
 
-        Map<Set<Operation>, Set<String>> operations = new HashMap<>();
+        Map<Set<Operation>, Set<String>> operations = new LinkedHashMap<>();
         for (Map.Entry<String, Set<Operation>> byAddressEntry : operationsByAddress.entrySet()) {
             if (!operations.containsKey(byAddressEntry.getValue())) {
-                operations.put(byAddressEntry.getValue(), new HashSet<>());
+                operations.put(byAddressEntry.getValue(), new LinkedHashSet<>());
             }
             operations.get(byAddressEntry.getValue()).add(byAddressEntry.getKey());
         }
diff --git a/pom.xml b/pom.xml
index 085eb756f..1dbb3b504 100644
--- a/pom.xml
+++ b/pom.xml
@@ -59,9 +59,10 @@
         <commons-collections.version>3.2.2</commons-collections.version>
         <guava.version>25.0-jre</guava.version>
         <hamcrest.version>1.3</hamcrest.version>
-        <junit.jupiter.version>5.3.1</junit.jupiter.version>
-        <junit.platform.runner.version>1.1.0</junit.platform.runner.version>
-        <junit.platform.launcher.version>1.3.0</junit.platform.launcher.version>
+        <junit.jupiter.version>5.4.0</junit.jupiter.version>
+        <junit.platform.runner.version>1.4.0</junit.platform.runner.version>
+        <junit.platform.launcher.version>1.4.0</junit.platform.launcher.version>
+        <junit.platform.surefire.provider.version>1.3.2</junit.platform.surefire.provider.version>
         <artemis.version>2.6.4</artemis.version>
         <ngwebdriver.version>1.1.4</ngwebdriver.version>
         <paho.version>1.2.0</paho.version>
@@ -89,7 +90,7 @@
         <maven-checkstyle-plugin.version>3.0.0</maven-checkstyle-plugin.version>
         <maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
         <maven-shade-plugin.version>3.1.0</maven-shade-plugin.version>
-        <maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
+        <maven-surefire-plugin.version>2.22.1</maven-surefire-plugin.version>
         <maven-site-plugin.version>3.5.1</maven-site-plugin.version>
         <maven-project-info-reports-plugin.version>2.9</maven-project-info-reports-plugin.version>
         <maven-enforcer-plugin.version>3.0.0-M2</maven-enforcer-plugin.version>
@@ -840,7 +841,7 @@
                     <dependency>
                         <groupId>org.junit.platform</groupId>
                         <artifactId>junit-platform-surefire-provider</artifactId>
-                        <version>${junit.platform.runner.version}</version>
+                        <version>${junit.platform.surefire.provider.version}</version>
                     </dependency>
                 </dependencies>
             </plugin>


Test patch:
diff --git a/keycloak-user-api/src/test/java/io/enmasse/user/keycloak/KeycloakUserApiTest.java b/keycloak-user-api/src/test/java/io/enmasse/user/keycloak/KeycloakUserApiTest.java
index c32ee035d..9f6970462 100644
--- a/keycloak-user-api/src/test/java/io/enmasse/user/keycloak/KeycloakUserApiTest.java
+++ b/keycloak-user-api/src/test/java/io/enmasse/user/keycloak/KeycloakUserApiTest.java
@@ -264,7 +264,7 @@ public class KeycloakUserApiTest {
 
         final Set<String> result = KeycloakUserApi.createDesiredGroupsSet(auth);
 
-        assertGroups(result, "manage", "manage_#");
+        assertGroups(result, "manage");
     }
 
     @Test
@@ -280,7 +280,7 @@ public class KeycloakUserApiTest {
 
         assertGroups(result,
                 "recv_foo%2Fbar", "send_foo%2Fbar", "recv_bar%2Fbaz%2F%23", "send_bar%2Fbaz%2F%23",
-                "monitor", "monitor_#", "manage", "manage_#");
+                "monitor", "manage");
     }
 
     @Test
@@ -303,7 +303,7 @@ public class KeycloakUserApiTest {
 
         final Set<String> result = KeycloakUserApi.createDesiredGroupsSet(auth);
 
-        assertGroups(result, "manage", "manage_#");
+        assertGroups(result, "manage");
     }
 
     /**
diff --git a/systemtests/pom.xml b/systemtests/pom.xml
index de9f6e7f4..e4592689f 100644
--- a/systemtests/pom.xml
+++ b/systemtests/pom.xml
@@ -128,7 +128,7 @@
                     <dependency>
                         <groupId>org.junit.platform</groupId>
                         <artifactId>junit-platform-surefire-provider</artifactId>
-                        <version>${junit.platform.runner.version}</version>
+                        <version>${junit.platform.surefire.provider.version}</version>
                     </dependency>
                 </dependencies>
             </plugin>
diff --git a/systemtests/scripts/test_func.sh b/systemtests/scripts/test_func.sh
index 94ea6b43d..471fd79a9 100755
--- a/systemtests/scripts/test_func.sh
+++ b/systemtests/scripts/test_func.sh
@@ -42,7 +42,9 @@ function export_required_env {
     SANITIZED_NAMESPACE=${SANITIZED_NAMESPACE//\//-}
     KUBERNETES_NAMESPACE=${SANITIZED_NAMESPACE}
 
-    API_URL=$(oc config view -o jsonpath='{.clusters[0].cluster.server}')
+    if oc whoami --show-server=true > /dev/null 2>&1; then
+        API_URL=$(oc whoami --show-server=true)
+    fi
     export KUBERNETES_API_URL=${KUBERNETES_API_URL:-${API_URL}}
     export OPENSHIFT_USER=${OPENSHIFT_USER:-test}
     export OPENSHIFT_PASSWD=${OPENSHIFT_PASSWD:-test}
diff --git a/systemtests/src/main/java/io/enmasse/systemtest/Environment.java b/systemtests/src/main/java/io/enmasse/systemtest/Environment.java
index a8979cfde..076170fd2 100644
--- a/systemtests/src/main/java/io/enmasse/systemtest/Environment.java
+++ b/systemtests/src/main/java/io/enmasse/systemtest/Environment.java
@@ -21,6 +21,7 @@ public class Environment {
     public static final String tokenEnv = "KUBERNETES_API_TOKEN";
     public static final String upgradeEnv = "SYSTEMTESTS_UPGRADED";
     public static final String enmasseVersionProp = "enmasse.version";
+    public static final String domain = "KUBERNETES_DOMAIN";
 
     private final String token = System.getenv(tokenEnv);
     private final String url = System.getenv(urlEnv);
@@ -32,6 +33,7 @@ public class Environment {
     private final boolean upgrade = Boolean.parseBoolean(System.getenv().getOrDefault(upgradeEnv, "false"));
     private final String ocpVersion = System.getenv().getOrDefault(ocpVersionEnv, "3.11");
     private final String enmasseVersion = System.getProperty("enmasse.version");
+    private final String kubernetesDomain = System.getenv().getOrDefault(domain, ".nip.io");
 
     private Environment() {
         String debugFormat = "{}:{}";
@@ -120,4 +122,8 @@ public class Environment {
     public String enmasseVersion() {
         return enmasseVersion;
     }
+
+    public String kubernetesDomain() {
+        return kubernetesDomain;
+    }
 }
diff --git a/systemtests/src/main/java/io/enmasse/systemtest/SystemtestsKubernetesApps.java b/systemtests/src/main/java/io/enmasse/systemtest/SystemtestsKubernetesApps.java
index e256b01ae..9d7050619 100644
--- a/systemtests/src/main/java/io/enmasse/systemtest/SystemtestsKubernetesApps.java
+++ b/systemtests/src/main/java/io/enmasse/systemtest/SystemtestsKubernetesApps.java
@@ -197,6 +197,7 @@ public class SystemtestsKubernetesApps {
     }
 
     private static Ingress getSystemtestsIngressResource(String appName, int port) throws Exception {
+        Environment env = Environment.getInstance();
         IngressBackend backend = new IngressBackend();
         backend.setServiceName(appName);
         backend.setServicePort(new IntOrString(port));
@@ -211,7 +212,7 @@ public class SystemtestsKubernetesApps {
                 .endMetadata()
                 .withNewSpec()
                 .withRules(new IngressRuleBuilder()
-                        .withHost(appName + "." + new URL(Environment.getInstance().getApiUrl()).getHost() + ".nip.io")
+                        .withHost(appName + "." +  (env.kubernetesDomain().equals(".nip.io") ?  new URL(Environment.getInstance().getApiUrl()).getHost() + ".nip.io" : env.kubernetesDomain()))
                         .withNewHttp()
                         .withPaths(path)
                         .endHttp()