use of org.apache.commons.httpclient.FeedbackService in project ecf by eclipse.
the class TestBasicAuth method testHeadBasicAuthentication.
public void testHeadBasicAuthentication() throws Exception {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("testuser", "testpass");
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
HttpState state = new HttpState();
AuthScope authscope = new AuthScope(this.server.getLocalAddress(), this.server.getLocalPort(), "test");
state.setCredentials(authscope, creds);
this.client.setState(state);
this.server.setRequestHandler(handlerchain);
HeadMethod head = new HeadMethod("/test/");
try {
this.client.executeMethod(head);
} finally {
head.releaseConnection();
}
assertNotNull(head.getStatusLine());
assertEquals(HttpStatus.SC_OK, head.getStatusLine().getStatusCode());
Header auth = head.getRequestHeader("Authorization");
assertNotNull(auth);
String expected = "Basic " + EncodingUtil.getAsciiString(Base64.encodeBase64(EncodingUtil.getAsciiBytes("testuser:testpass")));
assertEquals(expected, auth.getValue());
AuthState authstate = head.getHostAuthState();
assertNotNull(authstate.getAuthScheme());
assertTrue(authstate.getAuthScheme() instanceof BasicScheme);
assertEquals("test", authstate.getRealm());
}
use of org.apache.commons.httpclient.FeedbackService in project ecf by eclipse.
the class TestBasicAuth method testBasicAuthenticationWithDefaultCreds.
public void testBasicAuthenticationWithDefaultCreds() throws Exception {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("testuser", "testpass");
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
HttpState state = new HttpState();
state.setCredentials(AuthScope.ANY, creds);
this.client.setState(state);
this.server.setRequestHandler(handlerchain);
GetMethod httpget = new GetMethod("/test/");
try {
this.client.executeMethod(httpget);
} finally {
httpget.releaseConnection();
}
assertNotNull(httpget.getStatusLine());
assertEquals(HttpStatus.SC_OK, httpget.getStatusLine().getStatusCode());
Header auth = httpget.getRequestHeader("Authorization");
assertNotNull(auth);
String expected = "Basic " + EncodingUtil.getAsciiString(Base64.encodeBase64(EncodingUtil.getAsciiBytes("testuser:testpass")));
assertEquals(expected, auth.getValue());
AuthState authstate = httpget.getHostAuthState();
assertNotNull(authstate.getAuthScheme());
assertTrue(authstate.getAuthScheme() instanceof BasicScheme);
assertEquals("test", authstate.getRealm());
}
use of org.apache.commons.httpclient.FeedbackService in project ecf by eclipse.
the class TestBasicAuth method testBasicAuthenticationWithNoCreds.
public void testBasicAuthenticationWithNoCreds() throws IOException {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("testuser", "testpass");
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
this.server.setRequestHandler(handlerchain);
GetMethod httpget = new GetMethod("/test/");
try {
this.client.executeMethod(httpget);
assertNotNull(httpget.getStatusLine());
assertEquals(HttpStatus.SC_UNAUTHORIZED, httpget.getStatusLine().getStatusCode());
AuthState authstate = httpget.getHostAuthState();
assertNotNull(authstate.getAuthScheme());
assertTrue(authstate.getAuthScheme() instanceof BasicScheme);
assertEquals("test", authstate.getRealm());
} finally {
httpget.releaseConnection();
}
}
use of org.apache.commons.httpclient.FeedbackService in project ecf by eclipse.
the class TestSSLTunnelParams method testTunnellingParamsAgentLevel.
/**
* Tests correct proparation of HTTP params from the client to
* CONNECT method.
*/
public void testTunnellingParamsAgentLevel() throws IOException {
this.proxy.addHandler(new HttpVersionHandler());
this.server.setHttpService(new FeedbackService());
this.client.getParams().setVersion(HttpVersion.HTTP_1_1);
GetMethod httpget = new GetMethod("/test/");
try {
this.client.executeMethod(httpget);
assertNotNull(httpget.getStatusLine());
assertEquals(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED, httpget.getStatusLine().getStatusCode());
} finally {
httpget.releaseConnection();
}
this.client.getParams().setVersion(HttpVersion.HTTP_1_0);
httpget = new GetMethod("/test/");
try {
this.client.executeMethod(httpget);
assertNotNull(httpget.getStatusLine());
assertEquals(HttpStatus.SC_OK, httpget.getStatusLine().getStatusCode());
} finally {
httpget.releaseConnection();
}
}
use of org.apache.commons.httpclient.FeedbackService in project ecf by eclipse.
the class TestSSLTunnelParams method testTunnellingParamsHostHTTP10AndMethodHTTP11.
/**
* Tests ability to use HTTP/1.0 to execute CONNECT method and HTTP/1.1 to
* execute methods once the tunnel is established.
*/
public void testTunnellingParamsHostHTTP10AndMethodHTTP11() throws IOException {
this.proxy.addHandler(new HttpVersionHandler());
this.server.setHttpService(new FeedbackService());
this.client.getHostConfiguration().getParams().setParameter(HttpMethodParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_0);
GetMethod httpget = new GetMethod("/test/");
httpget.getParams().setVersion(HttpVersion.HTTP_1_1);
try {
this.client.executeMethod(httpget);
assertNotNull(httpget.getStatusLine());
assertEquals(HttpStatus.SC_OK, httpget.getStatusLine().getStatusCode());
assertEquals(HttpVersion.HTTP_1_1, httpget.getEffectiveVersion());
} finally {
httpget.releaseConnection();
}
}
Aggregations