You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2016/11/02 09:26:34 UTC

karaf git commit: [KARAF-3400] Add an integration test to verify Karaf can start properly when running under a security manager

Repository: karaf
Updated Branches:
  refs/heads/master d0e8e3d6e -> 28aa4dd85


[KARAF-3400] Add an integration test to verify Karaf can start properly when running under a security manager

Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/28aa4dd8
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/28aa4dd8
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/28aa4dd8

Branch: refs/heads/master
Commit: 28aa4dd855b47bd96b29ef13f84e46d6f533fdfc
Parents: d0e8e3d
Author: Guillaume Nodet <gn...@apache.org>
Authored: Wed Nov 2 10:16:19 2016 +0100
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Wed Nov 2 10:16:19 2016 +0100

----------------------------------------------------------------------
 itests/pom.xml                                  | 10 ++
 .../apache/karaf/itests/JavaSecurityTest.java   | 99 ++++++++++++++++++++
 2 files changed, 109 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/28aa4dd8/itests/pom.xml
----------------------------------------------------------------------
diff --git a/itests/pom.xml b/itests/pom.xml
index c4d080f..490b7d0 100644
--- a/itests/pom.xml
+++ b/itests/pom.xml
@@ -124,6 +124,16 @@
         </dependency>
 
         <dependency>
+            <groupId>org.apache.karaf.bundle</groupId>
+            <artifactId>org.apache.karaf.bundle.core</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.framework.security</artifactId>
+        </dependency>
+
+        <dependency>
             <groupId>org.apache.servicemix.bundles</groupId>
             <artifactId>org.apache.servicemix.bundles.not-yet-commons-ssl</artifactId>
             <version>0.3.11_1</version>

http://git-wip-us.apache.org/repos/asf/karaf/blob/28aa4dd8/itests/src/test/java/org/apache/karaf/itests/JavaSecurityTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/JavaSecurityTest.java b/itests/src/test/java/org/apache/karaf/itests/JavaSecurityTest.java
new file mode 100644
index 0000000..9fc3a05
--- /dev/null
+++ b/itests/src/test/java/org/apache/karaf/itests/JavaSecurityTest.java
@@ -0,0 +1,99 @@
+/*
+ * 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.
+ */
+package org.apache.karaf.itests;
+
+import org.apache.karaf.bundle.core.BundleInfo;
+import org.apache.karaf.bundle.core.BundleService;
+import org.apache.karaf.bundle.core.BundleState;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.MavenUtils;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.osgi.framework.Bundle;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.*;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+import static org.ops4j.pax.exam.CoreOptions.maven;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.*;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class JavaSecurityTest extends KarafTestSupport {
+
+    @Configuration
+    public Option[] config() {
+        String version = MavenUtils.getArtifactVersion("org.apache.felix", "org.apache.felix.framework.security");
+        String url = maven("org.apache.felix", "org.apache.felix.framework.security", version).getURL();
+        Path temp;
+        try {
+            temp = Files.createTempFile("org.apache.felix.framework.security-" + version + "-", ".jar");
+            System.setProperty("java.protocol.handler.pkgs", "org.ops4j.pax.url");
+            try (InputStream is = new URL(url).openStream()) {
+                Files.copy(is, temp, StandardCopyOption.REPLACE_EXISTING);
+            }
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+
+
+        List<Option> options = new ArrayList<>(Arrays.asList(super.config()));
+        // Add some extra options used by this test...
+        options.addAll(Arrays.asList(
+            editConfigurationFilePut("etc/system.properties", "java.security.policy", "${karaf.etc}/all.policy"),
+            editConfigurationFilePut("etc/system.properties", "org.osgi.framework.security", "osgi"),
+            editConfigurationFilePut("etc/system.properties", "org.osgi.framework.trust.repositories", "${karaf.etc}/trustStore.ks"),
+            editConfigurationFilePut("etc/startup.properties", "mvn:org.apache.felix/org.apache.felix.framework.security/" + version, "1"),
+            replaceConfigurationFile("system/org/apache/felix/org.apache.felix.framework.security/" + version + "/org.apache.felix.framework.security-" + version + ".jar", temp.toFile())));
+        return options.toArray(new Option[] {});
+    }
+
+    @Test
+    public void testJavaSecurity() throws Exception {
+        assertNotNull("Karaf should run under a security manager", System.getSecurityManager());
+
+        BundleService service = getOsgiService(BundleService.class);
+        long tried = 0;
+        while (true) {
+            Map<Bundle, BundleState> incorrect = new HashMap<>();
+            for (Bundle bundle : bundleContext.getBundles()) {
+                BundleInfo info = service.getInfo(bundle);
+                BundleState state = info.getState();
+                if (state != BundleState.Active && state != BundleState.Resolved) {
+                    incorrect.put(bundle, state);
+                }
+            }
+            if (incorrect.isEmpty()) {
+                break;
+            } else {
+                if (++tried >= 10) {
+                    fail("Unable to start bundles correctly: " + incorrect);
+                }
+                Thread.sleep(100);
+            }
+        }
+    }
+
+}