check that successful basic/digest auth credentials are cached with server and volunteered on subsequent requests

This commit is contained in:
Noah Levitt
2012-07-16 19:33:11 -07:00
parent cb6be2e9ca
commit ea7e7ed304
3 changed files with 22 additions and 8 deletions
+1 -1
View File
@@ -57,5 +57,5 @@
<classpathentry kind="var" path="M2_REPO/org/apache/httpcomponents/httpclient/4.2/httpclient-4.2.jar" sourcepath="/M2_REPO/org/apache/httpcomponents/httpclient/4.2/httpclient-4.2-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/org/apache/httpcomponents/httpcore/4.2/httpcore-4.2.jar" sourcepath="/M2_REPO/org/apache/httpcomponents/httpcore/4.2/httpcore-4.2-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/org/mortbay/jetty/jetty/6.1.26/jetty-6.1.26.jar" sourcepath="/M2_REPO/org/mortbay/jetty/jetty/6.1.26/jetty-6.1.26-sources.jar"/>
<classpathentry kind="output" path="bin"/>
<classpathentry kind="output" path="eclipse-build"/>
</classpath>
@@ -121,8 +121,7 @@ public class CommonsHttpCredentialUtil {
http.getState().setCredentials(new AuthScope(curi.getUURI().getHost(),
curi.getUURI().getPort(), cred.getRealm()), upc);
logger.fine("Credentials for realm " + cred.getRealm() +
" for CrawlURI " + curi.toString() + " added to request: " +
result);
" for CrawlURI " + curi.toString() + " added to request");
http.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY,
Arrays.asList(AuthPolicy.DIGEST, AuthPolicy.BASIC));
@@ -109,12 +109,11 @@ public abstract class FetchHTTPTestBase extends ProcessorTestBase {
ConstraintMapping constraintMapping = new ConstraintMapping();
constraintMapping.setConstraint(constraint);
constraintMapping.setPathSpec("/auth");
constraintMapping.setPathSpec("/auth/*");
SecurityHandler authWrapper = new SecurityHandler();
authWrapper.setAuthMethod(authMethod);
authWrapper
.setConstraintMappings(new ConstraintMapping[] { constraintMapping });
authWrapper.setConstraintMappings(new ConstraintMapping[] {constraintMapping});
authWrapper.setUserRealm(new HashUserRealm(realm) {
{
put(login, password);
@@ -335,7 +334,7 @@ public abstract class FetchHTTPTestBase extends ProcessorTestBase {
getFetcher().getCredentialStore().getCredentials().put("basic-auth-credential",
basicAuthCredential);
CrawlURI curi = makeCrawlURI("http://localhost:7777/auth");
CrawlURI curi = makeCrawlURI("http://localhost:7777/auth/1");
getFetcher().process(curi);
// check that we got the expected response and the fetcher did its thing
@@ -349,6 +348,14 @@ public abstract class FetchHTTPTestBase extends ProcessorTestBase {
assertTrue(httpRequestString.contains("Authorization: Basic YmFzaWMtYXV0aC1sb2dpbjpiYXNpYy1hdXRoLXBhc3N3b3Jk\r\n"));
// otherwise should be a normal 200 response
runDefaultChecks(curi, new HashSet<String>(Arrays.asList("requestLine")));
// fetch a fresh uri to make sure auth info was cached and we don't get another 401
curi = makeCrawlURI("http://localhost:7777/auth/2");
getFetcher().process(curi);
httpRequestString = httpRequestString(curi);
assertTrue(httpRequestString.contains("Authorization: Basic YmFzaWMtYXV0aC1sb2dpbjpiYXNpYy1hdXRoLXBhc3N3b3Jk\r\n"));
// otherwise should be a normal 200 response
runDefaultChecks(curi, new HashSet<String>(Arrays.asList("requestLine")));
}
// server for digest auth is at localhost:7778
@@ -364,7 +371,7 @@ public abstract class FetchHTTPTestBase extends ProcessorTestBase {
getFetcher().getCredentialStore().getCredentials().put("digest-auth-credential",
digestAuthCred);
CrawlURI curi = makeCrawlURI("http://localhost:7778/auth");
CrawlURI curi = makeCrawlURI("http://localhost:7778/auth/1");
getFetcher().process(curi);
// check that we got the expected response and the fetcher did its thing
@@ -378,6 +385,14 @@ public abstract class FetchHTTPTestBase extends ProcessorTestBase {
assertTrue(httpRequestString.contains("Authorization: Digest"));
// otherwise should be a normal 200 response
runDefaultChecks(curi, new HashSet<String>(Arrays.asList("requestLine", "hostHeader")));
// fetch a fresh uri to make sure auth info was cached and we don't get another 401
curi = makeCrawlURI("http://localhost:7778/auth/2");
getFetcher().process(curi);
httpRequestString = httpRequestString(curi);
assertTrue(httpRequestString.contains("Authorization: Digest"));
// otherwise should be a normal 200 response
runDefaultChecks(curi, new HashSet<String>(Arrays.asList("requestLine")));
}
protected void checkSetCookieURI() throws URIException, IOException,