|
51 | 51 | import org.openqa.selenium.RetrySessionRequestException; |
52 | 52 | import org.openqa.selenium.SessionNotCreatedException; |
53 | 53 | import org.openqa.selenium.TimeoutException; |
| 54 | +import org.openqa.selenium.UsernameAndPassword; |
54 | 55 | import org.openqa.selenium.WebDriverException; |
55 | 56 | import org.openqa.selenium.docker.Container; |
56 | 57 | import org.openqa.selenium.docker.ContainerConfig; |
@@ -186,6 +187,7 @@ public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sess |
186 | 187 | URL remoteAddress = getUrl(port, containerIp); |
187 | 188 | ClientConfig clientConfig = |
188 | 189 | ClientConfig.defaultConfig().baseUrl(remoteAddress).readTimeout(sessionTimeout); |
| 190 | + clientConfig = applyBasicAuth(clientConfig); |
189 | 191 | HttpClient client = clientFactory.createClient(clientConfig); |
190 | 192 |
|
191 | 193 | attributeMap.put("docker.browser.image", browserImage.toString()); |
@@ -520,10 +522,28 @@ private void waitForServerToStart(HttpClient client, Duration duration) { |
520 | 522 | obj -> { |
521 | 523 | HttpResponse response = client.execute(new HttpRequest(GET, "/status")); |
522 | 524 | LOG.fine(string(response)); |
| 525 | + if (401 == response.getStatus()) { |
| 526 | + LOG.warning( |
| 527 | + "Server requires basic authentication. " |
| 528 | + + "Set SE_ROUTER_USERNAME and SE_ROUTER_PASSWORD environment variables " |
| 529 | + + "to provide credentials."); |
| 530 | + } |
523 | 531 | return 200 == response.getStatus(); |
524 | 532 | }); |
525 | 533 | } |
526 | 534 |
|
| 535 | + private ClientConfig applyBasicAuth(ClientConfig clientConfig) { |
| 536 | + String routerUsername = System.getenv("SE_ROUTER_USERNAME"); |
| 537 | + String routerPassword = System.getenv("SE_ROUTER_PASSWORD"); |
| 538 | + if (routerUsername != null |
| 539 | + && !routerUsername.isEmpty() |
| 540 | + && routerPassword != null |
| 541 | + && !routerPassword.isEmpty()) { |
| 542 | + return clientConfig.authenticateAs(new UsernameAndPassword(routerUsername, routerPassword)); |
| 543 | + } |
| 544 | + return clientConfig; |
| 545 | + } |
| 546 | + |
527 | 547 | private URL getUrl(int port, String containerIp) { |
528 | 548 | try { |
529 | 549 | String host = "localhost"; |
|
0 commit comments