use of org.apache.commons.httpclient.server.HttpRequestHandlerChain in project ecf by eclipse.
the class TestProxy method testGetProxyAuthHostAuthHTTP10.
/**
* Tests GET via authenticating proxy + host auth + HTTP/1.0
*/
public void testGetProxyAuthHostAuthHTTP10() throws Exception {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("testuser", "testpass");
this.client.getState().setCredentials(AuthScope.ANY, creds);
this.client.getState().setProxyCredentials(AuthScope.ANY, creds);
this.client.getParams().setVersion(HttpVersion.HTTP_1_0);
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds, "test", true));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
this.server.setRequestHandler(handlerchain);
this.proxy.requireAuthentication(creds, "test", false);
GetMethod get = new GetMethod("/");
try {
this.client.executeMethod(get);
assertEquals(HttpStatus.SC_OK, get.getStatusCode());
} finally {
get.releaseConnection();
}
}
use of org.apache.commons.httpclient.server.HttpRequestHandlerChain in project ecf by eclipse.
the class TestProxy method testGetProxyAuthHostAuthConnClose.
/**
* Tests GET via authenticating proxy + host auth + connection close
*/
public void testGetProxyAuthHostAuthConnClose() throws Exception {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("testuser", "testpass");
this.client.getState().setCredentials(AuthScope.ANY, creds);
this.client.getState().setProxyCredentials(AuthScope.ANY, creds);
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds, "test", false));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
this.server.setRequestHandler(handlerchain);
this.proxy.requireAuthentication(creds, "test", true);
GetMethod get = new GetMethod("/");
try {
this.client.executeMethod(get);
assertEquals(HttpStatus.SC_OK, get.getStatusCode());
} finally {
get.releaseConnection();
}
}
use of org.apache.commons.httpclient.server.HttpRequestHandlerChain in project ecf by eclipse.
the class TestProxy method testPostHostInvalidAuth.
/**
* Tests POST via non-authenticating proxy + invalid host auth
*/
public void testPostHostInvalidAuth() throws Exception {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("testuser", "testpass");
this.client.getState().setCredentials(AuthScope.ANY, creds);
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
this.client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("testuser", "wrongstuff"));
this.server.setRequestHandler(handlerchain);
PostMethod post = new PostMethod("/");
post.setRequestEntity(new StringRequestEntity("Like tons of stuff"));
try {
this.client.executeMethod(post);
assertEquals(HttpStatus.SC_UNAUTHORIZED, post.getStatusCode());
} finally {
post.releaseConnection();
}
}
use of org.apache.commons.httpclient.server.HttpRequestHandlerChain in project ecf by eclipse.
the class TestProxy method testGetInteractiveProxyAuthHostAuthConnKeepAlive.
/**
* Tests GET via authenticating proxy + interactive host and proxy auth + connection keep-alive
*/
public void testGetInteractiveProxyAuthHostAuthConnKeepAlive() throws Exception {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("testuser", "testpass");
this.client.getParams().setParameter(CredentialsProvider.PROVIDER, new GetItWrongThenGetItRight());
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds, "test", true));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
this.server.setRequestHandler(handlerchain);
this.proxy.requireAuthentication(creds, "test", true);
GetMethod get = new GetMethod("/");
try {
this.client.executeMethod(get);
assertEquals(HttpStatus.SC_OK, get.getStatusCode());
} finally {
get.releaseConnection();
}
}
use of org.apache.commons.httpclient.server.HttpRequestHandlerChain in project ecf by eclipse.
the class TestProxy method testGetInteractiveHostAuthConnClose.
/**
* Tests GET via non-authenticating proxy + interactive host auth + connection close
*/
public void testGetInteractiveHostAuthConnClose() throws Exception {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("testuser", "testpass");
this.client.getParams().setParameter(CredentialsProvider.PROVIDER, new GetItWrongThenGetItRight());
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds, "test", false));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
this.server.setRequestHandler(handlerchain);
GetMethod get = new GetMethod("/");
try {
this.client.executeMethod(get);
assertEquals(HttpStatus.SC_OK, get.getStatusCode());
} finally {
get.releaseConnection();
}
}
Aggregations