Ejemplo n.º 1
0
  @Test
  @Category(PROXY.class)
  public void validUser() throws Exception {
    SocketAddress sa =
        new InetSocketAddress("127.0.0.1", TestProperties.getInteger("webproxy.server.port"));
    Proxy p = new Proxy(Proxy.Type.HTTP, sa);

    URL url = new URL("http://www.google.com/index.html");
    HttpURLConnection con = (HttpURLConnection) url.openConnection(p);

    byte[] encodedUserPwd = Base64.encodeBase64("admin:123".getBytes());
    con.setRequestProperty("Proxy-Authorization", "Basic " + new String(encodedUserPwd));
    con.getInputStream();

    for (int i = 0; i < 100; i++) {
      Thread.sleep(200);

      List<String> uris = server.getAccessedUris();
      for (String uri : uris) {
        if (uri.contains("google.com")) {
          return;
        }
      }
    }

    Assert.fail("Proxy was not able to access google.com");
  }
Ejemplo n.º 2
0
  @Test(expected = IOException.class)
  @Category(PROXY.class)
  public void invalidUser() throws Exception {
    SocketAddress sa =
        new InetSocketAddress("127.0.0.1", TestProperties.getInteger("webproxy.server.port"));
    Proxy p = new Proxy(Proxy.Type.HTTP, sa);

    URL url = new URL("http://www.google.com/index.html");
    HttpURLConnection con = (HttpURLConnection) url.openConnection(p);

    byte[] encodedUserPwd = Base64.encodeBase64("admin:1234".getBytes());
    con.setRequestProperty("Proxy-Authorization", "Basic " + new String(encodedUserPwd));
    con.getInputStream();

    Assert.fail("Proxy was not able to access google.com");
  }