Skip to content

Commit

Permalink
[java] Schema HTTPS in Distributor, SessionQueue, SessionMap (Seleniu…
Browse files Browse the repository at this point in the history
…mHQ#13413)

Signed-off-by: Viet Nguyen Duc <[email protected]>
  • Loading branch information
VietND96 authored Jan 9, 2024
1 parent 10af32c commit 111086d
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ java_library(
"//java/src/org/openqa/selenium/grid/data",
"//java/src/org/openqa/selenium/grid/distributor",
"//java/src/org/openqa/selenium/grid/distributor/selector",
"//java/src/org/openqa/selenium/grid/server",
artifact("com.beust:jcommander"),
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.openqa.selenium.grid.data.SlotMatcher;
import org.openqa.selenium.grid.distributor.Distributor;
import org.openqa.selenium.grid.distributor.selector.SlotSelector;
import org.openqa.selenium.grid.server.BaseServerOptions;

public class DistributorOptions {

Expand Down Expand Up @@ -67,6 +68,8 @@ public URI getDistributorUri() {
return host.get();
}

BaseServerOptions serverOptions = new BaseServerOptions(config);
String schema = (serverOptions.isSecure() || serverOptions.isSelfSigned()) ? "https" : "http";
Optional<Integer> port = config.getInt(DISTRIBUTOR_SECTION, "port");
Optional<String> hostname = config.get(DISTRIBUTOR_SECTION, "hostname");

Expand All @@ -75,7 +78,7 @@ public URI getDistributorUri() {
}

try {
return new URI("http", null, hostname.get(), port.get(), null, null, null);
return new URI(schema, null, hostname.get(), port.get(), null, null, null);
} catch (URISyntaxException e) {
throw new ConfigException(
"Distributor uri configured through host (%s) and port (%d) is not a valid URI",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public SecretOptions(Config config) {

public Secret getRegistrationSecret() {
String secret = "";
if ((isSecure()) && !config.get(SERVER_SECTION, "registration-secret").isPresent()) {
if ((isSecure() || isSelfSigned())
&& !config.get(SERVER_SECTION, "registration-secret").isPresent()) {
try {
secret =
getEncoder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ java_library(
deps = [
"//java:auto-service",
"//java/src/org/openqa/selenium/grid/config",
"//java/src/org/openqa/selenium/grid/server",
"//java/src/org/openqa/selenium/grid/sessionmap",
artifact("com.beust:jcommander"),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Optional;
import org.openqa.selenium.grid.config.Config;
import org.openqa.selenium.grid.config.ConfigException;
import org.openqa.selenium.grid.server.BaseServerOptions;
import org.openqa.selenium.grid.sessionmap.SessionMap;

public class SessionMapOptions {
Expand All @@ -30,7 +31,6 @@ public class SessionMapOptions {

private static final String DEFAULT_SESSION_MAP =
"org.openqa.selenium.grid.sessionmap.remote.RemoteSessionMap";
private static final String DEFAULT_SESSION_MAP_SCHEME = "http";
private final Config config;

public SessionMapOptions(Config config) {
Expand All @@ -39,7 +39,11 @@ public SessionMapOptions(Config config) {

public URI getSessionMapUri() {

String scheme = config.get(SESSIONS_SECTION, "scheme").orElse(DEFAULT_SESSION_MAP_SCHEME);
BaseServerOptions serverOptions = new BaseServerOptions(config);
String scheme =
config
.get(SESSIONS_SECTION, "scheme")
.orElse((serverOptions.isSecure() || serverOptions.isSelfSigned()) ? "https" : "http");

Optional<URI> host =
config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ java_library(
"//java:auto-service",
"//java/src/org/openqa/selenium/grid/config",
"//java/src/org/openqa/selenium/grid/jmx",
"//java/src/org/openqa/selenium/grid/server",
"//java/src/org/openqa/selenium/grid/sessionqueue",
artifact("com.beust:jcommander"),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.openqa.selenium.grid.jmx.JMXHelper;
import org.openqa.selenium.grid.jmx.ManagedAttribute;
import org.openqa.selenium.grid.jmx.ManagedService;
import org.openqa.selenium.grid.server.BaseServerOptions;
import org.openqa.selenium.grid.sessionqueue.NewSessionQueue;

@ManagedService(
Expand Down Expand Up @@ -70,6 +71,8 @@ public URI getSessionQueueUri() {
return host.get();
}

BaseServerOptions serverOptions = new BaseServerOptions(config);
String schema = (serverOptions.isSecure() || serverOptions.isSelfSigned()) ? "https" : "http";
Optional<Integer> port = config.getInt(SESSION_QUEUE_SECTION, "port");
Optional<String> hostname = config.get(SESSION_QUEUE_SECTION, "hostname");

Expand All @@ -78,7 +81,7 @@ public URI getSessionQueueUri() {
}

try {
return new URI("http", null, hostname.get(), port.get(), "", null, null);
return new URI(schema, null, hostname.get(), port.get(), "", null, null);
} catch (URISyntaxException e) {
throw new ConfigException(
"Session queue server uri configured through host (%s) and port (%d) is not a valid URI",
Expand Down

0 comments on commit 111086d

Please sign in to comment.