// This is going to be a whole heap of fun. public void testShouldAllowAPacToBeBasedOffAnExistingPacFile() throws IOException { // We should allow people to override the settings in the given pac // The strategy will be to rename the method we care about to something else // And then include the original (JS) source code. How badly can this fail? File example = File.createTempFile("example", "pac"); example.deleteOnExit(); FileWriter out = new FileWriter(example); out.append(EXAMPLE_PAC); out.close(); DoNotUseProxyPac pac = new DoNotUseProxyPac(); pac.map("/foobar/*").toNoProxy(); pac.defaults().toProxy("http://example.com:8080/se-server"); pac.deriveFrom(example.toURI()); String converted = captureOutput(pac); assertEquals( converted, "function originalFindProxyForURL(u, h) { if (u.contains('fishy') return 'DIRECT'; }\n" + "function isFishy() { return false; }\n" + "function FindProxyForURL(url, host) {\n" + " if (shExpMatch(url, '/foobar/*')) { return 'DIRECT'; }\n" + "\n" + " var value = originalFindProxyForURL(host, url);\n" + " if (value) { return value; }\n" + "\n" + " return 'PROXY http://example.com:8080/se-server';\n" + "}\n", converted); }
public void testShouldAllowSpecificUrlsToBePassedThroughDirectly() throws IOException { DoNotUseProxyPac pac = new DoNotUseProxyPac(); pac.map("http://seleniumhq.org/cheese").toNoProxy(); String config = captureOutput(pac); assertTrue( config, config.contains( "if (shExpMatch(url, 'http://seleniumhq.org/cheese')) {" + " return 'DIRECT'; " + "}")); }
// See: http://support.microsoft.com/kb/274204 public void testShouldUseJsRegexIfIEWouldNotHandleTheMappingUrl() throws IOException { DoNotUseProxyPac pac = new DoNotUseProxyPac(); pac.map("/[a-zA-Z]{4}.microsoft.com/").toProxy("http://localhost:8080/selenium-server/"); String config = captureOutput(pac); assertTrue( config, config.contains( "if (/[a-zA-Z]{4}.microsoft.com/.test(url)) {" + " return 'PROXY http://localhost:8080/selenium-server/'; " + "}")); }
public void testShouldAllowBasicWildCarding() throws IOException { DoNotUseProxyPac pac = new DoNotUseProxyPac(); pac.map("*/selenium-server/*").toProxy("http://localhost:8080/selenium-server/"); String config = captureOutput(pac); assertTrue( config, config.contains( "if (shExpMatch(url, '*/selenium-server/*')) {" + " return 'PROXY http://localhost:8080/selenium-server/'; " + "}")); }
public void testShouldConvertAProxyPacProperly() throws JSONException { DoNotUseProxyPac pac = new DoNotUseProxyPac(); pac.map("*/selenium/*").toProxy("http://localhost:8080/selenium-server"); pac.map("/[a-zA-Z]{4}.microsoft.com/").toProxy("http://localhost:1010/selenium-server/"); pac.map("/flibble*").toNoProxy(); pac.mapHost("www.google.com").toProxy("http://fishy.com/"); pac.mapHost("seleniumhq.org").toNoProxy(); pac.defaults().toNoProxy(); String json = new BeanToJsonConverter().convert(pac); JSONObject converted = new JSONObject(json); assertEquals( "http://localhost:8080/selenium-server", converted.getJSONObject("proxiedUrls").get("*/selenium/*")); assertEquals( "http://localhost:1010/selenium-server/", converted.getJSONObject("proxiedRegexUrls").get("/[a-zA-Z]{4}.microsoft.com/")); assertEquals("/flibble*", converted.getJSONArray("directUrls").get(0)); assertEquals("seleniumhq.org", converted.getJSONArray("directHosts").get(0)); assertEquals( "http://fishy.com/", converted.getJSONObject("proxiedHosts").get("www.google.com")); assertEquals("'DIRECT'", converted.get("defaultProxy")); }