summaryrefslogtreecommitdiffstats
path: root/sonar-application
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-10-24 13:10:38 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2013-10-24 13:10:38 +0200
commit618fa50b90711fffb6d39de233b1bcd22c715b04 (patch)
tree5aa3efcd4c17313c0ce0c830c23e58cecb169bdd /sonar-application
parent680f549abb87cc79b0d09a07add1a666dd2d0387 (diff)
downloadsonarqube-618fa50b90711fffb6d39de233b1bcd22c715b04.tar.gz
sonarqube-618fa50b90711fffb6d39de233b1bcd22c715b04.zip
SONAR-4741 Bind to 0.0.0.0 by default
Diffstat (limited to 'sonar-application')
-rw-r--r--sonar-application/src/main/assembly/conf/sonar.properties2
-rw-r--r--sonar-application/src/main/java/org/sonar/application/Connectors.java2
-rw-r--r--sonar-application/src/test/java/org/sonar/application/ConnectorsTest.java51
3 files changed, 53 insertions, 2 deletions
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<Connector>() {
+ @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<Connector>() {
+ @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<Connector>() {
+ @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<Connector>() {
+ @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