Skip to content

Commit cb3c1b7

Browse files
authored
Merge 9aac3b0 into 3bfd6c4
2 parents 3bfd6c4 + 9aac3b0 commit cb3c1b7

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

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

+12-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class DistributorOptions {
3131

3232
public static final int DEFAULT_HEALTHCHECK_INTERVAL = 120;
3333
public static final String DISTRIBUTOR_SECTION = "distributor";
34+
private static final String SERVER_SECTION = "server";
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";
@@ -67,6 +68,7 @@ public URI getDistributorUri() {
6768
return host.get();
6869
}
6970

71+
String schema = (isSecure() || isSelfSigned()) ? "https" : "http";
7072
Optional<Integer> port = config.getInt(DISTRIBUTOR_SECTION, "port");
7173
Optional<String> hostname = config.get(DISTRIBUTOR_SECTION, "hostname");
7274

@@ -75,14 +77,23 @@ public URI getDistributorUri() {
7577
}
7678

7779
try {
78-
return new URI("http", null, hostname.get(), port.get(), null, null, null);
80+
return new URI(schema, null, hostname.get(), port.get(), null, null, null);
7981
} catch (URISyntaxException e) {
8082
throw new ConfigException(
8183
"Distributor uri configured through host (%s) and port (%d) is not a valid URI",
8284
hostname.get(), port.get());
8385
}
8486
}
8587

88+
public boolean isSecure() {
89+
return config.get(SERVER_SECTION, "https-private-key").isPresent()
90+
&& config.get(SERVER_SECTION, "https-certificate").isPresent();
91+
}
92+
93+
public boolean isSelfSigned() {
94+
return config.getBool(SERVER_SECTION, "https-self-signed").orElse(false);
95+
}
96+
8697
public Duration getHealthCheckInterval() {
8798
// If the user sets 0s or less, we default to 10s.
8899
int seconds =

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

+14-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
public class SessionMapOptions {
2828

2929
private static final String SESSIONS_SECTION = "sessions";
30+
private static final String SERVER_SECTION = "server";
3031

3132
private static final String DEFAULT_SESSION_MAP =
3233
"org.openqa.selenium.grid.sessionmap.remote.RemoteSessionMap";
33-
private static final String DEFAULT_SESSION_MAP_SCHEME = "http";
3434
private final Config config;
3535

3636
public SessionMapOptions(Config config) {
@@ -39,7 +39,10 @@ public SessionMapOptions(Config config) {
3939

4040
public URI getSessionMapUri() {
4141

42-
String scheme = config.get(SESSIONS_SECTION, "scheme").orElse(DEFAULT_SESSION_MAP_SCHEME);
42+
String scheme =
43+
config
44+
.get(SESSIONS_SECTION, "scheme")
45+
.orElse((isSecure() || isSelfSigned()) ? "https" : "http");
4346

4447
Optional<URI> host =
4548
config
@@ -78,6 +81,15 @@ public URI getSessionMapUri() {
7881
}
7982
}
8083

84+
public boolean isSecure() {
85+
return config.get(SERVER_SECTION, "https-private-key").isPresent()
86+
&& config.get(SERVER_SECTION, "https-certificate").isPresent();
87+
}
88+
89+
public boolean isSelfSigned() {
90+
return config.getBool(SERVER_SECTION, "https-self-signed").orElse(false);
91+
}
92+
8193
public SessionMap getSessionMap() {
8294
return config.getClass(
8395
SESSIONS_SECTION, "implementation", SessionMap.class, DEFAULT_SESSION_MAP);

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

+12-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
public class NewSessionQueueOptions {
3535

3636
static final String SESSION_QUEUE_SECTION = "sessionqueue";
37+
private static final String SERVER_SECTION = "server";
3738
static final int DEFAULT_REQUEST_TIMEOUT = 300;
3839
static final int DEFAULT_REQUEST_TIMEOUT_PERIOD = 10;
3940
static final int DEFAULT_RETRY_INTERVAL = 15;
@@ -70,6 +71,7 @@ public URI getSessionQueueUri() {
7071
return host.get();
7172
}
7273

74+
String schema = (isSecure() || isSelfSigned()) ? "https" : "http";
7375
Optional<Integer> port = config.getInt(SESSION_QUEUE_SECTION, "port");
7476
Optional<String> hostname = config.get(SESSION_QUEUE_SECTION, "hostname");
7577

@@ -78,14 +80,23 @@ public URI getSessionQueueUri() {
7880
}
7981

8082
try {
81-
return new URI("http", null, hostname.get(), port.get(), "", null, null);
83+
return new URI(schema, null, hostname.get(), port.get(), "", null, null);
8284
} catch (URISyntaxException e) {
8385
throw new ConfigException(
8486
"Session queue server uri configured through host (%s) and port (%d) is not a valid URI",
8587
hostname.get(), port.get());
8688
}
8789
}
8890

91+
public boolean isSecure() {
92+
return config.get(SERVER_SECTION, "https-private-key").isPresent()
93+
&& config.get(SERVER_SECTION, "https-certificate").isPresent();
94+
}
95+
96+
public boolean isSelfSigned() {
97+
return config.getBool(SERVER_SECTION, "https-self-signed").orElse(false);
98+
}
99+
89100
public Duration getSessionRequestTimeout() {
90101
// If the user sets 0 or less, we default to 1s.
91102
int timeout =

0 commit comments

Comments
 (0)