Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.openqa.selenium.RetrySessionRequestException;
import org.openqa.selenium.SessionNotCreatedException;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.UsernameAndPassword;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.docker.Container;
import org.openqa.selenium.docker.ContainerConfig;
Expand Down Expand Up @@ -186,6 +187,7 @@ public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sess
URL remoteAddress = getUrl(port, containerIp);
ClientConfig clientConfig =
ClientConfig.defaultConfig().baseUrl(remoteAddress).readTimeout(sessionTimeout);
clientConfig = applyBasicAuth(clientConfig);
HttpClient client = clientFactory.createClient(clientConfig);

attributeMap.put("docker.browser.image", browserImage.toString());
Expand Down Expand Up @@ -520,10 +522,28 @@ private void waitForServerToStart(HttpClient client, Duration duration) {
obj -> {
HttpResponse response = client.execute(new HttpRequest(GET, "/status"));
LOG.fine(string(response));
if (401 == response.getStatus()) {
LOG.warning(
"Server requires basic authentication. "
+ "Set SE_ROUTER_USERNAME and SE_ROUTER_PASSWORD environment variables "
+ "to provide credentials.");
Comment thread
VietND96 marked this conversation as resolved.
Comment thread
VietND96 marked this conversation as resolved.
}
return 200 == response.getStatus();
});
}

private ClientConfig applyBasicAuth(ClientConfig clientConfig) {
String routerUsername = System.getenv("SE_ROUTER_USERNAME");
String routerPassword = System.getenv("SE_ROUTER_PASSWORD");
if (routerUsername != null
&& !routerUsername.isEmpty()
&& routerPassword != null
&& !routerPassword.isEmpty()) {
return clientConfig.authenticateAs(new UsernameAndPassword(routerUsername, routerPassword));
}
return clientConfig;
}

private URL getUrl(int port, String containerIp) {
try {
String host = "localhost";
Expand Down
Loading