use of org.sonatype.goodies.httpfixture.server.jetty.behaviour.Content in project goodies by sonatype.
the class JettyProxyProviderTest method testAuthAfterProxyAuthGetFail401.
@Test
public void testAuthAfterProxyAuthGetFail401() throws Exception {
JettyProxyProvider proxy = new JettyProxyProvider("u", "p");
proxy.addBehaviour("/*", new Debug(), new Content());
proxy.addAuthentication("/*", "BASIC");
proxy.addUser("user", "password");
proxy.start();
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
if (getRequestingHost().equals("localhost")) {
String password = "p";
return new PasswordAuthentication("u", password.toCharArray());
}
return super.getPasswordAuthentication();
}
});
URL url = new URL("http://speutel.invalid/foo");
SocketAddress sa = new InetSocketAddress("localhost", proxy.getPort());
Proxy p = new Proxy(Type.HTTP, sa);
HttpURLConnection conn = (HttpURLConnection) url.openConnection(p);
try {
conn.setDoInput(true);
conn.connect();
assertEquals(401, conn.getResponseCode());
} finally {
conn.disconnect();
}
}
use of org.sonatype.goodies.httpfixture.server.jetty.behaviour.Content in project goodies by sonatype.
the class JettyProxyProviderTest method testProxyAuthGet.
@Test
public void testProxyAuthGet() throws Exception {
JettyProxyProvider proxy = new JettyProxyProvider("u", "p");
proxy.addBehaviour("/*", new Debug(), new Content());
proxy.start();
URL url = new URL("http://speutel.invalid/foo");
SocketAddress sa = new InetSocketAddress("localhost", proxy.getPort());
Proxy p = new Proxy(Type.HTTP, sa);
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
if (getRequestingHost().equals("localhost")) {
String password = "p";
return new PasswordAuthentication("u", password.toCharArray());
}
return super.getPasswordAuthentication();
}
});
HttpURLConnection conn = (HttpURLConnection) url.openConnection(p);
conn.setDoInput(true);
conn.connect();
assertEquals(200, conn.getResponseCode());
assertEquals("foo", read(conn.getContent()).trim());
conn.disconnect();
}
use of org.sonatype.goodies.httpfixture.server.jetty.behaviour.Content in project goodies by sonatype.
the class JettyProxyProviderTest method testAuthAfterProxyAuthGet.
@Test
public void testAuthAfterProxyAuthGet() throws Exception {
JettyProxyProvider proxy = new JettyProxyProvider("u", "p");
proxy.addBehaviour("/*", new Debug(), new Content());
proxy.addAuthentication("/*", "BASIC");
proxy.addUser("user", "password");
proxy.start();
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
if (getRequestingHost().equals("localhost")) {
String password = "p";
return new PasswordAuthentication("u", password.toCharArray());
} else {
String password = "password";
return new PasswordAuthentication("user", password.toCharArray());
}
}
});
URL url = new URL("http://speutel.invalid/foo");
SocketAddress sa = new InetSocketAddress("localhost", proxy.getPort());
Proxy p = new Proxy(Type.HTTP, sa);
HttpURLConnection conn = (HttpURLConnection) url.openConnection(p);
try {
conn.setDoInput(true);
conn.connect();
assertEquals(200, conn.getResponseCode());
} finally {
conn.disconnect();
}
}
use of org.sonatype.goodies.httpfixture.server.jetty.behaviour.Content in project goodies by sonatype.
the class JettyProxyProviderTest method testProxyAuthGetFail407.
@Test
public void testProxyAuthGetFail407() throws Exception {
JettyProxyProvider proxy = new JettyProxyProvider("u", "p");
proxy.addBehaviour("/*", new Debug(), new Content());
proxy.start();
URL url = new URL("http://speutel.invalid/foo");
SocketAddress sa = new InetSocketAddress("localhost", proxy.getPort());
Proxy p = new Proxy(Type.HTTP, sa);
HttpURLConnection conn = (HttpURLConnection) url.openConnection(p);
try {
conn.setDoInput(true);
conn.connect();
conn.getResponseCode();
} catch (IOException e) {
assertTrue("expected status code 407", e.getMessage().contains("407"));
} finally {
conn.disconnect();
}
}
use of org.sonatype.goodies.httpfixture.server.jetty.behaviour.Content in project goodies by sonatype.
the class JettyProxyProviderTest method testProxyGet.
@Test
public void testProxyGet() throws Exception {
JettyProxyProvider proxy = new JettyProxyProvider();
proxy.addBehaviour("/*", new Debug(), new Content());
proxy.start();
URL url = new URL("http://speutel.invalid/foo");
SocketAddress sa = new InetSocketAddress("localhost", proxy.getPort());
Proxy p = new Proxy(Type.HTTP, sa);
HttpURLConnection conn = (HttpURLConnection) url.openConnection(p);
conn.setDoInput(true);
conn.connect();
assertEquals(200, conn.getResponseCode());
assertEquals("foo", read(conn.getContent()).trim());
conn.disconnect();
}
Aggregations