You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2016/03/30 15:59:53 UTC

[16/50] brooklyn-server git commit: Fix failing tests because of auth request

Fix failing tests because of auth request

Explicitly disable web server authentication for tests that don't need it.


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/ab65c084
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/ab65c084
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/ab65c084

Branch: refs/heads/master
Commit: ab65c084c8d8055d7776488f420f89ec09e30f02
Parents: 3d3216c
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Mon Mar 7 15:10:10 2016 +0200
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Thu Mar 17 15:27:00 2016 +0200

----------------------------------------------------------------------
 .../brooklyn/launcher/BrooklynLauncher.java     | 14 ++++++++++++--
 .../brooklyn/launcher/BrooklynWebServer.java    |  7 ++++++-
 .../brooklyn/launcher/BrooklynLauncherTest.java | 20 ++++++++++----------
 .../launcher/BrooklynWebServerTest.java         |  4 +++-
 .../brooklyn/launcher/WebAppRunnerTest.java     | 16 ++++++----------
 5 files changed, 37 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/ab65c084/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynLauncher.java
----------------------------------------------------------------------
diff --git a/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynLauncher.java b/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynLauncher.java
index 75bd90e..2ef038d 100644
--- a/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynLauncher.java
+++ b/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynLauncher.java
@@ -45,6 +45,7 @@ import org.apache.brooklyn.launcher.common.BasicLauncher;
 import org.apache.brooklyn.launcher.common.BrooklynPropertiesFactoryHelper;
 import org.apache.brooklyn.launcher.config.StopWhichAppsOnShutdown;
 import org.apache.brooklyn.rest.BrooklynWebConfig;
+import org.apache.brooklyn.rest.security.provider.AnyoneSecurityProvider;
 import org.apache.brooklyn.rest.security.provider.BrooklynUserWithRandomPasswordSecurityProvider;
 import org.apache.brooklyn.rest.util.ShutdownHandler;
 import org.apache.brooklyn.util.exceptions.Exceptions;
