Skip to content

Commit c24a50f

Browse files
committed
[grid] Checking config URIs have a host
This is needed because when GraphQL is queried and no host is present in the URI, things blow up. Relates to #9431
1 parent 2074698 commit c24a50f

File tree

7 files changed

+29
-17
lines changed

7 files changed

+29
-17
lines changed

java/server/src/org/openqa/selenium/docker/internal/Reference.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ public boolean equals(Object o) {
160160

161161
Reference that = (Reference) o;
162162
return this.domain.equals(that.domain) &&
163-
this.name.equals(that.name) &&
164-
Objects.equals(tag, that.tag) &&
165-
Objects.equals(digest, that.digest);
163+
this.name.equals(that.name) &&
164+
Objects.equals(tag, that.tag) &&
165+
Objects.equals(digest, that.digest);
166166
}
167167

168168
@Override

java/server/src/org/openqa/selenium/grid/distributor/config/DistributorOptions.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@
3030

3131
public class DistributorOptions {
3232

33+
public static final int DEFAULT_HEALTHCHECK_INTERVAL = 300;
3334
static final String DISTRIBUTOR_SECTION = "distributor";
3435
static final String DEFAULT_DISTRIBUTOR_IMPLEMENTATION =
3536
"org.openqa.selenium.grid.distributor.local.LocalDistributor";
3637
static final String DEFAULT_SLOT_MATCHER = "org.openqa.selenium.grid.data.DefaultSlotMatcher";
3738
static final String DEFAULT_SLOT_SELECTOR_IMPLEMENTATION =
3839
"org.openqa.selenium.grid.distributor.selector.DefaultSlotSelector";
3940
static final boolean DEFAULT_REJECT_UNSUPPORTED_CAPS = false;
40-
41-
public static final int DEFAULT_HEALTHCHECK_INTERVAL = 300;
42-
4341
private final Config config;
4442

4543
public DistributorOptions(Config config) {
@@ -49,7 +47,11 @@ public DistributorOptions(Config config) {
4947
public URI getDistributorUri() {
5048
Optional<URI> host = config.get(DISTRIBUTOR_SECTION, "host").map(str -> {
5149
try {
52-
return new URI(str);
50+
URI distributorUri = new URI(str);
51+
if (distributorUri.getHost() == null || distributorUri.getPort() == -1) {
52+
throw new ConfigException("Undefined host or port in Distributor server URI: " + str);
53+
}
54+
return distributorUri;
5355
} catch (URISyntaxException e) {
5456
throw new ConfigException("Distributor URI is not a valid URI: " + str);
5557
}

java/server/src/org/openqa/selenium/grid/distributor/httpd/DistributorServer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.google.common.collect.ImmutableMap;
2222
import com.google.common.collect.ImmutableSet;
2323
import com.google.common.net.MediaType;
24+
2425
import org.openqa.selenium.BuildInfo;
2526
import org.openqa.selenium.cli.CliCommand;
2627
import org.openqa.selenium.grid.TemplateGridServerCommand;
@@ -119,7 +120,7 @@ protected void execute(Config config) {
119120

120121
BuildInfo info = new BuildInfo();
121122
LOG.info(String.format(
122-
"Started Selenium distributor %s (revision %s): %s",
123+
"Started Selenium Distributor %s (revision %s): %s",
123124
info.getReleaseLabel(),
124125
info.getBuildRevision(),
125126
server.getUrl()));

java/server/src/org/openqa/selenium/grid/sessionmap/config/SessionMapOptions.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,13 @@ public URI getSessionMapUri() {
4545

4646
Optional<URI> host = config.get(SESSIONS_SECTION, "host").map(str -> {
4747
try {
48-
return new URI(str);
48+
URI sessionUri = new URI(str);
49+
if (sessionUri.getHost() == null || sessionUri.getPort() == -1) {
50+
throw new ConfigException("Undefined host or port in SessionMap server URI: " + str);
51+
}
52+
return sessionUri;
4953
} catch (URISyntaxException e) {
50-
throw new ConfigException("Session map server URI is not a valid URI: " + str);
54+
throw new ConfigException("Session Map server URI is not a valid URI: " + str);
5155
}
5256
});
5357

java/server/src/org/openqa/selenium/grid/sessionmap/httpd/SessionMapServer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
import com.google.auto.service.AutoService;
2121
import com.google.common.collect.ImmutableMap;
2222
import com.google.common.collect.ImmutableSet;
23+
2324
import org.openqa.selenium.BuildInfo;
2425
import org.openqa.selenium.cli.CliCommand;
2526
import org.openqa.selenium.grid.TemplateGridServerCommand;
2627
import org.openqa.selenium.grid.config.Config;
2728
import org.openqa.selenium.grid.config.Role;
28-
import org.openqa.selenium.grid.server.BaseServerOptions;
2929
import org.openqa.selenium.grid.server.Server;
3030
import org.openqa.selenium.grid.sessionmap.SessionMap;
3131
import org.openqa.selenium.grid.sessionmap.config.SessionMapOptions;
@@ -108,7 +108,7 @@ protected void execute(Config config) {
108108

109109
BuildInfo info = new BuildInfo();
110110
LOG.info(String.format(
111-
"Started Selenium session map %s (revision %s): %s",
111+
"Started Selenium SessionMap %s (revision %s): %s",
112112
info.getReleaseLabel(),
113113
info.getBuildRevision(),
114114
server.getUrl()));

java/server/src/org/openqa/selenium/grid/sessionqueue/config/NewSessionQueueOptions.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ public URI getSessionQueueUri() {
3939

4040
Optional<URI> host = config.get(SESSION_QUEUE_SECTION, "host").map(str -> {
4141
try {
42-
return new URI(str);
42+
URI sessionQueueUri = new URI(str);
43+
if (sessionQueueUri.getHost() == null || sessionQueueUri.getPort() == -1) {
44+
throw new ConfigException("Undefined host or port in SessionQueue server URI: " + str);
45+
}
46+
return sessionQueueUri;
4347
} catch (URISyntaxException e) {
4448
throw new ConfigException("Session queue server URI is not a valid URI: " + str);
4549
}

java/server/src/org/openqa/selenium/grid/sessionqueue/httpd/NewSessionQueueServer.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.google.auto.service.AutoService;
2121
import com.google.common.collect.ImmutableMap;
2222
import com.google.common.collect.ImmutableSet;
23+
2324
import org.openqa.selenium.BuildInfo;
2425
import org.openqa.selenium.cli.CliCommand;
2526
import org.openqa.selenium.grid.TemplateGridServerCommand;
@@ -110,9 +111,9 @@ protected void execute(Config config) {
110111

111112
BuildInfo info = new BuildInfo();
112113
LOG.info(String.format(
113-
"Started Selenium New Session Queue %s (revision %s): %s",
114-
info.getReleaseLabel(),
115-
info.getBuildRevision(),
116-
server.getUrl()));
114+
"Started Selenium SessionQueue %s (revision %s): %s",
115+
info.getReleaseLabel(),
116+
info.getBuildRevision(),
117+
server.getUrl()));
117118
}
118119
}

0 commit comments

Comments
 (0)