Skip to content

Commit

Permalink
Fixing noProxy handling in Grid
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed May 24, 2018
1 parent 2606295 commit 9090f52
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
30 changes: 27 additions & 3 deletions java/client/src/org/openqa/selenium/remote/NewSessionPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.openqa.selenium.json.Json.MAP_TYPE;
import static org.openqa.selenium.remote.CapabilityType.PLATFORM;
import static org.openqa.selenium.remote.CapabilityType.PLATFORM_NAME;
import static org.openqa.selenium.remote.CapabilityType.PROXY;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -57,6 +58,7 @@
import java.io.Reader;
import java.io.StringReader;
import java.io.Writer;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -210,6 +212,7 @@ public void writeTo(Appendable appendable) throws IOException {
.orElse(new ImmutableCapabilities())
.asMap();
}
Map<String, Object> ossFirst = new HashMap<>(first);
if (first.containsKey(CapabilityType.PROXY)) {
Map<String, Object> proxyMap;
Object rawProxy = first.get(CapabilityType.PROXY);
Expand All @@ -221,17 +224,18 @@ public void writeTo(Appendable appendable) throws IOException {
proxyMap = new HashMap<>();
}
if (proxyMap.containsKey("noProxy")) {
Map<String, Object> ossProxyMap = new HashMap<>(proxyMap);
Object rawData = proxyMap.get("noProxy");
if (rawData instanceof List) {
proxyMap.put("noProxy", ((List<String>) rawData).stream().collect(Collectors.joining(",")));
ossProxyMap.put("noProxy", ((List<String>) rawData).stream().collect(Collectors.joining(",")));
}
first.put(CapabilityType.PROXY, proxyMap);
ossFirst.put(CapabilityType.PROXY, ossProxyMap);
}
}

// Write the first capability we get as the desired capability.
json.name("desiredCapabilities");
json.write(first);
json.write(ossFirst);

// And write the first capability for gecko13
json.name("capabilities");
Expand Down Expand Up @@ -410,6 +414,26 @@ private Map<String, Object> convertOssToW3C(Map<String, Object> capabilities) {
toReturn.put(PLATFORM_NAME, String.valueOf(capabilities.get(PLATFORM)));
}

if (capabilities.containsKey(PROXY)) {
Map<String, Object> proxyMap;
Object rawProxy = capabilities.get(CapabilityType.PROXY);
if (rawProxy instanceof Proxy) {
proxyMap = ((Proxy) rawProxy).toJson();
} else if (rawProxy instanceof Map) {
proxyMap = (Map<String, Object>) rawProxy;
} else {
proxyMap = new HashMap<>();
}
if (proxyMap.containsKey("noProxy")) {
Map<String, Object> w3cProxyMap = new HashMap<>(proxyMap);
Object rawData = proxyMap.get("noProxy");
if (rawData instanceof String) {
w3cProxyMap.put("noProxy", Arrays.asList(((String) rawData).split(",\\s*")));
}
toReturn.put(CapabilityType.PROXY, w3cProxyMap);
}
}

return toReturn;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.remote.Dialect;

import java.util.List;
Expand Down Expand Up @@ -169,7 +170,7 @@ public boolean isSupporting(Capabilities capabilities) {

@Override
public Optional<ActiveSession> apply(Set<Dialect> downstreamDialects, Capabilities caps) {
LOG.info("Capabilities are: " + caps);
LOG.info("Capabilities are: " + new Json().toJson(caps));
return factories.stream()
.filter(factory -> factory.isSupporting(caps))
.peek(factory -> LOG.info(String.format("Matched factory %s", factory)))
Expand Down

0 comments on commit 9090f52

Please sign in to comment.