@@ -273,7 +274,16 @@ public class BrooklynLauncher extends BasicLauncher<BrooklynLauncher> {
         BrooklynProperties brooklynProperties = (BrooklynProperties) managementContext.getConfig();
 
         // No security options in properties and no command line options overriding.
-        if (Boolean.TRUE.equals(skipSecurityFilter) && bindAddress==null) {
+        Boolean skipSecurity = skipSecurityFilter;
+        if (skipSecurity == null) {
+            String securityProvider = managementContext.getConfig().getConfig(BrooklynWebConfig.SECURITY_PROVIDER_CLASSNAME);
+            // The security provider will let anyone in, but still require a password to be entered.
+            // Skip password request dialog if we know the provider will let users through.
+            if (AnyoneSecurityProvider.class.getName().equals(securityProvider)) {
+                skipSecurity = true;
+            }
+        }
+        if (Boolean.TRUE.equals(skipSecurity) && bindAddress==null) {
             LOG.info("Starting Brooklyn web-console on loopback because security is explicitly disabled and no bind address specified");
             bindAddress = Networking.LOOPBACK;
         } else if (BrooklynWebConfig.hasNoSecurityOptions(managementContext.getConfig())) {
@@ -307,7 +317,7 @@ public class BrooklynLauncher extends BasicLauncher<BrooklynLauncher> {
             if (useHttps!=null) webServer.setHttpsEnabled(useHttps);
             webServer.setShutdownHandler(shutdownHandler);
             webServer.putAttributes(brooklynProperties);
-            webServer.skipSecurity(Boolean.TRUE.equals(skipSecurityFilter));
+            webServer.skipSecurity(Boolean.TRUE.equals(skipSecurity));
             for (WebAppContextProvider webapp : webApps) {
                 webServer.addWar(webapp);
             }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/ab65c084/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynWebServer.java
----------------------------------------------------------------------
diff --git a/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynWebServer.java b/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynWebServer.java
index 4049b01..5e9f9f0 100644
--- a/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynWebServer.java
+++ b/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynWebServer.java
@@ -244,8 +244,13 @@ public class BrooklynWebServer {
         this.securityFilterClazz = filterClazz;
     }
 
-    public void skipSecurity(boolean skipSecurity) {
+    public BrooklynWebServer skipSecurity() {
+        return skipSecurity(true);
+    }
+
+    public BrooklynWebServer skipSecurity(boolean skipSecurity) {
         this.skipSecurity = skipSecurity;
+        return this;
     }
 
     public void setShutdownHandler(@Nullable ShutdownHandler shutdownHandler) {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/ab65c084/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherTest.java
----------------------------------------------------------------------
diff --git a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherTest.java b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherTest.java
index 101a21a..b70c1fe 100644
--- a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherTest.java
+++ b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherTest.java
@@ -32,7 +32,6 @@ import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.core.catalog.internal.CatalogInitialization;
-import org.apache.brooklyn.core.entity.factory.ApplicationBuilder;
 import org.apache.brooklyn.core.internal.BrooklynProperties;
 import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
 import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
@@ -43,7 +42,7 @@ import org.apache.brooklyn.core.test.entity.TestApplicationImpl;
 import org.apache.brooklyn.core.test.entity.TestEntity;
 import org.apache.brooklyn.launcher.common.BrooklynPropertiesFactoryHelperTest;
 import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
-import org.apache.brooklyn.test.HttpTestUtils;
+import org.apache.brooklyn.util.http.HttpAsserts;
 import org.apache.brooklyn.util.io.FileUtil;
 import org.apache.brooklyn.util.net.Urls;
 import org.apache.brooklyn.util.os.Os;
@@ -75,6 +74,7 @@ public class BrooklynLauncherTest {
     public void testStartsWebServerOnExpectectedPort() throws Exception {
         launcher = newLauncherForTests(true)
                 .webconsolePort("10000+")
+                .installSecurityFilter(false)
                 .start();
         
         String webServerUrlStr = launcher.getServerDetails().getWebServerUrl();
@@ -82,7 +82,7 @@ public class BrooklynLauncherTest {
         
         assertEquals(launcher.getApplications(), ImmutableList.of());
         assertTrue(webServerUri.getPort() >= 10000 && webServerUri.getPort() < 10100, "port="+webServerUri.getPort()+"; uri="+webServerUri);
-        HttpTestUtils.assertUrlReachable(webServerUrlStr);
+        HttpAsserts.assertUrlReachable(webServerUrlStr);
     }
     
     // Integration because takes a few seconds to start web-console
@@ -117,7 +117,7 @@ public class BrooklynLauncherTest {
     public void testStartsAppInstance() throws Exception {
         launcher = newLauncherForTests(true)
                 .webconsole(false)
-                .application(new TestApplicationImpl())
+                .application(EntitySpec.create(TestApplicationImpl.class))
                 .start();
         
         assertOnlyApp(launcher, TestApplication.class);
@@ -134,10 +134,11 @@ public class BrooklynLauncherTest {
     }
     
     @Test
+    @SuppressWarnings("deprecation")
     public void testStartsAppFromBuilder() throws Exception {
         launcher = newLauncherForTests(true)
                 .webconsole(false)
-                .application(new ApplicationBuilder(EntitySpec.create(TestApplication.class)) {
+                .application(new org.apache.brooklyn.core.entity.factory.ApplicationBuilder(EntitySpec.create(TestApplication.class)) {
                         @Override protected void doBuild() {
                         }})
                 .start();
@@ -167,9 +168,7 @@ public class BrooklynLauncherTest {
         launcher = newLauncherForTests(true)
                 .webconsole(false)
                 .location("localhost")
-                .application(new ApplicationBuilder(EntitySpec.create(TestApplication.class)) {
-                        @Override protected void doBuild() {
-                        }})
+                .application(EntitySpec.create(TestApplication.class))
                 .start();
         
         Application app = Iterables.find(launcher.getApplications(), Predicates.instanceOf(TestApplication.class));
@@ -254,15 +253,16 @@ public class BrooklynLauncherTest {
                         throw new RuntimeException("deliberate-exception-for-testing");
                     }
                 }))
+                .installSecurityFilter(false)
                 .start();
         // such an error should be thrown, then caught in this calling thread
         ManagementContext mgmt = launcher.getServerDetails().getManagementContext();
         Assert.assertFalse( ((ManagementContextInternal)mgmt).errors().isEmpty() );
         Assert.assertTrue( ((ManagementContextInternal)mgmt).errors().get(0).toString().contains("deliberate"), ""+((ManagementContextInternal)mgmt).errors() );
-        HttpTestUtils.assertContentMatches(
+        HttpAsserts.assertContentMatches(
             Urls.mergePaths(launcher.getServerDetails().getWebServerUrl(), "v1/server/up"), 
             "true");
-        HttpTestUtils.assertContentMatches(
+        HttpAsserts.assertContentMatches(
             Urls.mergePaths(launcher.getServerDetails().getWebServerUrl(), "v1/server/healthy"), 
             "false");
         // TODO test errors api?

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/ab65c084/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynWebServerTest.java
----------------------------------------------------------------------
diff --git a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynWebServerTest.java b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynWebServerTest.java
index eafaa49..2b8406e 100644
--- a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynWebServerTest.java
+++ b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynWebServerTest.java
@@ -88,6 +88,7 @@ public class BrooklynWebServerTest {
     @Test
     public void verifyHttp() throws Exception {
         webServer = new BrooklynWebServer(newManagementContext(brooklynProperties));
+        webServer.skipSecurity();
         try {
             webServer.start();
 
@@ -114,7 +115,7 @@ public class BrooklynWebServerTest {
                 .put("keystorePassword", "password")
                 .build();
         webServer = new BrooklynWebServer(flags, newManagementContext(brooklynProperties));
-        webServer.start();
+        webServer.skipSecurity().start();
         
         try {
             KeyStore keyStore = load("client.ks", "password");
@@ -172,6 +173,7 @@ public class BrooklynWebServerTest {
 
     private void verifyHttpsFromConfig(BrooklynProperties brooklynProperties) throws Exception {
         webServer = new BrooklynWebServer(MutableMap.of(), newManagementContext(brooklynProperties));
+        webServer.skipSecurity();
         webServer.start();
         
         try {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/ab65c084/launcher/src/test/java/org/apache/brooklyn/launcher/WebAppRunnerTest.java
----------------------------------------------------------------------
diff --git a/launcher/src/test/java/org/apache/brooklyn/launcher/WebAppRunnerTest.java b/launcher/src/test/java/org/apache/brooklyn/launcher/WebAppRunnerTest.java
index 36dbfac..a53ea95 100644
--- a/launcher/src/test/java/org/apache/brooklyn/launcher/WebAppRunnerTest.java
+++ b/launcher/src/test/java/org/apache/brooklyn/launcher/WebAppRunnerTest.java
@@ -18,20 +18,16 @@
  */
 package org.apache.brooklyn.launcher;
 
-import org.apache.brooklyn.core.entity.Entities;
-import org.apache.brooklyn.core.internal.BrooklynProperties;
-import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
-import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
-import org.apache.brooklyn.launcher.BrooklynWebServer;
-import org.apache.brooklyn.launcher.BrooklynLauncher;
-import org.apache.brooklyn.launcher.BrooklynServerDetails;
-
 import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.fail;
 
 import java.util.List;
 import java.util.Map;
 
+import org.apache.brooklyn.core.entity.Entities;
+import org.apache.brooklyn.core.internal.BrooklynProperties;
+import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
+import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
 import org.apache.brooklyn.test.HttpTestUtils;
 import org.apache.brooklyn.test.support.TestResourceUnavailableException;
 import org.apache.brooklyn.util.collections.MutableMap;
@@ -75,9 +71,9 @@ public class WebAppRunnerTest {
 
         BrooklynProperties brooklynProperties = BrooklynProperties.Factory.newEmpty();
         brooklynProperties.putAll(bigProps);
-        brooklynProperties.put("brooklyn.webconsole.security.provider","org.apache.brooklyn.rest.security.provider.AnyoneSecurityProvider");
         brooklynProperties.put("brooklyn.webconsole.security.https.required","false");
-        return new BrooklynWebServer(bigProps, newManagementContext(brooklynProperties));
+        return new BrooklynWebServer(bigProps, newManagementContext(brooklynProperties))
+                .skipSecurity();
     }
     
     @Test