hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1689155 [2/3] - in /httpcomponents/httpclient/trunk: fluent-hc/src/main/java/org/apache/http/client/fluent/ httpclient-win/src/main/java/org/apache/http/impl/auth/win/ httpclient/src/main/java/org/apache/http/auth/ httpclient/src/main/java...
Date Sat, 04 Jul 2015 13:42:40 GMT
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java?rev=1689155&r1=1689154&r2=1689155&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java Sat Jul  4 13:42:40 2015
@@ -46,6 +46,7 @@ import org.apache.http.annotation.Immuta
 import org.apache.http.auth.AUTH;
 import org.apache.http.auth.AuthProtocolState;
 import org.apache.http.auth.AuthState;
+import org.apache.http.auth.ChallengeType;
 import org.apache.http.client.AuthenticationStrategy;
 import org.apache.http.client.NonRepeatableRequestException;
 import org.apache.http.client.UserTokenHandler;
@@ -465,9 +466,9 @@ public class MainClientExec implements C
             }
 
             if (config.isAuthenticationEnabled()) {
-                if (this.authenticator.isAuthenticationRequested(proxy, response,
-                        this.proxyAuthStrategy, proxyAuthState, context)) {
-                    if (this.authenticator.handleAuthChallenge(proxy, response,
+                if (this.authenticator.updateAuthState(proxy, ChallengeType.PROXY, response,
+                        proxyAuthState, context)) {
+                    if (this.authenticator.handleAuthChallenge(proxy, ChallengeType.PROXY, response,
                             this.proxyAuthStrategy, proxyAuthState, context)) {
                         // Retry request
                         if (this.reuseStrategy.keepAlive(response, context)) {
@@ -546,23 +547,23 @@ public class MainClientExec implements C
                         route.getTargetHost().getPort(),
                         target.getSchemeName());
             }
-            final boolean targetAuthRequested = this.authenticator.isAuthenticationRequested(
-                    target, response, this.targetAuthStrategy, targetAuthState, context);
+            final boolean targetAuthRequested = this.authenticator.updateAuthState(
+                    target, ChallengeType.TARGET, response, targetAuthState, context);
 
             HttpHost proxy = route.getProxyHost();
             // if proxy is not set use target host instead
             if (proxy == null) {
                 proxy = route.getTargetHost();
             }
-            final boolean proxyAuthRequested = this.authenticator.isAuthenticationRequested(
-                    proxy, response, this.proxyAuthStrategy, proxyAuthState, context);
+            final boolean proxyAuthRequested = this.authenticator.updateAuthState(
+                    proxy, ChallengeType.PROXY, response, proxyAuthState, context);
 
             if (targetAuthRequested) {
-                return this.authenticator.handleAuthChallenge(target, response,
+                return this.authenticator.handleAuthChallenge(target, ChallengeType.TARGET, response,
                         this.targetAuthStrategy, targetAuthState, context);
             }
             if (proxyAuthRequested) {
-                return this.authenticator.handleAuthChallenge(proxy, response,
+                return this.authenticator.handleAuthChallenge(proxy, ChallengeType.PROXY, response,
                         this.proxyAuthStrategy, proxyAuthState, context);
             }
         }

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestAuthChallengeParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestAuthChallengeParser.java?rev=1689155&r1=1689154&r2=1689155&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestAuthChallengeParser.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestAuthChallengeParser.java Sat Jul  4 13:42:40 2015
@@ -59,6 +59,17 @@ public class TestAuthChallengeParser {
     }
 
     @Test
+    public void testParseTokenWithBlank() throws Exception {
+        final CharArrayBuffer buffer = new CharArrayBuffer(64);
+        buffer.append("blah ");
+        final ParserCursor cursor = new ParserCursor(0, buffer.length());
+        final NameValuePair nvp = parser.parseTokenOrParameter(buffer, cursor);
+        Assert.assertNotNull(nvp);
+        Assert.assertEquals("blah", nvp.getName());
+        Assert.assertEquals(null, nvp.getValue());
+    }
+
+    @Test
     public void testParseTokenWithBlanks() throws Exception {
         final CharArrayBuffer buffer = new CharArrayBuffer(64);
         buffer.append("  blah  blah ");

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestBasicScheme.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestBasicScheme.java?rev=1689155&r1=1689154&r2=1689155&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestBasicScheme.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestBasicScheme.java Sat Jul  4 13:42:40 2015
@@ -30,18 +30,22 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
+import java.util.List;
 
 import org.apache.commons.codec.binary.Base64;
 import org.apache.http.Consts;
 import org.apache.http.Header;
 import org.apache.http.HttpRequest;
 import org.apache.http.auth.AUTH;
+import org.apache.http.auth.AuthChallenge;
 import org.apache.http.auth.AuthScheme;
+import org.apache.http.auth.ChallengeType;
 import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.message.BasicHeader;
 import org.apache.http.message.BasicHttpRequest;
+import org.apache.http.message.ParserCursor;
 import org.apache.http.protocol.BasicHttpContext;
 import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.CharArrayBuffer;
 import org.apache.http.util.EncodingUtils;
 import org.junit.Assert;
 import org.junit.Test;
@@ -51,12 +55,21 @@ import org.junit.Test;
  */
 public class TestBasicScheme {
 
+    private static AuthChallenge parse(final String s) {
+        final CharArrayBuffer buffer = new CharArrayBuffer(s.length());
+        buffer.append(s);
+        final ParserCursor cursor = new ParserCursor(0, buffer.length());
+        final List<AuthChallenge> authChallenges = AuthChallengeParser.INSTANCE.parse(buffer, cursor);
+        Assert.assertEquals(1, authChallenges.size());
+        return authChallenges.get(0);
+    }
+
     @Test
     public void testBasicAuthenticationEmptyChallenge() throws Exception {
         final String challenge = "Basic";
-        final Header header = new BasicHeader(AUTH.WWW_AUTH, challenge);
+        final AuthChallenge authChallenge = parse(challenge);
         final AuthScheme authscheme = new BasicScheme();
-        authscheme.processChallenge(header);
+        authscheme.processChallenge(ChallengeType.TARGET, authChallenge);
         Assert.assertNull(authscheme.getRealm());
     }
 
@@ -79,13 +92,12 @@ public class TestBasicScheme {
 
     @Test
     public void testBasicAuthentication() throws Exception {
-        final UsernamePasswordCredentials creds =
-            new UsernamePasswordCredentials("testuser", "testpass");
+        final UsernamePasswordCredentials creds = new UsernamePasswordCredentials("testuser", "testpass");
 
-        final Header challenge = new BasicHeader(AUTH.WWW_AUTH, "Basic realm=\"test\"");
+        final AuthChallenge authChallenge = parse("Basic realm=\"test\"");
 
         final BasicScheme authscheme = new BasicScheme();
-        authscheme.processChallenge(challenge);
+        authscheme.processChallenge(ChallengeType.TARGET, authChallenge);
 
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpContext context = new BasicHttpContext();
@@ -102,13 +114,12 @@ public class TestBasicScheme {
 
     @Test
     public void testBasicProxyAuthentication() throws Exception {
-        final UsernamePasswordCredentials creds =
-            new UsernamePasswordCredentials("testuser", "testpass");
+        final UsernamePasswordCredentials creds = new UsernamePasswordCredentials("testuser", "testpass");
 
-        final Header challenge = new BasicHeader(AUTH.PROXY_AUTH, "Basic realm=\"test\"");
+        final AuthChallenge authChallenge = parse("Basic realm=\"test\"");
 
         final BasicScheme authscheme = new BasicScheme();
-        authscheme.processChallenge(challenge);
+        authscheme.processChallenge(ChallengeType.PROXY, authChallenge);
 
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final HttpContext context = new BasicHttpContext();
@@ -125,10 +136,10 @@ public class TestBasicScheme {
 
     @Test
     public void testSerialization() throws Exception {
-        final Header challenge = new BasicHeader(AUTH.PROXY_AUTH, "Basic realm=\"test\"");
+        final AuthChallenge authChallenge = parse("Basic realm=\"test\"");
 
         final BasicScheme basicScheme = new BasicScheme();
-        basicScheme.processChallenge(challenge);
+        basicScheme.processChallenge(ChallengeType.PROXY, authChallenge);
 
         final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
         final ObjectOutputStream out = new ObjectOutputStream(buffer);

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestDigestScheme.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestDigestScheme.java?rev=1689155&r1=1689154&r2=1689155&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestDigestScheme.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestDigestScheme.java Sat Jul  4 13:42:40 2015
@@ -33,27 +33,30 @@ import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.security.MessageDigest;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.http.Header;
 import org.apache.http.HeaderElement;
 import org.apache.http.HttpEntityEnclosingRequest;
 import org.apache.http.HttpRequest;
-import org.apache.http.auth.AUTH;
+import org.apache.http.auth.AuthChallenge;
 import org.apache.http.auth.AuthScheme;
 import org.apache.http.auth.AuthenticationException;
+import org.apache.http.auth.ChallengeType;
 import org.apache.http.auth.Credentials;
 import org.apache.http.auth.MalformedChallengeException;
 import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.http.entity.InputStreamEntity;
 import org.apache.http.entity.StringEntity;
-import org.apache.http.message.BasicHeader;
 import org.apache.http.message.BasicHeaderValueParser;
 import org.apache.http.message.BasicHttpEntityEnclosingRequest;
 import org.apache.http.message.BasicHttpRequest;
+import org.apache.http.message.ParserCursor;
 import org.apache.http.protocol.BasicHttpContext;
 import org.apache.http.protocol.HTTP;
 import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.CharArrayBuffer;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -62,29 +65,38 @@ import org.junit.Test;
  */
 public class TestDigestScheme {
 
+    private static AuthChallenge parse(final String s) {
+        final CharArrayBuffer buffer = new CharArrayBuffer(s.length());
+        buffer.append(s);
+        final ParserCursor cursor = new ParserCursor(0, buffer.length());
+        final List<AuthChallenge> authChallenges = AuthChallengeParser.INSTANCE.parse(buffer, cursor);
+        Assert.assertEquals(1, authChallenges.size());
+        return authChallenges.get(0);
+    }
+
     @Test(expected=MalformedChallengeException.class)
     public void testDigestAuthenticationEmptyChallenge1() throws Exception {
-        final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, "Digest");
+        final AuthChallenge authChallenge = parse("Digest");
         final AuthScheme authscheme = new DigestScheme();
-        authscheme.processChallenge(authChallenge);
+        authscheme.processChallenge(ChallengeType.TARGET, authChallenge);
     }
 
     @Test(expected=MalformedChallengeException.class)
     public void testDigestAuthenticationEmptyChallenge2() throws Exception {
-        final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, "Digest ");
+        final AuthChallenge authChallenge = parse("Digest ");
         final AuthScheme authscheme = new DigestScheme();
-        authscheme.processChallenge(authChallenge);
+        authscheme.processChallenge(ChallengeType.TARGET, authChallenge);
     }
 
     @Test
     public void testDigestAuthenticationWithDefaultCreds() throws Exception {
         final String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\"";
-        final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
+        final AuthChallenge authChallenge = parse(challenge);
         final HttpRequest request = new BasicHttpRequest("Simple", "/");
         final Credentials cred = new UsernamePasswordCredentials("username","password");
         final DigestScheme authscheme = new DigestScheme();
         final HttpContext context = new BasicHttpContext();
-        authscheme.processChallenge(authChallenge);
+        authscheme.processChallenge(ChallengeType.TARGET, authChallenge);
         final Header authResponse = authscheme.authenticate(cred, request, context);
         Assert.assertTrue(authscheme.isComplete());
         Assert.assertFalse(authscheme.isConnectionBased());
@@ -100,12 +112,12 @@ public class TestDigestScheme {
     @Test
     public void testDigestAuthentication() throws Exception {
         final String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\"";
-        final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
+        final AuthChallenge authChallenge = parse(challenge);
         final HttpRequest request = new BasicHttpRequest("Simple", "/");
         final Credentials cred = new UsernamePasswordCredentials("username","password");
         final DigestScheme authscheme = new DigestScheme();
         final HttpContext context = new BasicHttpContext();
-        authscheme.processChallenge(authChallenge);
+        authscheme.processChallenge(ChallengeType.TARGET, authChallenge);
         final Header authResponse = authscheme.authenticate(cred, request, context);
 
         final Map<String, String> table = parseAuthResponse(authResponse);
@@ -119,12 +131,12 @@ public class TestDigestScheme {
     @Test
     public void testDigestAuthenticationInvalidInput() throws Exception {
         final String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\"";
-        final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
+        final AuthChallenge authChallenge = parse(challenge);
         final HttpRequest request = new BasicHttpRequest("Simple", "/");
         final Credentials cred = new UsernamePasswordCredentials("username","password");
         final DigestScheme authscheme = new DigestScheme();
         final HttpContext context = new BasicHttpContext();
-        authscheme.processChallenge(authChallenge);
+        authscheme.processChallenge(ChallengeType.TARGET, authChallenge);
         try {
             authscheme.authenticate(null, request, context);
             Assert.fail("IllegalArgumentException should have been thrown");
@@ -138,36 +150,16 @@ public class TestDigestScheme {
     }
 
     @Test
-    public void testDigestAuthenticationOverrideParameter() throws Exception {
-        final String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\"";
-        final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
-        final HttpRequest request = new BasicHttpRequest("Simple", "/");
-        final Credentials cred = new UsernamePasswordCredentials("username","password");
-        final DigestScheme authscheme = new DigestScheme();
-        final HttpContext context = new BasicHttpContext();
-        authscheme.processChallenge(authChallenge);
-        authscheme.overrideParamter("realm", "other realm");
-        final Header authResponse = authscheme.authenticate(cred, request, context);
-
-        final Map<String, String> table = parseAuthResponse(authResponse);
-        Assert.assertEquals("username", table.get("username"));
-        Assert.assertEquals("other realm", table.get("realm"));
-        Assert.assertEquals("/", table.get("uri"));
-        Assert.assertEquals("f2a3f18799759d4f1a1c068b92b573cb", table.get("nonce"));
-        Assert.assertEquals("3f211de10463cbd055ab4cd9c5158eac", table.get("response"));
-    }
-
-    @Test
     public void testDigestAuthenticationWithSHA() throws Exception {
         final String challenge = "Digest realm=\"realm1\", " +
                 "nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " +
                 "algorithm=SHA";
-        final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
+        final AuthChallenge authChallenge = parse(challenge);
         final HttpRequest request = new BasicHttpRequest("Simple", "/");
         final Credentials cred = new UsernamePasswordCredentials("username","password");
         final HttpContext context = new BasicHttpContext();
         final DigestScheme authscheme = new DigestScheme();
-        authscheme.processChallenge(authChallenge);
+        authscheme.processChallenge(ChallengeType.TARGET, authChallenge);
         final Header authResponse = authscheme.authenticate(cred, request, context);
 
         final Map<String, String> table = parseAuthResponse(authResponse);
@@ -181,12 +173,12 @@ public class TestDigestScheme {
     @Test
     public void testDigestAuthenticationWithQueryStringInDigestURI() throws Exception {
         final String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\"";
-        final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
+        final AuthChallenge authChallenge = parse(challenge);
         final HttpRequest request = new BasicHttpRequest("Simple", "/?param=value");
         final Credentials cred = new UsernamePasswordCredentials("username","password");
         final HttpContext context = new BasicHttpContext();
         final DigestScheme authscheme = new DigestScheme();
-        authscheme.processChallenge(authChallenge);
+        authscheme.processChallenge(ChallengeType.TARGET, authChallenge);
         final Header authResponse = authscheme.authenticate(cred, request, context);
 
         final Map<String, String> table = parseAuthResponse(authResponse);
@@ -204,11 +196,11 @@ public class TestDigestScheme {
         final Credentials cred = new UsernamePasswordCredentials("username","password");
         final Credentials cred2 = new UsernamePasswordCredentials("uname2","password2");
 
-        Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge1);
+        final AuthChallenge authChallenge1 = parse(challenge1);
         final HttpRequest request = new BasicHttpRequest("Simple", "/");
         final HttpContext context = new BasicHttpContext();
         final DigestScheme authscheme = new DigestScheme();
-        authscheme.processChallenge(authChallenge);
+        authscheme.processChallenge(ChallengeType.TARGET, authChallenge1);
         Header authResponse = authscheme.authenticate(cred, request, context);
 
         Map<String, String> table = parseAuthResponse(authResponse);
@@ -218,9 +210,9 @@ public class TestDigestScheme {
         Assert.assertEquals("abcde", table.get("nonce"));
         Assert.assertEquals("786f500303eac1478f3c2865e676ed68", table.get("response"));
 
-        authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge2);
+        final AuthChallenge authChallenge2 = parse(challenge2);
         final DigestScheme authscheme2 = new DigestScheme();
-        authscheme2.processChallenge(authChallenge);
+        authscheme2.processChallenge(ChallengeType.TARGET, authChallenge2);
         authResponse = authscheme2.authenticate(cred2, request, context);
 
         table = parseAuthResponse(authResponse);
@@ -234,10 +226,10 @@ public class TestDigestScheme {
     @Test(expected=AuthenticationException.class)
     public void testDigestAuthenticationNoRealm() throws Exception {
         final String challenge = "Digest no-realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\"";
-        final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
+        final AuthChallenge authChallenge = parse(challenge);
         final HttpContext context = new BasicHttpContext();
         final DigestScheme authscheme = new DigestScheme();
-        authscheme.processChallenge(authChallenge);
+        authscheme.processChallenge(ChallengeType.TARGET, authChallenge);
 
         final Credentials cred = new UsernamePasswordCredentials("username","password");
         final HttpRequest request = new BasicHttpRequest("Simple", "/");
@@ -247,10 +239,10 @@ public class TestDigestScheme {
     @Test(expected=AuthenticationException.class)
     public void testDigestAuthenticationNoNonce() throws Exception {
         final String challenge = "Digest realm=\"realm1\", no-nonce=\"f2a3f18799759d4f1a1c068b92b573cb\"";
-        final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
+        final AuthChallenge authChallenge = parse(challenge);
         final HttpContext context = new BasicHttpContext();
         final DigestScheme authscheme = new DigestScheme();
-        authscheme.processChallenge(authChallenge);
+        authscheme.processChallenge(ChallengeType.TARGET, authChallenge);
 
         final Credentials cred = new UsernamePasswordCredentials("username","password");
         final HttpRequest request = new BasicHttpRequest("Simple", "/");
@@ -276,14 +268,14 @@ public class TestDigestScheme {
             + "algorithm=MD5-sess, "
             + "qop=\"auth,auth-int\""; // we pass both but expect auth to be used
 
-        final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
+        final AuthChallenge authChallenge = parse(challenge);
 
         final Credentials cred = new UsernamePasswordCredentials(username, password);
         final HttpRequest request = new BasicHttpRequest("Simple", "/");
         final HttpContext context = new BasicHttpContext();
 
         final DigestScheme authscheme = new DigestScheme();
-        authscheme.processChallenge(authChallenge);
+        authscheme.processChallenge(ChallengeType.TARGET, authChallenge);
         final Header authResponse = authscheme.authenticate(cred, request, context);
         final String response = authResponse.getValue();
 
@@ -322,7 +314,7 @@ public class TestDigestScheme {
             + "stale=false, "
             + "algorithm=MD5-sess";
 
-        final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
+        final AuthChallenge authChallenge = parse(challenge);
 
         final Credentials cred = new UsernamePasswordCredentials(username, password);
 
@@ -330,7 +322,7 @@ public class TestDigestScheme {
         final HttpContext context = new BasicHttpContext();
 
         final DigestScheme authscheme = new DigestScheme();
-        authscheme.processChallenge(authChallenge);
+        authscheme.processChallenge(ChallengeType.TARGET, authChallenge);
         final Header authResponse = authscheme.authenticate(cred, request, context);
 
         final Map<String, String> table = parseAuthResponse(authResponse);
@@ -365,10 +357,10 @@ public class TestDigestScheme {
             + "algorithm=MD5-sess, "
             + "qop=\"stuff\"";
 
-        final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
+        final AuthChallenge authChallenge = parse(challenge);
 
         final DigestScheme authscheme = new DigestScheme();
-        authscheme.processChallenge(authChallenge);
+        authscheme.processChallenge(ChallengeType.TARGET, authChallenge);
 
         final Credentials cred = new UsernamePasswordCredentials(username, password);
         final HttpRequest request = new BasicHttpRequest("Simple", "/");
@@ -395,10 +387,10 @@ public class TestDigestScheme {
             + "algorithm=stuff, "
             + "qop=\"auth\"";
 
-        final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
+        final AuthChallenge authChallenge = parse(challenge);
 
         final DigestScheme authscheme = new DigestScheme();
-        authscheme.processChallenge(authChallenge);
+        authscheme.processChallenge(ChallengeType.TARGET, authChallenge);
 
         final Credentials cred = new UsernamePasswordCredentials(username, password);
         final HttpRequest request = new BasicHttpRequest("Simple", "/");
@@ -410,9 +402,9 @@ public class TestDigestScheme {
     public void testDigestAuthenticationWithStaleNonce() throws Exception {
         final String challenge = "Digest realm=\"realm1\", " +
                 "nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", stale=\"true\"";
-        final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
+        final AuthChallenge authChallenge = parse(challenge);
         final AuthScheme authscheme = new DigestScheme();
-        authscheme.processChallenge(authChallenge);
+        authscheme.processChallenge(ChallengeType.TARGET, authChallenge);
 
         Assert.assertFalse(authscheme.isComplete());
     }
@@ -433,12 +425,12 @@ public class TestDigestScheme {
     @Test
     public void testDigestNouceCount() throws Exception {
         final String challenge1 = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", qop=auth";
-        final Header authChallenge1 = new BasicHeader(AUTH.WWW_AUTH, challenge1);
+        final AuthChallenge authChallenge1 = parse(challenge1);
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final Credentials cred = new UsernamePasswordCredentials("username","password");
         final HttpContext context = new BasicHttpContext();
         final DigestScheme authscheme = new DigestScheme();
-        authscheme.processChallenge(authChallenge1);
+        authscheme.processChallenge(ChallengeType.TARGET, authChallenge1);
         final Header authResponse1 = authscheme.authenticate(cred, request, context);
         final Map<String, String> table1 = parseAuthResponse(authResponse1);
         Assert.assertEquals("00000001", table1.get("nc"));
@@ -446,14 +438,14 @@ public class TestDigestScheme {
         final Map<String, String> table2 = parseAuthResponse(authResponse2);
         Assert.assertEquals("00000002", table2.get("nc"));
         final String challenge2 = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", qop=auth";
-        final Header authChallenge2 = new BasicHeader(AUTH.WWW_AUTH, challenge2);
-        authscheme.processChallenge(authChallenge2);
+        final AuthChallenge authChallenge2 = parse(challenge2);
+        authscheme.processChallenge(ChallengeType.TARGET, authChallenge2);
         final Header authResponse3 = authscheme.authenticate(cred, request, context);
         final Map<String, String> table3 = parseAuthResponse(authResponse3);
         Assert.assertEquals("00000003", table3.get("nc"));
         final String challenge3 = "Digest realm=\"realm1\", nonce=\"e273f1776275974f1a120d8b92c5b3cb\", qop=auth";
-        final Header authChallenge3 = new BasicHeader(AUTH.WWW_AUTH, challenge3);
-        authscheme.processChallenge(authChallenge3);
+        final AuthChallenge authChallenge3 = parse(challenge3);
+        authscheme.processChallenge(ChallengeType.TARGET, authChallenge3);
         final Header authResponse4 = authscheme.authenticate(cred, request, context);
         final Map<String, String> table4 = parseAuthResponse(authResponse4);
         Assert.assertEquals("00000001", table4.get("nc"));
@@ -463,12 +455,12 @@ public class TestDigestScheme {
     public void testDigestMD5SessA1AndCnonceConsistency() throws Exception {
         final String challenge1 = "Digest qop=\"auth\", algorithm=MD5-sess, nonce=\"1234567890abcdef\", " +
                 "charset=utf-8, realm=\"subnet.domain.com\"";
-        final Header authChallenge1 = new BasicHeader(AUTH.WWW_AUTH, challenge1);
+        final AuthChallenge authChallenge1 = parse(challenge1);
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final Credentials cred = new UsernamePasswordCredentials("username","password");
         final HttpContext context = new BasicHttpContext();
         final DigestScheme authscheme = new DigestScheme();
-        authscheme.processChallenge(authChallenge1);
+        authscheme.processChallenge(ChallengeType.TARGET, authChallenge1);
         final Header authResponse1 = authscheme.authenticate(cred, request, context);
         final Map<String, String> table1 = parseAuthResponse(authResponse1);
         Assert.assertEquals("00000001", table1.get("nc"));
@@ -486,8 +478,8 @@ public class TestDigestScheme {
 
         final String challenge2 = "Digest qop=\"auth\", algorithm=MD5-sess, nonce=\"1234567890abcdef\", " +
             "charset=utf-8, realm=\"subnet.domain.com\"";
-        final Header authChallenge2 = new BasicHeader(AUTH.WWW_AUTH, challenge2);
-        authscheme.processChallenge(authChallenge2);
+        final AuthChallenge authChallenge2 = parse(challenge2);
+        authscheme.processChallenge(ChallengeType.TARGET, authChallenge2);
         final Header authResponse3 = authscheme.authenticate(cred, request, context);
         final Map<String, String> table3 = parseAuthResponse(authResponse3);
         Assert.assertEquals("00000003", table3.get("nc"));
@@ -500,8 +492,8 @@ public class TestDigestScheme {
 
         final String challenge3 = "Digest qop=\"auth\", algorithm=MD5-sess, nonce=\"fedcba0987654321\", " +
             "charset=utf-8, realm=\"subnet.domain.com\"";
-        final Header authChallenge3 = new BasicHeader(AUTH.WWW_AUTH, challenge3);
-        authscheme.processChallenge(authChallenge3);
+        final AuthChallenge authChallenge3 = parse(challenge3);
+        authscheme.processChallenge(ChallengeType.TARGET, authChallenge3);
         final Header authResponse4 = authscheme.authenticate(cred, request, context);
         final Map<String, String> table4 = parseAuthResponse(authResponse4);
         Assert.assertEquals("00000001", table4.get("nc"));
@@ -543,13 +535,13 @@ public class TestDigestScheme {
     public void testDigestAuthenticationQopAuthInt() throws Exception {
         final String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " +
                 "qop=\"auth,auth-int\"";
-        final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
+        final AuthChallenge authChallenge = parse(challenge);
         final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("Post", "/");
         request.setEntity(new StringEntity("abc\u00e4\u00f6\u00fcabc", HTTP.DEF_CONTENT_CHARSET));
         final Credentials cred = new UsernamePasswordCredentials("username","password");
         final DigestScheme authscheme = new DigestScheme();
         final HttpContext context = new BasicHttpContext();
-        authscheme.processChallenge(authChallenge);
+        authscheme.processChallenge(ChallengeType.TARGET, authChallenge);
         final Header authResponse = authscheme.authenticate(cred, request, context);
 
         Assert.assertEquals("Post:/:acd2b59cd01c7737d8069015584c6cac", authscheme.getA2());
@@ -566,12 +558,12 @@ public class TestDigestScheme {
     public void testDigestAuthenticationQopAuthIntNullEntity() throws Exception {
         final String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " +
                 "qop=\"auth,auth-int\"";
-        final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
+        final AuthChallenge authChallenge = parse(challenge);
         final HttpRequest request = new BasicHttpEntityEnclosingRequest("Post", "/");
         final Credentials cred = new UsernamePasswordCredentials("username","password");
         final DigestScheme authscheme = new DigestScheme();
         final HttpContext context = new BasicHttpContext();
-        authscheme.processChallenge(authChallenge);
+        authscheme.processChallenge(ChallengeType.TARGET, authChallenge);
         final Header authResponse = authscheme.authenticate(cred, request, context);
 
         Assert.assertEquals("Post:/:d41d8cd98f00b204e9800998ecf8427e", authscheme.getA2());
@@ -588,13 +580,13 @@ public class TestDigestScheme {
     public void testDigestAuthenticationQopAuthOrAuthIntNonRepeatableEntity() throws Exception {
         final String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " +
                 "qop=\"auth,auth-int\"";
-        final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
+        final AuthChallenge authChallenge = parse(challenge);
         final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("Post", "/");
         request.setEntity(new InputStreamEntity(new ByteArrayInputStream(new byte[] {'a'}), -1));
         final Credentials cred = new UsernamePasswordCredentials("username","password");
         final DigestScheme authscheme = new DigestScheme();
         final HttpContext context = new BasicHttpContext();
-        authscheme.processChallenge(authChallenge);
+        authscheme.processChallenge(ChallengeType.TARGET, authChallenge);
         final Header authResponse = authscheme.authenticate(cred, request, context);
 
         Assert.assertEquals("Post:/", authscheme.getA2());
@@ -612,12 +604,12 @@ public class TestDigestScheme {
         final String challenge = "Digest Realm=\"-\", " +
                 "nonce=\"YjYuNGYyYmJhMzUuY2I5ZDhlZDE5M2ZlZDM 1Mjk3NGJkNTIyYjgyNTcwMjQ=\", " +
                 "opaque=\"98700A3D9CE17065E2246B41035C6609\", qop=\"auth\"";
-        final Header authChallenge = new BasicHeader(AUTH.PROXY_AUTH, challenge);
+        final AuthChallenge authChallenge = parse(challenge);
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         final Credentials cred = new UsernamePasswordCredentials("username","password");
         final DigestScheme authscheme = new DigestScheme();
         final HttpContext context = new BasicHttpContext();
-        authscheme.processChallenge(authChallenge);
+        authscheme.processChallenge(ChallengeType.TARGET, authChallenge);
         Assert.assertEquals("-", authscheme.getRealm());
 
         authscheme.authenticate(cred, request, context);
@@ -627,13 +619,13 @@ public class TestDigestScheme {
     public void testDigestAuthenticationQopIntOnlyNonRepeatableEntity() throws Exception {
         final String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " +
                 "qop=\"auth-int\"";
-        final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
+        final AuthChallenge authChallenge = parse(challenge);
         final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("Post", "/");
         request.setEntity(new InputStreamEntity(new ByteArrayInputStream(new byte[] {'a'}), -1));
         final Credentials cred = new UsernamePasswordCredentials("username","password");
         final DigestScheme authscheme = new DigestScheme();
         final HttpContext context = new BasicHttpContext();
-        authscheme.processChallenge(authChallenge);
+        authscheme.processChallenge(ChallengeType.TARGET, authChallenge);
         authscheme.authenticate(cred, request, context);
     }
 
@@ -641,9 +633,9 @@ public class TestDigestScheme {
     public void testSerialization() throws Exception {
         final String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " +
                 "qop=\"auth,auth-int\"";
-        final Header authChallenge = new BasicHeader(AUTH.WWW_AUTH, challenge);
+        final AuthChallenge authChallenge = parse(challenge);
         final DigestScheme digestScheme = new DigestScheme();
-        digestScheme.processChallenge(authChallenge);
+        digestScheme.processChallenge(ChallengeType.TARGET, authChallenge);
 
         final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
         final ObjectOutputStream out = new ObjectOutputStream(buffer);

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestHttpAuthenticator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestHttpAuthenticator.java?rev=1689155&r1=1689154&r2=1689155&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestHttpAuthenticator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestHttpAuthenticator.java Sat Jul  4 13:42:40 2015
@@ -26,11 +26,10 @@
  */
 package org.apache.http.impl.auth;
 
-import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.Queue;
 
-import org.apache.http.Header;
+import org.apache.http.HttpHeaders;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
@@ -44,15 +43,14 @@ import org.apache.http.auth.AuthSchemePr
 import org.apache.http.auth.AuthScope;
 import org.apache.http.auth.AuthState;
 import org.apache.http.auth.AuthenticationException;
+import org.apache.http.auth.ChallengeType;
 import org.apache.http.auth.Credentials;
-import org.apache.http.auth.MalformedChallengeException;
 import org.apache.http.client.AuthCache;
-import org.apache.http.client.AuthenticationStrategy;
 import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.config.Lookup;
 import org.apache.http.config.RegistryBuilder;
 import org.apache.http.impl.client.BasicCredentialsProvider;
-import org.apache.http.impl.client.TargetAuthenticationStrategy;
+import org.apache.http.impl.client.DefaultAuthenticationStrategy;
 import org.apache.http.message.BasicHeader;
 import org.apache.http.message.BasicHttpRequest;
 import org.apache.http.message.BasicHttpResponse;
@@ -67,7 +65,6 @@ import org.mockito.Mockito;
 @SuppressWarnings({"boxing","static-access"})
 public class TestHttpAuthenticator {
 
-    private AuthenticationStrategy defltAuthStrategy;
     private AuthState authState;
     private AuthScheme authScheme;
     private HttpContext context;
@@ -80,7 +77,6 @@ public class TestHttpAuthenticator {
 
     @Before
     public void setUp() throws Exception {
-        this.defltAuthStrategy = Mockito.mock(AuthenticationStrategy.class);
         this.authState = new AuthState();
         this.authScheme = Mockito.mock(AuthScheme.class);
         Mockito.when(this.authScheme.getSchemeName()).thenReturn("Basic");
@@ -103,86 +99,61 @@ public class TestHttpAuthenticator {
     }
 
     @Test
-    public void testAuthenticationRequested() throws Exception {
+    public void testUpdateAuthState() throws Exception {
         final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
-        Mockito.when(this.defltAuthStrategy.isAuthenticationRequested(
-                Mockito.any(HttpHost.class),
-                Mockito.any(HttpResponse.class),
-                Mockito.any(HttpContext.class))).thenReturn(Boolean.TRUE);
-
-        Assert.assertTrue(this.httpAuthenticator.isAuthenticationRequested(
-                this.defaultHost, response, this.defltAuthStrategy, this.authState, this.context));
-
-        Mockito.verify(this.defltAuthStrategy).isAuthenticationRequested(this.defaultHost, response, this.context);
+        response.setHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=test");
+        Assert.assertTrue(this.httpAuthenticator.updateAuthState(
+                this.defaultHost, ChallengeType.TARGET, response, this.authState, this.context));
+        Mockito.verifyZeroInteractions(this.authCache);
     }
 
     @Test
     public void testAuthenticationRequestedAfterSuccess() throws Exception {
         final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
-        Mockito.when(this.defltAuthStrategy.isAuthenticationRequested(
-                Mockito.any(HttpHost.class),
-                Mockito.any(HttpResponse.class),
-                Mockito.any(HttpContext.class))).thenReturn(Boolean.TRUE);
+        response.setHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=test");
 
         this.authState.update(this.authScheme, this.credentials);
         this.authState.setState(AuthProtocolState.SUCCESS);
 
-        Assert.assertTrue(this.httpAuthenticator.isAuthenticationRequested(
-                this.defaultHost, response, this.defltAuthStrategy, this.authState, this.context));
+        Assert.assertTrue(this.httpAuthenticator.updateAuthState(
+                this.defaultHost, ChallengeType.TARGET, response, this.authState, this.context));
 
-        Mockito.verify(this.defltAuthStrategy).isAuthenticationRequested(this.defaultHost, response, this.context);
-        Mockito.verify(this.defltAuthStrategy).authFailed(this.defaultHost, this.authScheme, this.context);
+        Mockito.verify(this.authCache).remove(this.defaultHost);
     }
 
     @Test
     public void testAuthenticationNotRequestedUnchallenged() throws Exception {
         final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
-        Mockito.when(this.defltAuthStrategy.isAuthenticationRequested(
-                Mockito.any(HttpHost.class),
-                Mockito.any(HttpResponse.class),
-                Mockito.any(HttpContext.class))).thenReturn(Boolean.FALSE);
 
-        Assert.assertFalse(this.httpAuthenticator.isAuthenticationRequested(
-                this.defaultHost, response, this.defltAuthStrategy, this.authState, this.context));
+        Assert.assertFalse(this.httpAuthenticator.updateAuthState(
+                this.defaultHost, ChallengeType.TARGET, response, this.authState, this.context));
         Assert.assertEquals(AuthProtocolState.UNCHALLENGED, this.authState.getState());
-
-        Mockito.verify(this.defltAuthStrategy).isAuthenticationRequested(this.defaultHost, response, this.context);
     }
 
     @Test
     public void testAuthenticationNotRequestedSuccess1() throws Exception {
         final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
-        Mockito.when(this.defltAuthStrategy.isAuthenticationRequested(
-                Mockito.any(HttpHost.class),
-                Mockito.any(HttpResponse.class),
-                Mockito.any(HttpContext.class))).thenReturn(Boolean.FALSE);
         this.authState.update(this.authScheme, this.credentials);
         this.authState.setState(AuthProtocolState.CHALLENGED);
 
-        Assert.assertFalse(this.httpAuthenticator.isAuthenticationRequested(
-                this.defaultHost, response, this.defltAuthStrategy, this.authState, this.context));
+        Assert.assertFalse(this.httpAuthenticator.updateAuthState(
+                this.defaultHost, ChallengeType.TARGET, response, this.authState, this.context));
         Assert.assertEquals(AuthProtocolState.SUCCESS, this.authState.getState());
 
-        Mockito.verify(this.defltAuthStrategy).isAuthenticationRequested(this.defaultHost, response, this.context);
-        Mockito.verify(this.defltAuthStrategy).authSucceeded(this.defaultHost, this.authScheme, this.context);
+        Mockito.verify(this.authCache).put(this.defaultHost, this.authScheme);
     }
 
     @Test
     public void testAuthenticationNotRequestedSuccess2() throws Exception {
         final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
-        Mockito.when(this.defltAuthStrategy.isAuthenticationRequested(
-                Mockito.any(HttpHost.class),
-                Mockito.any(HttpResponse.class),
-                Mockito.any(HttpContext.class))).thenReturn(Boolean.FALSE);
         this.authState.update(this.authScheme, this.credentials);
         this.authState.setState(AuthProtocolState.HANDSHAKE);
 
-        Assert.assertFalse(this.httpAuthenticator.isAuthenticationRequested(
-                this.defaultHost, response, this.defltAuthStrategy, this.authState, this.context));
+        Assert.assertFalse(this.httpAuthenticator.updateAuthState(
+                this.defaultHost, ChallengeType.TARGET, response, this.authState, this.context));
         Assert.assertEquals(AuthProtocolState.SUCCESS, this.authState.getState());
 
-        Mockito.verify(this.defltAuthStrategy).isAuthenticationRequested(this.defaultHost, response, this.context);
-        Mockito.verify(this.defltAuthStrategy).authSucceeded(this.defaultHost, this.authScheme, this.context);
+        Mockito.verify(this.authCache).put(this.defaultHost, this.authScheme);
     }
 
     @Test
@@ -193,10 +164,10 @@ public class TestHttpAuthenticator {
         response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "Digest realm=\"realm1\", nonce=\"1234\""));
         response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "whatever realm=\"realm1\", stuff=\"1234\""));
 
-        final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
+        final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
 
-        Assert.assertTrue(this.httpAuthenticator.handleAuthChallenge(host,
-                response, authStrategy, this.authState, this.context));
+        Assert.assertTrue(this.httpAuthenticator.handleAuthChallenge(
+                host,ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
         Assert.assertEquals(AuthProtocolState.CHALLENGED, this.authState.getState());
 
         final Queue<AuthOption> options = this.authState.getAuthOptions();
@@ -215,13 +186,10 @@ public class TestHttpAuthenticator {
         final HttpHost host = new HttpHost("somehost", 80);
         final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
 
-        Mockito.when(this.defltAuthStrategy.getChallenges(
-                Mockito.any(HttpHost.class),
-                Mockito.any(HttpResponse.class),
-                Mockito.any(HttpContext.class))).thenReturn(new HashMap<String, Header>());
+        final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
 
-        Assert.assertFalse(this.httpAuthenticator.handleAuthChallenge(host,
-                response, this.defltAuthStrategy, this.authState, this.context));
+        Assert.assertFalse(this.httpAuthenticator.handleAuthChallenge(
+                host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
     }
 
     @Test
@@ -231,10 +199,10 @@ public class TestHttpAuthenticator {
         response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "This realm=\"test\""));
         response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "That realm=\"realm1\", nonce=\"1234\""));
 
-        final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
+        final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
 
-        Assert.assertFalse(this.httpAuthenticator.handleAuthChallenge(host,
-                response, authStrategy, this.authState, this.context));
+        Assert.assertFalse(this.httpAuthenticator.handleAuthChallenge(
+                host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
     }
 
     @Test
@@ -246,10 +214,10 @@ public class TestHttpAuthenticator {
 
         this.credentialsProvider.clear();
 
-        final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
+        final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
 
-        Assert.assertFalse(this.httpAuthenticator.handleAuthChallenge(host,
-                response, authStrategy, this.authState, this.context));
+        Assert.assertFalse(this.httpAuthenticator.handleAuthChallenge(
+                host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
     }
 
     @Test
@@ -262,10 +230,10 @@ public class TestHttpAuthenticator {
         this.authState.setState(AuthProtocolState.CHALLENGED);
         this.authState.update(this.authScheme, this.credentials);
 
-        final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
+        final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
 
-        Assert.assertFalse(this.httpAuthenticator.handleAuthChallenge(host,
-                response, authStrategy, this.authState, this.context));
+        Assert.assertFalse(this.httpAuthenticator.handleAuthChallenge(
+                host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
 
         Assert.assertEquals(AuthProtocolState.FAILURE, this.authState.getState());
 
@@ -281,10 +249,10 @@ public class TestHttpAuthenticator {
 
         this.authState.setState(AuthProtocolState.FAILURE);
 
-        final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
+        final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
 
-        Assert.assertFalse(this.httpAuthenticator.handleAuthChallenge(host,
-                response, authStrategy, this.authState, this.context));
+        Assert.assertFalse(this.httpAuthenticator.handleAuthChallenge(
+                host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
 
         Assert.assertEquals(AuthProtocolState.FAILURE, this.authState.getState());
     }
@@ -297,13 +265,13 @@ public class TestHttpAuthenticator {
         response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "Digest realm=\"realm1\", nonce=\"1234\""));
         response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "whatever realm=\"realm1\", stuff=\"1234\""));
 
-        final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
+        final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
 
         this.authState.setState(AuthProtocolState.CHALLENGED);
         this.authState.update(new BasicScheme(), this.credentials);
 
-        Assert.assertFalse(this.httpAuthenticator.handleAuthChallenge(host,
-                response, authStrategy, this.authState, this.context));
+        Assert.assertFalse(this.httpAuthenticator.handleAuthChallenge(
+                host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
         Assert.assertEquals(AuthProtocolState.FAILURE, this.authState.getState());
         Assert.assertNull(this.authState.getCredentials());
     }
@@ -316,13 +284,13 @@ public class TestHttpAuthenticator {
         response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "Digest realm=\"realm1\", stale=true, nonce=\"1234\""));
         response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "whatever realm=\"realm1\", stuff=\"1234\""));
 
-        final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
+        final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
 
         this.authState.setState(AuthProtocolState.CHALLENGED);
         this.authState.update(new DigestScheme(), this.credentials);
 
-        Assert.assertTrue(this.httpAuthenticator.handleAuthChallenge(host,
-                response, authStrategy, this.authState, this.context));
+        Assert.assertTrue(this.httpAuthenticator.handleAuthChallenge(
+                host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
 
         Assert.assertEquals(AuthProtocolState.HANDSHAKE, this.authState.getState());
     }
@@ -334,13 +302,13 @@ public class TestHttpAuthenticator {
         response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "Digest realm=\"realm1\", nonce=\"1234\""));
         response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "whatever realm=\"realm1\", stuff=\"1234\""));
 
-        final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
+        final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
 
         this.authState.setState(AuthProtocolState.CHALLENGED);
         this.authState.update(new BasicScheme(), this.credentials);
 
-        Assert.assertTrue(this.httpAuthenticator.handleAuthChallenge(host,
-                response, authStrategy, this.authState, this.context));
+        Assert.assertTrue(this.httpAuthenticator.handleAuthChallenge(
+                host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
         Assert.assertEquals(AuthProtocolState.CHALLENGED, this.authState.getState());
 
         final Queue<AuthOption> options = this.authState.getAuthOptions();
@@ -355,16 +323,14 @@ public class TestHttpAuthenticator {
     public void testAuthenticationException() throws Exception {
         final HttpHost host = new HttpHost("somehost", 80);
         final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
+        response.addHeader(new BasicHeader(AUTH.WWW_AUTH, "blah blah blah"));
 
         this.authState.setState(AuthProtocolState.CHALLENGED);
 
-        Mockito.doThrow(new MalformedChallengeException()).when(this.defltAuthStrategy).getChallenges(
-                Mockito.any(HttpHost.class),
-                Mockito.any(HttpResponse.class),
-                Mockito.any(HttpContext.class));
+        final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
 
-        Assert.assertFalse(this.httpAuthenticator.handleAuthChallenge(host,
-                response, this.defltAuthStrategy, this.authState, this.context));
+        Assert.assertFalse(this.httpAuthenticator.handleAuthChallenge(
+                host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
 
         Assert.assertEquals(AuthProtocolState.UNCHALLENGED, this.authState.getState());
         Assert.assertNull(this.authState.getAuthScheme());

Added: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestNonStandardHttpScheme.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestNonStandardHttpScheme.java?rev=1689155&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestNonStandardHttpScheme.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestNonStandardHttpScheme.java Sat Jul  4 13:42:40 2015
@@ -0,0 +1,87 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.auth;
+
+import org.apache.http.Header;
+import org.apache.http.HttpRequest;
+import org.apache.http.auth.AuthChallenge;
+import org.apache.http.auth.AuthenticationException;
+import org.apache.http.auth.ChallengeType;
+import org.apache.http.auth.Credentials;
+import org.apache.http.auth.MalformedChallengeException;
+import org.apache.http.protocol.HttpContext;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestNonStandardHttpScheme {
+
+    static class TestAuthScheme extends NonStandardAuthScheme {
+
+        @Override
+        public void processChallenge(
+                final ChallengeType challengeType, final AuthChallenge authChallenge) throws MalformedChallengeException {
+            update(challengeType, authChallenge);
+        }
+
+        @Override
+        public Header authenticate(
+                final Credentials credentials,
+                final HttpRequest request,
+                final HttpContext context) throws AuthenticationException {
+            return null;
+        }
+
+        @Override
+        public String getSchemeName() {
+            return "test";
+        }
+
+        @Override
+        public boolean isComplete() {
+            return false;
+        }
+
+        @Override
+        public boolean isConnectionBased() {
+            return false;
+        }
+
+    }
+
+    @Test
+    public void testProcessChallenge() throws Exception {
+        final TestAuthScheme authscheme = new TestAuthScheme();
+        authscheme.processChallenge(ChallengeType.TARGET, new AuthChallenge("Test", "this_and_that", null));
+
+        Assert.assertEquals("test", authscheme.getSchemeName());
+        Assert.assertEquals("test(TARGET) this_and_that", authscheme.toString());
+        Assert.assertEquals("this_and_that", authscheme.getChallenge());
+    }
+
+}
+

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestNonStandardHttpScheme.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestNonStandardHttpScheme.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestNonStandardHttpScheme.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestStandardHttpScheme.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestStandardHttpScheme.java?rev=1689155&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestStandardHttpScheme.java (added)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestStandardHttpScheme.java Sat Jul  4 13:42:40 2015
@@ -0,0 +1,95 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.auth;
+
+import java.util.Arrays;
+
+import org.apache.http.Header;
+import org.apache.http.HttpRequest;
+import org.apache.http.auth.AuthChallenge;
+import org.apache.http.auth.AuthenticationException;
+import org.apache.http.auth.ChallengeType;
+import org.apache.http.auth.Credentials;
+import org.apache.http.auth.MalformedChallengeException;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.protocol.HttpContext;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestStandardHttpScheme {
+
+    static class TestAuthScheme extends StandardAuthScheme {
+
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        public void processChallenge(
+                final ChallengeType challengeType, final AuthChallenge authChallenge) throws MalformedChallengeException {
+            update(challengeType, authChallenge);
+        }
+
+        @Override
+        public Header authenticate(
+                final Credentials credentials,
+                final HttpRequest request,
+                final HttpContext context) throws AuthenticationException {
+            return null;
+        }
+
+        @Override
+        public String getSchemeName() {
+            return "test";
+        }
+
+        @Override
+        public boolean isComplete() {
+            return false;
+        }
+
+        @Override
+        public boolean isConnectionBased() {
+            return false;
+        }
+
+    }
+
+    @Test
+    public void testProcessChallenge() throws Exception {
+        final TestAuthScheme authscheme = new TestAuthScheme();
+        authscheme.processChallenge(ChallengeType.TARGET, new AuthChallenge("Test", null, Arrays.asList(
+                new BasicNameValuePair("realm", "realm1"), new BasicNameValuePair("this", "blah"))));
+
+        Assert.assertEquals("test", authscheme.getSchemeName());
+        Assert.assertEquals("test(TARGET) {realm=realm1, this=blah}", authscheme.toString());
+        Assert.assertEquals("realm1", authscheme.getParameter("realm"));
+        Assert.assertEquals(null, authscheme.getParameter("test"));
+        Assert.assertEquals("blah", authscheme.getParameter("this"));
+    }
+
+}
+

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestStandardHttpScheme.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestStandardHttpScheme.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestStandardHttpScheme.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestAuthenticationStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestAuthenticationStrategy.java?rev=1689155&r1=1689154&r2=1689155&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestAuthenticationStrategy.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestAuthenticationStrategy.java Sat Jul  4 13:42:40 2015
@@ -27,23 +27,19 @@
 package org.apache.http.impl.client;
 
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Queue;
 
-import org.apache.http.Header;
 import org.apache.http.HttpHost;
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpStatus;
-import org.apache.http.HttpVersion;
-import org.apache.http.auth.AUTH;
+import org.apache.http.auth.AuthChallenge;
 import org.apache.http.auth.AuthOption;
-import org.apache.http.auth.AuthScheme;
 import org.apache.http.auth.AuthSchemeProvider;
 import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.ChallengeType;
 import org.apache.http.auth.CredentialsProvider;
 import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.client.AuthCache;
 import org.apache.http.client.config.AuthSchemes;
 import org.apache.http.client.config.RequestConfig;
 import org.apache.http.client.protocol.HttpClientContext;
@@ -53,98 +49,38 @@ import org.apache.http.impl.auth.BasicSc
 import org.apache.http.impl.auth.BasicSchemeFactory;
 import org.apache.http.impl.auth.DigestScheme;
 import org.apache.http.impl.auth.DigestSchemeFactory;
-import org.apache.http.message.BasicHeader;
-import org.apache.http.message.BasicHttpResponse;
+import org.apache.http.message.BasicNameValuePair;
 import org.junit.Assert;
 import org.junit.Test;
-import org.mockito.Mockito;
 
 /**
- * Simple tests for {@link AuthenticationStrategyImpl}.
+ * Simple tests for {@link DefaultAuthenticationStrategy}.
  */
 @SuppressWarnings("boxing") // test code
 public class TestAuthenticationStrategy {
 
-    @Test(expected=IllegalArgumentException.class)
-    public void testIsAuthenticationRequestedInvalidInput() throws Exception {
-        final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
-        final HttpHost host = new HttpHost("localhost", 80);
-        final HttpClientContext context = HttpClientContext.create();
-        authStrategy.isAuthenticationRequested(host, null, context);
-    }
-
-    @Test
-    public void testTargetAuthRequested() throws Exception {
-        final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
-        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
-        final HttpHost host = new HttpHost("localhost", 80);
-        final HttpClientContext context = HttpClientContext.create();
-        Assert.assertTrue(authStrategy.isAuthenticationRequested(host, response, context));
-    }
-
-    @Test
-    public void testProxyAuthRequested() throws Exception {
-        final ProxyAuthenticationStrategy authStrategy = new ProxyAuthenticationStrategy();
-        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED, "UNAUTHORIZED");
-        final HttpHost host = new HttpHost("localhost", 80);
-        final HttpClientContext context = HttpClientContext.create();
-        Assert.assertTrue(authStrategy.isAuthenticationRequested(host, response, context));
-    }
-
-    @Test(expected=IllegalArgumentException.class)
-    public void testGetChallengesInvalidInput() throws Exception {
-        final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
-        final HttpHost host = new HttpHost("localhost", 80);
-        final HttpClientContext context = HttpClientContext.create();
-        authStrategy.getChallenges(host, null, context);
-    }
-
-    @Test
-    public void testGetChallenges() throws Exception {
-        final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
-        final HttpClientContext context = HttpClientContext.create();
-        final HttpHost host = new HttpHost("localhost", 80);
-        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
-        final Header h1 = new BasicHeader(AUTH.WWW_AUTH, "  Basic  realm=\"test\"");
-        final Header h2 = new BasicHeader(AUTH.WWW_AUTH, "\t\tDigest   realm=\"realm1\", nonce=\"1234\"");
-        final Header h3 = new BasicHeader(AUTH.WWW_AUTH, "WhatEver realm=\"realm1\", stuff=\"1234\"");
-        response.addHeader(h1);
-        response.addHeader(h2);
-        response.addHeader(h3);
-
-        final Map<String, Header> challenges = authStrategy.getChallenges(host, response, context);
-
-        Assert.assertNotNull(challenges);
-        Assert.assertEquals(3, challenges.size());
-        Assert.assertSame(h1, challenges.get("basic"));
-        Assert.assertSame(h2, challenges.get("digest"));
-        Assert.assertSame(h3, challenges.get("whatever"));
-    }
-
     @Test
     public void testSelectInvalidInput() throws Exception {
-        final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
-        final Map<String, Header> challenges = new HashMap<>();
-        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
+        final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
         final HttpHost authhost = new HttpHost("locahost", 80);
         final HttpClientContext context = HttpClientContext.create();
         try {
-            authStrategy.select(null, authhost, response, context);
+            authStrategy.select(null, authhost, Collections.<String, AuthChallenge>emptyMap(), context);
             Assert.fail("IllegalArgumentException expected");
         } catch (final IllegalArgumentException ex) {
         }
         try {
-            authStrategy.select(challenges, null, response, context);
+            authStrategy.select(ChallengeType.TARGET, null, Collections.<String, AuthChallenge>emptyMap(), context);
             Assert.fail("IllegalArgumentException expected");
         } catch (final IllegalArgumentException ex) {
         }
         try {
-            authStrategy.select(challenges, authhost, null, context);
+            authStrategy.select(ChallengeType.TARGET, authhost, null, context);
             Assert.fail("IllegalArgumentException expected");
         } catch (final IllegalArgumentException ex) {
         }
         try {
-            authStrategy.select(challenges, authhost, response, null);
+            authStrategy.select(ChallengeType.TARGET, authhost, Collections.<String, AuthChallenge>emptyMap(), null);
             Assert.fail("IllegalArgumentException expected");
         } catch (final IllegalArgumentException ex) {
         }
@@ -152,51 +88,54 @@ public class TestAuthenticationStrategy
 
     @Test
     public void testSelectNoSchemeRegistry() throws Exception {
-        final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
-        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
+        final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
         final HttpHost authhost = new HttpHost("locahost", 80);
         final HttpClientContext context = HttpClientContext.create();
 
-        final Map<String, Header> challenges = new HashMap<>();
-        challenges.put("basic", new BasicHeader(AUTH.WWW_AUTH, "Basic realm=\"test\""));
-        challenges.put("digest", new BasicHeader(AUTH.WWW_AUTH, "Digest realm=\"realm1\", nonce=\"1234\""));
+        final Map<String, AuthChallenge> challenges = new HashMap<>();
+        challenges.put("basic", new AuthChallenge("Basic",
+                new BasicNameValuePair("realm", "test")));
+        challenges.put("digest", new AuthChallenge("Digest",
+                new BasicNameValuePair("realm", "test"), new BasicNameValuePair("nonce", "1234")));
 
-        final Queue<AuthOption> options = authStrategy.select(challenges, authhost, response, context);
+        final Queue<AuthOption> options = authStrategy.select(ChallengeType.TARGET, authhost, challenges, context);
         Assert.assertNotNull(options);
         Assert.assertEquals(0, options.size());
     }
 
     @Test
     public void testSelectNoCredentialsProvider() throws Exception {
-        final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
-        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
+        final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
         final HttpHost authhost = new HttpHost("locahost", 80);
         final HttpClientContext context = HttpClientContext.create();
 
-        final Map<String, Header> challenges = new HashMap<>();
-        challenges.put("basic", new BasicHeader(AUTH.WWW_AUTH, "Basic realm=\"test\""));
-        challenges.put("digest", new BasicHeader(AUTH.WWW_AUTH, "Digest realm=\"realm1\", nonce=\"1234\""));
+        final Map<String, AuthChallenge> challenges = new HashMap<>();
+        challenges.put("basic", new AuthChallenge("Basic",
+                new BasicNameValuePair("realm", "test")));
+        challenges.put("digest", new AuthChallenge("Digest",
+                new BasicNameValuePair("realm", "test"), new BasicNameValuePair("nonce", "1234")));
 
         final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
             .register("basic", new BasicSchemeFactory())
             .register("digest", new DigestSchemeFactory()).build();
         context.setAuthSchemeRegistry(authSchemeRegistry);
 
-        final Queue<AuthOption> options = authStrategy.select(challenges, authhost, response, context);
+        final Queue<AuthOption> options = authStrategy.select(ChallengeType.TARGET, authhost, challenges, context);
         Assert.assertNotNull(options);
         Assert.assertEquals(0, options.size());
     }
 
     @Test
     public void testNoCredentials() throws Exception {
-        final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
-        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
+        final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
         final HttpHost authhost = new HttpHost("locahost", 80);
         final HttpClientContext context = HttpClientContext.create();
 
-        final Map<String, Header> challenges = new HashMap<>();
-        challenges.put("basic", new BasicHeader(AUTH.WWW_AUTH, "Basic realm=\"realm1\""));
-        challenges.put("digest", new BasicHeader(AUTH.WWW_AUTH, "Digest realm=\"realm2\", nonce=\"1234\""));
+        final Map<String, AuthChallenge> challenges = new HashMap<>();
+        challenges.put("basic", new AuthChallenge("Basic",
+                new BasicNameValuePair("realm", "realm1")));
+        challenges.put("digest", new AuthChallenge("Digest",
+                new BasicNameValuePair("realm", "realm2"), new BasicNameValuePair("nonce", "1234")));
 
         final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
             .register("basic", new BasicSchemeFactory())
@@ -206,21 +145,22 @@ public class TestAuthenticationStrategy
         final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
         context.setCredentialsProvider(credentialsProvider);
 
-        final Queue<AuthOption> options = authStrategy.select(challenges, authhost, response, context);
+        final Queue<AuthOption> options = authStrategy.select(ChallengeType.TARGET, authhost, challenges, context);
         Assert.assertNotNull(options);
         Assert.assertEquals(0, options.size());
     }
 
     @Test
     public void testCredentialsFound() throws Exception {
-        final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
-        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
+        final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
         final HttpHost authhost = new HttpHost("somehost", 80);
         final HttpClientContext context = HttpClientContext.create();
 
-        final Map<String, Header> challenges = new HashMap<>();
-        challenges.put("basic", new BasicHeader(AUTH.WWW_AUTH, "Basic realm=\"realm1\""));
-        challenges.put("digest", new BasicHeader(AUTH.WWW_AUTH, "Digest realm=\"realm2\", nonce=\"1234\""));
+        final Map<String, AuthChallenge> challenges = new HashMap<>();
+        challenges.put("basic", new AuthChallenge("Basic",
+                new BasicNameValuePair("realm", "realm1")));
+        challenges.put("digest", new AuthChallenge("Digest",
+                new BasicNameValuePair("realm", "realm2"), new BasicNameValuePair("nonce", "1234")));
 
         final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
             .register("basic", new BasicSchemeFactory())
@@ -232,7 +172,7 @@ public class TestAuthenticationStrategy
                 new UsernamePasswordCredentials("user", "pwd"));
         context.setCredentialsProvider(credentialsProvider);
 
-        final Queue<AuthOption> options = authStrategy.select(challenges, authhost, response, context);
+        final Queue<AuthOption> options = authStrategy.select(ChallengeType.TARGET, authhost, challenges, context);
         Assert.assertNotNull(options);
         Assert.assertEquals(1, options.size());
         final AuthOption option = options.remove();
@@ -241,15 +181,17 @@ public class TestAuthenticationStrategy
 
     @Test
     public void testUnsupportedScheme() throws Exception {
-        final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
-        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
+        final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
         final HttpHost authhost = new HttpHost("somehost", 80);
         final HttpClientContext context = HttpClientContext.create();
 
-        final Map<String, Header> challenges = new HashMap<>();
-        challenges.put("basic", new BasicHeader(AUTH.WWW_AUTH, "Basic realm=\"realm1\""));
-        challenges.put("digest", new BasicHeader(AUTH.WWW_AUTH, "Digest realm=\"realm2\", nonce=\"1234\""));
-        challenges.put("whatever", new BasicHeader(AUTH.WWW_AUTH, "Whatever realm=\"realm3\""));
+        final Map<String, AuthChallenge> challenges = new HashMap<>();
+        challenges.put("basic", new AuthChallenge("Basic",
+                new BasicNameValuePair("realm", "realm1")));
+        challenges.put("digest", new AuthChallenge("Digest",
+                new BasicNameValuePair("realm", "realm2"), new BasicNameValuePair("nonce", "1234")));
+        challenges.put("whatever", new AuthChallenge("Whatever",
+                new BasicNameValuePair("realm", "realm3")));
 
         final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
             .register("basic", new BasicSchemeFactory())
@@ -261,7 +203,7 @@ public class TestAuthenticationStrategy
                 new UsernamePasswordCredentials("user", "pwd"));
         context.setCredentialsProvider(credentialsProvider);
 
-        final Queue<AuthOption> options = authStrategy.select(challenges, authhost, response, context);
+        final Queue<AuthOption> options = authStrategy.select(ChallengeType.TARGET, authhost, challenges, context);
         Assert.assertNotNull(options);
         Assert.assertEquals(2, options.size());
         final AuthOption option1 = options.remove();
@@ -272,8 +214,7 @@ public class TestAuthenticationStrategy
 
     @Test
     public void testCustomAuthPreference() throws Exception {
-        final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
-        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
+        final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
         final RequestConfig config = RequestConfig.custom()
             .setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC))
             .build();
@@ -281,9 +222,11 @@ public class TestAuthenticationStrategy
         final HttpHost authhost = new HttpHost("somehost", 80);
         final HttpClientContext context = HttpClientContext.create();
 
-        final Map<String, Header> challenges = new HashMap<>();
-        challenges.put("basic", new BasicHeader(AUTH.WWW_AUTH, "Basic realm=\"realm1\""));
-        challenges.put("digest", new BasicHeader(AUTH.WWW_AUTH, "Digest realm=\"realm2\", nonce=\"1234\""));
+        final Map<String, AuthChallenge> challenges = new HashMap<>();
+        challenges.put("basic", new AuthChallenge("Basic",
+                new BasicNameValuePair("realm", "realm1")));
+        challenges.put("digest", new AuthChallenge("Digest",
+                new BasicNameValuePair("realm", "realm2"), new BasicNameValuePair("nonce", "1234")));
 
         final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
             .register("basic", new BasicSchemeFactory())
@@ -296,143 +239,11 @@ public class TestAuthenticationStrategy
                 new UsernamePasswordCredentials("user", "pwd"));
         context.setCredentialsProvider(credentialsProvider);
 
-        final Queue<AuthOption> options = authStrategy.select(challenges, authhost, response, context);
+        final Queue<AuthOption> options = authStrategy.select(ChallengeType.TARGET, authhost, challenges, context);
         Assert.assertNotNull(options);
         Assert.assertEquals(1, options.size());
         final AuthOption option1 = options.remove();
         Assert.assertTrue(option1.getAuthScheme() instanceof BasicScheme);
     }
-
-    @Test
-    public void testAuthSucceededInvalidInput() throws Exception {
-        final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
-        final HttpHost authhost = new HttpHost("locahost", 80);
-        final BasicScheme authScheme = new BasicScheme();
-        final HttpClientContext context = HttpClientContext.create();
-        try {
-            authStrategy.authSucceeded(null, authScheme, context);
-            Assert.fail("IllegalArgumentException expected");
-        } catch (final IllegalArgumentException ex) {
-        }
-        try {
-            authStrategy.authSucceeded(authhost, null, context);
-            Assert.fail("IllegalArgumentException expected");
-        } catch (final IllegalArgumentException ex) {
-        }
-        try {
-            authStrategy.authSucceeded(authhost, authScheme, null);
-            Assert.fail("IllegalArgumentException expected");
-        } catch (final IllegalArgumentException ex) {
-        }
-    }
-
-    @Test
-    public void testAuthSucceeded() throws Exception {
-        final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
-        final HttpHost authhost = new HttpHost("somehost", 80);
-        final BasicScheme authScheme = new BasicScheme();
-        authScheme.processChallenge(new BasicHeader(AUTH.WWW_AUTH, "Basic realm=test"));
-
-        final AuthCache authCache = Mockito.mock(AuthCache.class);
-
-        final HttpClientContext context = HttpClientContext.create();
-        context.setAuthCache(authCache);
-
-        authStrategy.authSucceeded(authhost, authScheme, context);
-        Mockito.verify(authCache).put(authhost, authScheme);
-    }
-
-    @Test
-    public void testAuthSucceededNoCache() throws Exception {
-        final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
-        final HttpHost authhost = new HttpHost("somehost", 80);
-        final BasicScheme authScheme = new BasicScheme();
-        authScheme.processChallenge(new BasicHeader(AUTH.WWW_AUTH, "Basic realm=test"));
-
-        final HttpClientContext context = HttpClientContext.create();
-        context.setAuthCache(null);
-
-        authStrategy.authSucceeded(authhost, authScheme, context);
-        final AuthCache authCache = context.getAuthCache();
-        Assert.assertNotNull(authCache);
-    }
-
-    @Test
-    public void testAuthScemeNotCompleted() throws Exception {
-        final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
-        final HttpHost authhost = new HttpHost("somehost", 80);
-        final BasicScheme authScheme = new BasicScheme();
-
-        final AuthCache authCache = Mockito.mock(AuthCache.class);
-
-        final HttpClientContext context = HttpClientContext.create();
-        context.setAuthCache(authCache);
-
-        authStrategy.authSucceeded(authhost, authScheme, context);
-        Mockito.verify(authCache, Mockito.never()).put(authhost, authScheme);
-    }
-
-    @Test
-    public void testAuthScemeNonCacheable() throws Exception {
-        final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
-        final HttpHost authhost = new HttpHost("somehost", 80);
-        final AuthScheme authScheme = Mockito.mock(AuthScheme.class);
-        Mockito.when(authScheme.isComplete()).thenReturn(true);
-        Mockito.when(authScheme.getSchemeName()).thenReturn("whatever");
-
-        final AuthCache authCache = Mockito.mock(AuthCache.class);
-
-        final HttpClientContext context = HttpClientContext.create();
-        context.setAuthCache(authCache);
-
-        authStrategy.authSucceeded(authhost, authScheme, context);
-        Mockito.verify(authCache, Mockito.never()).put(authhost, authScheme);
-    }
-
-    @Test
-    public void testAuthFailedInvalidInput() throws Exception {
-        final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
-        final HttpHost authhost = new HttpHost("locahost", 80);
-        final BasicScheme authScheme = new BasicScheme();
-        final HttpClientContext context = HttpClientContext.create();
-        try {
-            authStrategy.authFailed(null, authScheme, context);
-            Assert.fail("IllegalArgumentException expected");
-        } catch (final IllegalArgumentException ex) {
-        }
-        try {
-            authStrategy.authFailed(authhost, authScheme, null);
-            Assert.fail("IllegalArgumentException expected");
-        } catch (final IllegalArgumentException ex) {
-        }
-    }
-
-    @Test
-    public void testAuthFailed() throws Exception {
-        final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
-        final HttpHost authhost = new HttpHost("somehost", 80);
-        final BasicScheme authScheme = new BasicScheme();
-        authScheme.processChallenge(new BasicHeader(AUTH.WWW_AUTH, "Basic realm=test"));
-
-        final AuthCache authCache = Mockito.mock(AuthCache.class);
-
-        final HttpClientContext context = HttpClientContext.create();
-        context.setAuthCache(authCache);
-
-        authStrategy.authFailed(authhost, authScheme, context);
-        Mockito.verify(authCache).remove(authhost);
-    }
-
-    @Test
-    public void testAuthFailedNoCache() throws Exception {
-        final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
-        final HttpHost authhost = new HttpHost("somehost", 80);
-        final BasicScheme authScheme = new BasicScheme();
-
-        final HttpClientContext context = HttpClientContext.create();
-        context.setAuthCache(null);
-
-        authStrategy.authFailed(authhost, authScheme, context);
-    }
-
+    
 }



Mime
View raw message