Пример #1
0
  public void testFinalLineOfFunctionShouldRedirectToDefaultProxy() throws IOException {
    DoNotUseProxyPac pac = new DoNotUseProxyPac();

    String config = captureOutput(pac);
    assertTrue(config, config.endsWith("{\n}\n"));

    pac.defaults().toProxy("http://localhost:1010");
    config = captureOutput(pac);
    assertTrue(config, config.endsWith("return 'PROXY http://localhost:1010';\n}\n"));

    pac.defaults().toNoProxy();
    config = captureOutput(pac);
    assertTrue(config, config.endsWith("return 'DIRECT';\n}\n"));
  }
Пример #2
0
  // 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 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"));
  }