From 618fa50b90711fffb6d39de233b1bcd22c715b04 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 24 Oct 2013 13:10:38 +0200 Subject: SONAR-4741 Bind to 0.0.0.0 by default --- .../src/main/assembly/conf/sonar.properties | 2 +- .../java/org/sonar/application/Connectors.java | 2 +- .../java/org/sonar/application/ConnectorsTest.java | 51 ++++++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) (limited to 'sonar-application') diff --git a/sonar-application/src/main/assembly/conf/sonar.properties b/sonar-application/src/main/assembly/conf/sonar.properties index 6f4308af6c9..569a4f01017 100644 --- a/sonar-application/src/main/assembly/conf/sonar.properties +++ b/sonar-application/src/main/assembly/conf/sonar.properties @@ -89,7 +89,7 @@ sonar.jdbc.timeBetweenEvictionRunsMillis=30000 # Binding IP address. For servers with more than one IP address, this property specifies which # address will be used for listening on the specified ports. # By default, ports will be used on all IP addresses associated with the server. -#sonar.web.host= +#sonar.web.host=0.0.0.0 # Web context. When set, it must start with forward slash (for example /sonarqube). # The default value is root context (empty value). diff --git a/sonar-application/src/main/java/org/sonar/application/Connectors.java b/sonar-application/src/main/java/org/sonar/application/Connectors.java index 617b7d6a428..2fdb9c8ebe7 100644 --- a/sonar-application/src/main/java/org/sonar/application/Connectors.java +++ b/sonar-application/src/main/java/org/sonar/application/Connectors.java @@ -113,7 +113,7 @@ class Connectors { private static Connector newConnector(Props props, String protocol, String scheme) { Connector connector = new Connector(protocol); connector.setURIEncoding("UTF-8"); - connector.setProperty("address", props.of("sonar.web.host")); + connector.setProperty("address", props.of("sonar.web.host", "0.0.0.0")); configurePool(props, connector, scheme); configureCompression(connector); return connector; diff --git a/sonar-application/src/test/java/org/sonar/application/ConnectorsTest.java b/sonar-application/src/test/java/org/sonar/application/ConnectorsTest.java index e95af633028..4d8e9b4773c 100644 --- a/sonar-application/src/test/java/org/sonar/application/ConnectorsTest.java +++ b/sonar-application/src/test/java/org/sonar/application/ConnectorsTest.java @@ -26,6 +26,7 @@ import org.junit.Test; import org.mockito.ArgumentMatcher; import org.mockito.Mockito; +import java.net.InetAddress; import java.util.Map; import java.util.Properties; @@ -167,6 +168,56 @@ public class ConnectorsTest { } } + @Test + public void bind_to_all_addresses_by_default() throws Exception { + Properties p = new Properties(); + p.setProperty("sonar.web.port", "9000"); + p.setProperty("sonar.web.https.port", "9443"); + + Connectors.configure(tomcat, new Props(p)); + + verify(tomcat.getService()).addConnector(argThat(new ArgumentMatcher() { + @Override + public boolean matches(Object o) { + Connector c = (Connector) o; + return c.getScheme().equals("http") && c.getPort() == 9000 && ((InetAddress)c.getProperty("address")).getHostAddress().equals("0.0.0.0"); + } + })); + verify(tomcat.getService()).addConnector(argThat(new ArgumentMatcher() { + @Override + public boolean matches(Object o) { + Connector c = (Connector) o; + return c.getScheme().equals("https") && c.getPort() == 9443 && ((InetAddress)c.getProperty("address")).getHostAddress().equals("0.0.0.0"); + } + })); + } + + @Test + public void bind_to_specific_address() throws Exception { + Properties p = new Properties(); + p.setProperty("sonar.web.port", "9000"); + p.setProperty("sonar.web.https.port", "9443"); + p.setProperty("sonar.web.host", "1.2.3.4"); + + Connectors.configure(tomcat, new Props(p)); + + verify(tomcat.getService()).addConnector(argThat(new ArgumentMatcher() { + @Override + public boolean matches(Object o) { + Connector c = (Connector) o; + return c.getScheme().equals("http") && c.getPort() == 9000 && ((InetAddress)c.getProperty("address")).getHostAddress().equals("1.2.3.4"); + } + })); + verify(tomcat.getService()).addConnector(argThat(new ArgumentMatcher() { + @Override + public boolean matches(Object o) { + Connector c = (Connector) o; + return c.getScheme().equals("https") && c.getPort() == 9443 && ((InetAddress)c.getProperty("address")).getHostAddress().equals("1.2.3.4"); + } + })); + } + + //---- shutdown port @Test -- cgit v1.2.3