hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1692371 [3/3] - in /httpcomponents/httpclient/trunk: fluent-hc/src/main/java/org/apache/http/client/fluent/ httpclient-cache/src/main/java/org/apache/http/client/cache/ httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ http...
Date Thu, 23 Jul 2015 10:00:47 GMT
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=1692371&r1=1692370&r2=1692371&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 Thu Jul 23 10:00:46 2015
@@ -36,26 +36,25 @@ 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.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.auth.AuthChallenge;
 import org.apache.http.auth.AuthScheme;
+import org.apache.http.auth.AuthScope;
 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.impl.client.BasicCredentialsProvider;
 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;
@@ -78,27 +77,33 @@ public class TestDigestScheme {
     public void testDigestAuthenticationEmptyChallenge1() throws Exception {
         final AuthChallenge authChallenge = parse("Digest");
         final AuthScheme authscheme = new DigestScheme();
-        authscheme.processChallenge(ChallengeType.TARGET, authChallenge);
+        authscheme.processChallenge(authChallenge, null);
     }
 
     @Test(expected=MalformedChallengeException.class)
     public void testDigestAuthenticationEmptyChallenge2() throws Exception {
         final AuthChallenge authChallenge = parse("Digest ");
         final AuthScheme authscheme = new DigestScheme();
-        authscheme.processChallenge(ChallengeType.TARGET, authChallenge);
+        authscheme.processChallenge(authChallenge, null);
     }
 
     @Test
     public void testDigestAuthenticationWithDefaultCreds() throws Exception {
+        final HttpRequest request = new BasicHttpRequest("Simple", "/");
+        final HttpHost host = new HttpHost("somehost", 80);
+        final AuthScope authScope = new AuthScope(host, "realm1", null);
+        final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+        final Credentials creds = new UsernamePasswordCredentials("username","password");
+        credentialsProvider.setCredentials(authScope, creds);
+
         final String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\"";
         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(ChallengeType.TARGET, authChallenge);
-        final Header authResponse = authscheme.authenticate(cred, request, context);
-        Assert.assertTrue(authscheme.isComplete());
+        authscheme.processChallenge(authChallenge, null);
+
+        Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
+        final String authResponse = authscheme.generateAuthResponse(host, request, null);
+        Assert.assertTrue(authscheme.isChallengeComplete());
         Assert.assertFalse(authscheme.isConnectionBased());
 
         final Map<String, String> table = parseAuthResponse(authResponse);
@@ -111,14 +116,20 @@ public class TestDigestScheme {
 
     @Test
     public void testDigestAuthentication() throws Exception {
+        final HttpRequest request = new BasicHttpRequest("Simple", "/");
+        final HttpHost host = new HttpHost("somehost", 80);
+        final AuthScope authScope = new AuthScope(host, "realm1", null);
+        final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+        final Credentials creds = new UsernamePasswordCredentials("username","password");
+        credentialsProvider.setCredentials(authScope, creds);
+
         final String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\"";
         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(ChallengeType.TARGET, authChallenge);
-        final Header authResponse = authscheme.authenticate(cred, request, context);
+        authscheme.processChallenge(authChallenge, null);
+
+        Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
+        final String authResponse = authscheme.generateAuthResponse(host, request, null);
 
         final Map<String, String> table = parseAuthResponse(authResponse);
         Assert.assertEquals("username", table.get("username"));
@@ -130,20 +141,29 @@ public class TestDigestScheme {
 
     @Test
     public void testDigestAuthenticationInvalidInput() throws Exception {
+        final HttpHost host = new HttpHost("somehost", 80);
+        final AuthScope authScope = new AuthScope(host, "realm1", null);
+        final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+        final Credentials creds = new UsernamePasswordCredentials("username","password");
+        credentialsProvider.setCredentials(authScope, creds);
+
         final String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\"";
         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(ChallengeType.TARGET, authChallenge);
+        authscheme.processChallenge(authChallenge, null);
+
+        try {
+            authscheme.isResponseReady(null, credentialsProvider, null);
+            Assert.fail("IllegalArgumentException should have been thrown");
+        } catch (final IllegalArgumentException ex) {
+        }
         try {
-            authscheme.authenticate(null, request, context);
+            authscheme.isResponseReady(host, null, null);
             Assert.fail("IllegalArgumentException should have been thrown");
         } catch (final IllegalArgumentException ex) {
         }
         try {
-            authscheme.authenticate(cred, null, context);
+            authscheme.generateAuthResponse(host, null, null);
             Assert.fail("IllegalArgumentException should have been thrown");
         } catch (final IllegalArgumentException ex) {
         }
@@ -151,16 +171,22 @@ public class TestDigestScheme {
 
     @Test
     public void testDigestAuthenticationWithSHA() throws Exception {
+        final HttpRequest request = new BasicHttpRequest("Simple", "/");
+        final HttpHost host = new HttpHost("somehost", 80);
+        final AuthScope authScope = new AuthScope(host, "realm1", null);
+        final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+        final Credentials creds = new UsernamePasswordCredentials("username","password");
+        credentialsProvider.setCredentials(authScope, creds);
+
         final String challenge = "Digest realm=\"realm1\", " +
                 "nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " +
                 "algorithm=SHA";
         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(ChallengeType.TARGET, authChallenge);
-        final Header authResponse = authscheme.authenticate(cred, request, context);
+        authscheme.processChallenge(authChallenge, null);
+
+        Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
+        final String authResponse = authscheme.generateAuthResponse(host, request, null);
 
         final Map<String, String> table = parseAuthResponse(authResponse);
         Assert.assertEquals("username", table.get("username"));
@@ -172,14 +198,20 @@ public class TestDigestScheme {
 
     @Test
     public void testDigestAuthenticationWithQueryStringInDigestURI() throws Exception {
+        final HttpRequest request = new BasicHttpRequest("Simple", "/?param=value");
+        final HttpHost host = new HttpHost("somehost", 80);
+        final AuthScope authScope = new AuthScope(host, "realm1", null);
+        final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+        final Credentials creds = new UsernamePasswordCredentials("username","password");
+        credentialsProvider.setCredentials(authScope, creds);
+
         final String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\"";
         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(ChallengeType.TARGET, authChallenge);
-        final Header authResponse = authscheme.authenticate(cred, request, context);
+        authscheme.processChallenge(authChallenge, null);
+
+        Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
+        final String authResponse = authscheme.generateAuthResponse(host, request, null);
 
         final Map<String, String> table = parseAuthResponse(authResponse);
         Assert.assertEquals("username", table.get("username"));
@@ -189,64 +221,40 @@ public class TestDigestScheme {
         Assert.assertEquals("a847f58f5fef0bc087bcb9c3eb30e042", table.get("response"));
     }
 
-    @Test
-    public void testDigestAuthenticationWithMultipleRealms() throws Exception {
-        final String challenge1 = "Digest realm=\"realm1\", nonce=\"abcde\"";
-        final String challenge2 = "Digest realm=\"realm2\", nonce=\"123546\"";
-        final Credentials cred = new UsernamePasswordCredentials("username","password");
-        final Credentials cred2 = new UsernamePasswordCredentials("uname2","password2");
-
-        final AuthChallenge authChallenge1 = parse(challenge1);
-        final HttpRequest request = new BasicHttpRequest("Simple", "/");
-        final HttpContext context = new BasicHttpContext();
-        final DigestScheme authscheme = new DigestScheme();
-        authscheme.processChallenge(ChallengeType.TARGET, authChallenge1);
-        Header authResponse = authscheme.authenticate(cred, request, context);
-
-        Map<String, String> table = parseAuthResponse(authResponse);
-        Assert.assertEquals("username", table.get("username"));
-        Assert.assertEquals("realm1", table.get("realm"));
-        Assert.assertEquals("/", table.get("uri"));
-        Assert.assertEquals("abcde", table.get("nonce"));
-        Assert.assertEquals("786f500303eac1478f3c2865e676ed68", table.get("response"));
-
-        final AuthChallenge authChallenge2 = parse(challenge2);
-        final DigestScheme authscheme2 = new DigestScheme();
-        authscheme2.processChallenge(ChallengeType.TARGET, authChallenge2);
-        authResponse = authscheme2.authenticate(cred2, request, context);
-
-        table = parseAuthResponse(authResponse);
-        Assert.assertEquals("uname2", table.get("username"));
-        Assert.assertEquals("realm2", table.get("realm"));
-        Assert.assertEquals("/", table.get("uri"));
-        Assert.assertEquals("123546", table.get("nonce"));
-        Assert.assertEquals("0283edd9ef06a38b378b3b74661391e9", table.get("response"));
-    }
-
     @Test(expected=AuthenticationException.class)
     public void testDigestAuthenticationNoRealm() throws Exception {
+        final HttpRequest request = new BasicHttpRequest("Simple", "/");
+        final HttpHost host = new HttpHost("somehost", 80);
+        final AuthScope authScope = new AuthScope(host, "realm1", null);
+        final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+        final Credentials creds = new UsernamePasswordCredentials("username","password");
+        credentialsProvider.setCredentials(authScope, creds);
+
         final String challenge = "Digest no-realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\"";
         final AuthChallenge authChallenge = parse(challenge);
-        final HttpContext context = new BasicHttpContext();
         final DigestScheme authscheme = new DigestScheme();
-        authscheme.processChallenge(ChallengeType.TARGET, authChallenge);
+        authscheme.processChallenge(authChallenge, null);
 
-        final Credentials cred = new UsernamePasswordCredentials("username","password");
-        final HttpRequest request = new BasicHttpRequest("Simple", "/");
-        authscheme.authenticate(cred, request, context);
+        Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
+        authscheme.generateAuthResponse(host, request, null);
     }
 
     @Test(expected=AuthenticationException.class)
     public void testDigestAuthenticationNoNonce() throws Exception {
+        final HttpRequest request = new BasicHttpRequest("Simple", "/");
+        final HttpHost host = new HttpHost("somehost", 80);
+        final AuthScope authScope = new AuthScope(host, "realm1", null);
+        final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+        final Credentials creds = new UsernamePasswordCredentials("username","password");
+        credentialsProvider.setCredentials(authScope, creds);
+
         final String challenge = "Digest realm=\"realm1\", no-nonce=\"f2a3f18799759d4f1a1c068b92b573cb\"";
         final AuthChallenge authChallenge = parse(challenge);
-        final HttpContext context = new BasicHttpContext();
         final DigestScheme authscheme = new DigestScheme();
-        authscheme.processChallenge(ChallengeType.TARGET, authChallenge);
+        authscheme.processChallenge(authChallenge, null);
 
-        final Credentials cred = new UsernamePasswordCredentials("username","password");
-        final HttpRequest request = new BasicHttpRequest("Simple", "/");
-        authscheme.authenticate(cred, request, context);
+        Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
+        authscheme.generateAuthResponse(host, request, null);
     }
 
     /**
@@ -261,6 +269,13 @@ public class TestDigestScheme {
         final String password="password";
         final String nonce="e273f1776275974f1a120d8b92c5b3cb";
 
+        final HttpRequest request = new BasicHttpRequest("Simple", "/");
+        final HttpHost host = new HttpHost("somehost", 80);
+        final AuthScope authScope = new AuthScope(host, realm, null);
+        final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+        final Credentials creds = new UsernamePasswordCredentials(username, password);
+        credentialsProvider.setCredentials(authScope, creds);
+
         final String challenge="Digest realm=\"" + realm + "\", "
             + "nonce=\"" + nonce + "\", "
             + "opaque=\"SomeString\", "
@@ -270,17 +285,14 @@ public class TestDigestScheme {
 
         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(ChallengeType.TARGET, authChallenge);
-        final Header authResponse = authscheme.authenticate(cred, request, context);
-        final String response = authResponse.getValue();
+        authscheme.processChallenge(authChallenge, null);
+
+        Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
+        final String authResponse = authscheme.generateAuthResponse(host, request, null);
 
-        Assert.assertTrue(response.indexOf("nc=00000001") > 0); // test for quotes
-        Assert.assertTrue(response.indexOf("qop=auth") > 0); // test for quotes
+        Assert.assertTrue(authResponse.indexOf("nc=00000001") > 0); // test for quotes
+        Assert.assertTrue(authResponse.indexOf("qop=auth") > 0); // test for quotes
 
         final Map<String, String> table = parseAuthResponse(authResponse);
         Assert.assertEquals(username, table.get("username"));
@@ -308,6 +320,13 @@ public class TestDigestScheme {
         final String password="password";
         final String nonce="e273f1776275974f1a120d8b92c5b3cb";
 
+        final HttpRequest request = new BasicHttpRequest("Simple", "/");
+        final HttpHost host = new HttpHost("somehost", 80);
+        final AuthScope authScope = new AuthScope(host, realm, null);
+        final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+        final Credentials creds = new UsernamePasswordCredentials(username, password);
+        credentialsProvider.setCredentials(authScope, creds);
+
         final String challenge="Digest realm=\"" + realm + "\", "
             + "nonce=\"" + nonce + "\", "
             + "opaque=\"SomeString\", "
@@ -316,14 +335,10 @@ public class TestDigestScheme {
 
         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(ChallengeType.TARGET, authChallenge);
-        final Header authResponse = authscheme.authenticate(cred, request, context);
+        authscheme.processChallenge(authChallenge, null);
+        Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
+        final String authResponse = authscheme.generateAuthResponse(host, request, null);
 
         final Map<String, String> table = parseAuthResponse(authResponse);
         Assert.assertEquals(username, table.get("username"));
@@ -350,6 +365,13 @@ public class TestDigestScheme {
         final String password="password";
         final String nonce="e273f1776275974f1a120d8b92c5b3cb";
 
+        final HttpRequest request = new BasicHttpRequest("Simple", "/");
+        final HttpHost host = new HttpHost("somehost", 80);
+        final AuthScope authScope = new AuthScope(host, realm, null);
+        final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+        final Credentials creds = new UsernamePasswordCredentials(username, password);
+        credentialsProvider.setCredentials(authScope, creds);
+
         final String challenge="Digest realm=\"" + realm + "\", "
             + "nonce=\"" + nonce + "\", "
             + "opaque=\"SomeString\", "
@@ -360,12 +382,10 @@ public class TestDigestScheme {
         final AuthChallenge authChallenge = parse(challenge);
 
         final DigestScheme authscheme = new DigestScheme();
-        authscheme.processChallenge(ChallengeType.TARGET, authChallenge);
+        authscheme.processChallenge(authChallenge, null);
 
-        final Credentials cred = new UsernamePasswordCredentials(username, password);
-        final HttpRequest request = new BasicHttpRequest("Simple", "/");
-        final HttpContext context = new BasicHttpContext();
-        authscheme.authenticate(cred, request, context);
+        Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
+        authscheme.generateAuthResponse(host, request, null);
     }
 
     /**
@@ -380,6 +400,13 @@ public class TestDigestScheme {
         final String password="password";
         final String nonce="e273f1776275974f1a120d8b92c5b3cb";
 
+        final HttpRequest request = new BasicHttpRequest("Simple", "/");
+        final HttpHost host = new HttpHost("somehost", 80);
+        final AuthScope authScope = new AuthScope(host, realm, null);
+        final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+        final Credentials creds = new UsernamePasswordCredentials(username, password);
+        credentialsProvider.setCredentials(authScope, creds);
+
         final String challenge="Digest realm=\"" + realm + "\", "
             + "nonce=\"" + nonce + "\", "
             + "opaque=\"SomeString\", "
@@ -390,12 +417,10 @@ public class TestDigestScheme {
         final AuthChallenge authChallenge = parse(challenge);
 
         final DigestScheme authscheme = new DigestScheme();
-        authscheme.processChallenge(ChallengeType.TARGET, authChallenge);
+        authscheme.processChallenge(authChallenge, null);
 
-        final Credentials cred = new UsernamePasswordCredentials(username, password);
-        final HttpRequest request = new BasicHttpRequest("Simple", "/");
-        final HttpContext context = new BasicHttpContext();
-        authscheme.authenticate(cred, request, context);
+        Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
+        authscheme.generateAuthResponse(host, request, null);
     }
 
     @Test
@@ -404,17 +429,16 @@ public class TestDigestScheme {
                 "nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", stale=\"true\"";
         final AuthChallenge authChallenge = parse(challenge);
         final AuthScheme authscheme = new DigestScheme();
-        authscheme.processChallenge(ChallengeType.TARGET, authChallenge);
+        authscheme.processChallenge(authChallenge, null);
 
-        Assert.assertFalse(authscheme.isComplete());
+        Assert.assertFalse(authscheme.isChallengeComplete());
     }
 
-    private static Map<String, String> parseAuthResponse(final Header authResponse) {
-        final String s = authResponse.getValue();
-        if (!s.startsWith("Digest ")) {
+    private static Map<String, String> parseAuthResponse(final String authResponse) {
+        if (!authResponse.startsWith("Digest ")) {
             return null;
         }
-        final HeaderElement[] elements = BasicHeaderValueParser.parseElements(s.substring(7), null);
+        final HeaderElement[] elements = BasicHeaderValueParser.parseElements(authResponse.substring(7), null);
         final Map<String, String> map = new HashMap<>(elements.length);
         for (final HeaderElement element : elements) {
             map.put(element.getName(), element.getValue());
@@ -424,50 +448,73 @@ public class TestDigestScheme {
 
     @Test
     public void testDigestNouceCount() throws Exception {
+        final HttpRequest request = new BasicHttpRequest("GET", "/");
+        final HttpHost host = new HttpHost("somehost", 80);
+        final AuthScope authScope = new AuthScope(host, "realm1", null);
+        final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+        final Credentials creds = new UsernamePasswordCredentials("username","password");
+        credentialsProvider.setCredentials(authScope, creds);
+
         final String challenge1 = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", qop=auth";
         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(ChallengeType.TARGET, authChallenge1);
-        final Header authResponse1 = authscheme.authenticate(cred, request, context);
+        authscheme.processChallenge(authChallenge1, null);
+        Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
+        final String authResponse1 = authscheme.generateAuthResponse(host, request, null);
+
         final Map<String, String> table1 = parseAuthResponse(authResponse1);
         Assert.assertEquals("00000001", table1.get("nc"));
-        final Header authResponse2 = authscheme.authenticate(cred, request, context);
+
+        Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
+        final String authResponse2 = authscheme.generateAuthResponse(host, request, null);
+
         final Map<String, String> table2 = parseAuthResponse(authResponse2);
         Assert.assertEquals("00000002", table2.get("nc"));
         final String challenge2 = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", qop=auth";
         final AuthChallenge authChallenge2 = parse(challenge2);
-        authscheme.processChallenge(ChallengeType.TARGET, authChallenge2);
-        final Header authResponse3 = authscheme.authenticate(cred, request, context);
+        authscheme.processChallenge(authChallenge2, null);
+
+        Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
+        final String authResponse3 = authscheme.generateAuthResponse(host, request, null);
+
         final Map<String, String> table3 = parseAuthResponse(authResponse3);
         Assert.assertEquals("00000003", table3.get("nc"));
         final String challenge3 = "Digest realm=\"realm1\", nonce=\"e273f1776275974f1a120d8b92c5b3cb\", qop=auth";
         final AuthChallenge authChallenge3 = parse(challenge3);
-        authscheme.processChallenge(ChallengeType.TARGET, authChallenge3);
-        final Header authResponse4 = authscheme.authenticate(cred, request, context);
+        authscheme.processChallenge(authChallenge3, null);
+
+        Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
+        final String authResponse4 = authscheme.generateAuthResponse(host, request, null);
+
         final Map<String, String> table4 = parseAuthResponse(authResponse4);
         Assert.assertEquals("00000001", table4.get("nc"));
     }
 
     @Test
     public void testDigestMD5SessA1AndCnonceConsistency() throws Exception {
+        final HttpHost host = new HttpHost("somehost", 80);
+        final AuthScope authScope = new AuthScope(host, "subnet.domain.com", null);
+        final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+        final HttpRequest request = new BasicHttpRequest("GET", "/");
+        final Credentials creds = new UsernamePasswordCredentials("username","password");
+        credentialsProvider.setCredentials(authScope, creds);
+
         final String challenge1 = "Digest qop=\"auth\", algorithm=MD5-sess, nonce=\"1234567890abcdef\", " +
                 "charset=utf-8, realm=\"subnet.domain.com\"";
         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(ChallengeType.TARGET, authChallenge1);
-        final Header authResponse1 = authscheme.authenticate(cred, request, context);
+        authscheme.processChallenge(authChallenge1, null);
+        Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
+        final String authResponse1 = authscheme.generateAuthResponse(host, request, null);
+
         final Map<String, String> table1 = parseAuthResponse(authResponse1);
         Assert.assertEquals("00000001", table1.get("nc"));
         final String cnonce1 = authscheme.getCnonce();
         final String sessionKey1 = authscheme.getA1();
 
-        final Header authResponse2 = authscheme.authenticate(cred, request, context);
+        Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
+        final String authResponse2 = authscheme.generateAuthResponse(host, request, null);
         final Map<String, String> table2 = parseAuthResponse(authResponse2);
         Assert.assertEquals("00000002", table2.get("nc"));
         final String cnonce2 = authscheme.getCnonce();
@@ -479,8 +526,9 @@ public class TestDigestScheme {
         final String challenge2 = "Digest qop=\"auth\", algorithm=MD5-sess, nonce=\"1234567890abcdef\", " +
             "charset=utf-8, realm=\"subnet.domain.com\"";
         final AuthChallenge authChallenge2 = parse(challenge2);
-        authscheme.processChallenge(ChallengeType.TARGET, authChallenge2);
-        final Header authResponse3 = authscheme.authenticate(cred, request, context);
+        authscheme.processChallenge(authChallenge2, null);
+        Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
+        final String authResponse3 = authscheme.generateAuthResponse(host, request, null);
         final Map<String, String> table3 = parseAuthResponse(authResponse3);
         Assert.assertEquals("00000003", table3.get("nc"));
 
@@ -493,8 +541,9 @@ public class TestDigestScheme {
         final String challenge3 = "Digest qop=\"auth\", algorithm=MD5-sess, nonce=\"fedcba0987654321\", " +
             "charset=utf-8, realm=\"subnet.domain.com\"";
         final AuthChallenge authChallenge3 = parse(challenge3);
-        authscheme.processChallenge(ChallengeType.TARGET, authChallenge3);
-        final Header authResponse4 = authscheme.authenticate(cred, request, context);
+        authscheme.processChallenge(authChallenge3, null);
+        Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
+        final String authResponse4 = authscheme.generateAuthResponse(host, request, null);
         final Map<String, String> table4 = parseAuthResponse(authResponse4);
         Assert.assertEquals("00000001", table4.get("nc"));
 
@@ -533,16 +582,21 @@ public class TestDigestScheme {
 
     @Test
     public void testDigestAuthenticationQopAuthInt() throws Exception {
+        final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("Post", "/");
+        request.setEntity(new StringEntity("abc\u00e4\u00f6\u00fcabc", HTTP.DEF_CONTENT_CHARSET));
+        final HttpHost host = new HttpHost("somehost", 80);
+        final AuthScope authScope = new AuthScope(host, "realm1", null);
+        final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+        final Credentials creds = new UsernamePasswordCredentials("username","password");
+        credentialsProvider.setCredentials(authScope, creds);
+
         final String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " +
                 "qop=\"auth,auth-int\"";
         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(ChallengeType.TARGET, authChallenge);
-        final Header authResponse = authscheme.authenticate(cred, request, context);
+        authscheme.processChallenge(authChallenge, null);
+        Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
+        final String authResponse = authscheme.generateAuthResponse(host, request, null);
 
         Assert.assertEquals("Post:/:acd2b59cd01c7737d8069015584c6cac", authscheme.getA2());
 
@@ -556,15 +610,20 @@ public class TestDigestScheme {
 
     @Test
     public void testDigestAuthenticationQopAuthIntNullEntity() throws Exception {
+        final HttpRequest request = new BasicHttpEntityEnclosingRequest("Post", "/");
+        final HttpHost host = new HttpHost("somehost", 80);
+        final AuthScope authScope = new AuthScope(host, "realm1", null);
+        final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+        final Credentials creds = new UsernamePasswordCredentials("username","password");
+        credentialsProvider.setCredentials(authScope, creds);
+
         final String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " +
                 "qop=\"auth,auth-int\"";
         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(ChallengeType.TARGET, authChallenge);
-        final Header authResponse = authscheme.authenticate(cred, request, context);
+        authscheme.processChallenge(authChallenge, null);
+        Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
+        final String authResponse = authscheme.generateAuthResponse(host, request, null);
 
         Assert.assertEquals("Post:/:d41d8cd98f00b204e9800998ecf8427e", authscheme.getA2());
 
@@ -578,16 +637,21 @@ public class TestDigestScheme {
 
     @Test
     public void testDigestAuthenticationQopAuthOrAuthIntNonRepeatableEntity() throws Exception {
+        final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("Post", "/");
+        request.setEntity(new InputStreamEntity(new ByteArrayInputStream(new byte[] {'a'}), -1));
+        final HttpHost host = new HttpHost("somehost", 80);
+        final AuthScope authScope = new AuthScope(host, "realm1", null);
+        final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+        final Credentials creds = new UsernamePasswordCredentials("username","password");
+        credentialsProvider.setCredentials(authScope, creds);
+
         final String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " +
                 "qop=\"auth,auth-int\"";
         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(ChallengeType.TARGET, authChallenge);
-        final Header authResponse = authscheme.authenticate(cred, request, context);
+        authscheme.processChallenge(authChallenge, null);
+        Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
+        final String authResponse = authscheme.generateAuthResponse(host, request, null);
 
         Assert.assertEquals("Post:/", authscheme.getA2());
 
@@ -601,32 +665,43 @@ public class TestDigestScheme {
 
     @Test
     public void testParameterCaseSensitivity() throws Exception {
+        final HttpRequest request = new BasicHttpRequest("GET", "/");
+        final HttpHost host = new HttpHost("somehost", 80);
+        final AuthScope authScope = new AuthScope(host, "-", null);
+        final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+        final Credentials creds = new UsernamePasswordCredentials("username","password");
+        credentialsProvider.setCredentials(authScope, creds);
+
         final String challenge = "Digest Realm=\"-\", " +
                 "nonce=\"YjYuNGYyYmJhMzUuY2I5ZDhlZDE5M2ZlZDM 1Mjk3NGJkNTIyYjgyNTcwMjQ=\", " +
                 "opaque=\"98700A3D9CE17065E2246B41035C6609\", qop=\"auth\"";
         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(ChallengeType.TARGET, authChallenge);
+        authscheme.processChallenge(authChallenge, null);
         Assert.assertEquals("-", authscheme.getRealm());
 
-        authscheme.authenticate(cred, request, context);
+        Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
+        authscheme.generateAuthResponse(host, request, null);
     }
 
     @Test(expected=AuthenticationException.class)
     public void testDigestAuthenticationQopIntOnlyNonRepeatableEntity() throws Exception {
+        final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("Post", "/");
+        request.setEntity(new InputStreamEntity(new ByteArrayInputStream(new byte[] {'a'}), -1));
+        final HttpHost host = new HttpHost("somehost", 80);
+        final AuthScope authScope = new AuthScope(host, "realm1", null);
+        final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+        final Credentials creds = new UsernamePasswordCredentials("username","password");
+        credentialsProvider.setCredentials(authScope, creds);
+
         final String challenge = "Digest realm=\"realm1\", nonce=\"f2a3f18799759d4f1a1c068b92b573cb\", " +
                 "qop=\"auth-int\"";
         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(ChallengeType.TARGET, authChallenge);
-        authscheme.authenticate(cred, request, context);
+        authscheme.processChallenge(authChallenge, null);
+
+        Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
+        authscheme.generateAuthResponse(host, request, null);
     }
 
     @Test
@@ -635,7 +710,7 @@ public class TestDigestScheme {
                 "qop=\"auth,auth-int\"";
         final AuthChallenge authChallenge = parse(challenge);
         final DigestScheme digestScheme = new DigestScheme();
-        digestScheme.processChallenge(ChallengeType.TARGET, authChallenge);
+        digestScheme.processChallenge(authChallenge, null);
 
         final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
         final ObjectOutputStream out = new ObjectOutputStream(buffer);
@@ -645,9 +720,9 @@ public class TestDigestScheme {
         final ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(raw));
         final DigestScheme authScheme = (DigestScheme) in.readObject();
 
-        Assert.assertEquals(digestScheme.getSchemeName(), authScheme.getSchemeName());
+        Assert.assertEquals(digestScheme.getName(), authScheme.getName());
         Assert.assertEquals(digestScheme.getRealm(), authScheme.getRealm());
-        Assert.assertEquals(digestScheme.isComplete(), authScheme.isComplete());
+        Assert.assertEquals(digestScheme.isChallengeComplete(), authScheme.isChallengeComplete());
         Assert.assertEquals(digestScheme.getA1(), authScheme.getA1());
         Assert.assertEquals(digestScheme.getA2(), authScheme.getA2());
         Assert.assertEquals(digestScheme.getCnonce(), authScheme.getCnonce());

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=1692371&r1=1692370&r2=1692371&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 Thu Jul 23 10:00:46 2015
@@ -35,7 +35,6 @@ import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.HttpVersion;
-import org.apache.http.auth.AuthOption;
 import org.apache.http.auth.AuthProtocolState;
 import org.apache.http.auth.AuthScheme;
 import org.apache.http.auth.AuthSchemeProvider;
@@ -44,11 +43,12 @@ 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.CredentialsProvider;
+import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.http.client.AuthCache;
 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.DefaultAuthenticationStrategy;
 import org.apache.http.message.BasicHeader;
 import org.apache.http.message.BasicHttpRequest;
@@ -68,8 +68,7 @@ public class TestHttpAuthenticator {
     private AuthScheme authScheme;
     private HttpContext context;
     private HttpHost defaultHost;
-    private Credentials credentials;
-    private BasicCredentialsProvider credentialsProvider;
+    private CredentialsProvider credentialsProvider;
     private Lookup<AuthSchemeProvider> authSchemeRegistry;
     private AuthCache authCache;
     private HttpAuthenticator httpAuthenticator;
@@ -78,14 +77,12 @@ public class TestHttpAuthenticator {
     public void setUp() throws Exception {
         this.authState = new AuthState();
         this.authScheme = Mockito.mock(AuthScheme.class);
-        Mockito.when(this.authScheme.getSchemeName()).thenReturn("Basic");
-        Mockito.when(this.authScheme.isComplete()).thenReturn(Boolean.TRUE);
+        Mockito.when(this.authScheme.getName()).thenReturn("Basic");
+        Mockito.when(this.authScheme.isChallengeComplete()).thenReturn(Boolean.TRUE);
         this.context = new BasicHttpContext();
         this.defaultHost = new HttpHost("localhost", 80);
         this.context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, this.defaultHost);
-        this.credentials = Mockito.mock(Credentials.class);
-        this.credentialsProvider = new BasicCredentialsProvider();
-        this.credentialsProvider.setCredentials(AuthScope.ANY, this.credentials);
+        this.credentialsProvider = Mockito.mock(CredentialsProvider.class);
         this.context.setAttribute(HttpClientContext.CREDS_PROVIDER, this.credentialsProvider);
         this.authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
             .register("basic", new BasicSchemeFactory())
@@ -111,7 +108,7 @@ public class TestHttpAuthenticator {
         final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
         response.setHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=test");
 
-        this.authState.update(this.authScheme, this.credentials);
+        this.authState.update(this.authScheme);
         this.authState.setState(AuthProtocolState.SUCCESS);
 
         Assert.assertTrue(this.httpAuthenticator.isChallenged(
@@ -132,7 +129,7 @@ public class TestHttpAuthenticator {
     @Test
     public void testAuthenticationNotRequestedSuccess1() throws Exception {
         final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
-        this.authState.update(this.authScheme, this.credentials);
+        this.authState.update(this.authScheme);
         this.authState.setState(AuthProtocolState.CHALLENGED);
 
         Assert.assertFalse(this.httpAuthenticator.isChallenged(
@@ -145,7 +142,7 @@ public class TestHttpAuthenticator {
     @Test
     public void testAuthenticationNotRequestedSuccess2() throws Exception {
         final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
-        this.authState.update(this.authScheme, this.credentials);
+        this.authState.update(this.authScheme);
         this.authState.setState(AuthProtocolState.HANDSHAKE);
 
         Assert.assertFalse(this.httpAuthenticator.isChallenged(
@@ -163,20 +160,47 @@ public class TestHttpAuthenticator {
         response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "Digest realm=\"realm1\", nonce=\"1234\""));
         response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "whatever realm=\"realm1\", stuff=\"1234\""));
 
+        final Credentials credentials = new UsernamePasswordCredentials("user:pass");
+        Mockito.when(this.credentialsProvider.getCredentials(Mockito.<AuthScope>any())).thenReturn(credentials);
+
+        final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
+
+        Assert.assertTrue(this.httpAuthenticator.prepareAuthResponse(
+                host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
+        Assert.assertEquals(AuthProtocolState.CHALLENGED, this.authState.getState());
+
+        final Queue<AuthScheme> options = this.authState.getAuthOptions();
+        Assert.assertNotNull(options);
+        final AuthScheme authScheme1 = options.poll();
+        Assert.assertNotNull(authScheme1);
+        Assert.assertEquals("digest", authScheme1.getName());
+        final AuthScheme authScheme2 = options.poll();
+        Assert.assertNotNull(authScheme2);
+        Assert.assertEquals("basic", authScheme2.getName());
+        Assert.assertNull(options.poll());
+    }
+
+    @Test
+    public void testAuthenticationCredentialsForBasic() 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(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=\"test\""));
+        response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "Digest realm=\"realm1\", nonce=\"1234\""));
+
+        final Credentials credentials = new UsernamePasswordCredentials("user:pass");
+        Mockito.when(this.credentialsProvider.getCredentials(new AuthScope(host, "test", "basic"))).thenReturn(credentials);
+
         final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
 
         Assert.assertTrue(this.httpAuthenticator.prepareAuthResponse(
                 host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
         Assert.assertEquals(AuthProtocolState.CHALLENGED, this.authState.getState());
 
-        final Queue<AuthOption> options = this.authState.getAuthOptions();
+        final Queue<AuthScheme> options = this.authState.getAuthOptions();
         Assert.assertNotNull(options);
-        final AuthOption option1 = options.poll();
-        Assert.assertNotNull(option1);
-        Assert.assertEquals("digest", option1.getAuthScheme().getSchemeName());
-        final AuthOption option2 = options.poll();
-        Assert.assertNotNull(option2);
-        Assert.assertEquals("basic", option2.getAuthScheme().getSchemeName());
+        final AuthScheme authScheme1 = options.poll();
+        Assert.assertNotNull(authScheme1);
+        Assert.assertEquals("basic", authScheme1.getName());
         Assert.assertNull(options.poll());
     }
 
@@ -211,8 +235,6 @@ public class TestHttpAuthenticator {
         response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=\"test\""));
         response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "Digest realm=\"realm1\", nonce=\"1234\""));
 
-        this.credentialsProvider.clear();
-
         final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
 
         Assert.assertFalse(this.httpAuthenticator.prepareAuthResponse(
@@ -227,7 +249,7 @@ public class TestHttpAuthenticator {
         response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "Digest realm=\"realm1\", nonce=\"1234\""));
 
         this.authState.setState(AuthProtocolState.CHALLENGED);
-        this.authState.update(this.authScheme, this.credentials);
+        this.authState.update(this.authScheme);
 
         final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
 
@@ -267,12 +289,11 @@ public class TestHttpAuthenticator {
         final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
 
         this.authState.setState(AuthProtocolState.CHALLENGED);
-        this.authState.update(new BasicScheme(), this.credentials);
+        this.authState.update(new BasicScheme());
 
         Assert.assertFalse(this.httpAuthenticator.prepareAuthResponse(
                 host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
         Assert.assertEquals(AuthProtocolState.FAILURE, this.authState.getState());
-        Assert.assertNull(this.authState.getCredentials());
     }
 
     @Test
@@ -286,7 +307,7 @@ public class TestHttpAuthenticator {
         final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
 
         this.authState.setState(AuthProtocolState.CHALLENGED);
-        this.authState.update(new DigestScheme(), this.credentials);
+        this.authState.update(new DigestScheme());
 
         Assert.assertTrue(this.httpAuthenticator.prepareAuthResponse(
                 host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
@@ -301,20 +322,23 @@ public class TestHttpAuthenticator {
         response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "Digest realm=\"realm1\", nonce=\"1234\""));
         response.addHeader(new BasicHeader(HttpHeaders.WWW_AUTHENTICATE, "whatever realm=\"realm1\", stuff=\"1234\""));
 
+        final Credentials credentials = new UsernamePasswordCredentials("user:pass");
+        Mockito.when(this.credentialsProvider.getCredentials(new AuthScope(host, "realm1", "digest"))).thenReturn(credentials);
+
         final DefaultAuthenticationStrategy authStrategy = new DefaultAuthenticationStrategy();
 
         this.authState.setState(AuthProtocolState.CHALLENGED);
-        this.authState.update(new BasicScheme(), this.credentials);
+        this.authState.update(new BasicScheme());
 
         Assert.assertTrue(this.httpAuthenticator.prepareAuthResponse(
                 host, ChallengeType.TARGET, response, authStrategy, this.authState, this.context));
         Assert.assertEquals(AuthProtocolState.CHALLENGED, this.authState.getState());
 
-        final Queue<AuthOption> options = this.authState.getAuthOptions();
+        final Queue<AuthScheme> options = this.authState.getAuthOptions();
         Assert.assertNotNull(options);
-        final AuthOption option1 = options.poll();
-        Assert.assertNotNull(option1);
-        Assert.assertEquals("digest", option1.getAuthScheme().getSchemeName());
+        final AuthScheme authScheme1 = options.poll();
+        Assert.assertNotNull(authScheme1);
+        Assert.assertEquals("digest", authScheme1.getName());
         Assert.assertNull(options.poll());
     }
 
@@ -333,21 +357,20 @@ public class TestHttpAuthenticator {
 
         Assert.assertEquals(AuthProtocolState.UNCHALLENGED, this.authState.getState());
         Assert.assertNull(this.authState.getAuthScheme());
-        Assert.assertNull(this.authState.getCredentials());
     }
 
     @Test
     public void testAuthFailureState() throws Exception {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         this.authState.setState(AuthProtocolState.FAILURE);
-        this.authState.update(this.authScheme, this.credentials);
+        this.authState.update(this.authScheme);
 
-        this.httpAuthenticator.addAuthResponse(request, authState, context);
+        this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authState, context);
 
         Assert.assertFalse(request.containsHeader(HttpHeaders.AUTHORIZATION));
 
-        Mockito.verify(this.authScheme, Mockito.never()).authenticate(
-                Mockito.any(Credentials.class),
+        Mockito.verify(this.authScheme, Mockito.never()).generateAuthResponse(
+                Mockito.eq(defaultHost),
                 Mockito.any(HttpRequest.class),
                 Mockito.any(HttpContext.class));
     }
@@ -356,42 +379,37 @@ public class TestHttpAuthenticator {
     public void testAuthChallengeStateNoOption() throws Exception {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         this.authState.setState(AuthProtocolState.CHALLENGED);
-        this.authState.update(this.authScheme, this.credentials);
+        this.authState.update(this.authScheme);
 
-        Mockito.when(this.authScheme.authenticate(
-                Mockito.any(Credentials.class),
+        Mockito.when(this.authScheme.generateAuthResponse(
+                Mockito.eq(defaultHost),
                 Mockito.any(HttpRequest.class),
-                Mockito.any(HttpContext.class))).thenReturn(new BasicHeader(HttpHeaders.AUTHORIZATION, "stuff"));
+                Mockito.any(HttpContext.class))).thenReturn("stuff");
 
-        this.httpAuthenticator.addAuthResponse(request, authState, context);
+        this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authState, context);
 
         Assert.assertTrue(request.containsHeader(HttpHeaders.AUTHORIZATION));
-
-        Mockito.verify(this.authScheme).authenticate(this.credentials, request, this.context);
     }
 
     @Test
     public void testAuthChallengeStateOneOptions() throws Exception {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         this.authState.setState(AuthProtocolState.CHALLENGED);
-        final LinkedList<AuthOption> authOptions = new LinkedList<>();
-        authOptions.add(new AuthOption(this.authScheme, this.credentials));
+        final LinkedList<AuthScheme> authOptions = new LinkedList<>();
+        authOptions.add(this.authScheme);
         this.authState.update(authOptions);
 
-        Mockito.when(this.authScheme.authenticate(
-                Mockito.any(Credentials.class),
+        Mockito.when(this.authScheme.generateAuthResponse(
+                Mockito.eq(defaultHost),
                 Mockito.any(HttpRequest.class),
-                Mockito.any(HttpContext.class))).thenReturn(new BasicHeader(HttpHeaders.AUTHORIZATION, "stuff"));
+                Mockito.any(HttpContext.class))).thenReturn("stuff");
 
-        this.httpAuthenticator.addAuthResponse(request, authState, context);
+        this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authState, context);
 
         Assert.assertSame(this.authScheme, this.authState.getAuthScheme());
-        Assert.assertSame(this.credentials, this.authState.getCredentials());
         Assert.assertNull(this.authState.getAuthOptions());
 
         Assert.assertTrue(request.containsHeader(HttpHeaders.AUTHORIZATION));
-
-        Mockito.verify(this.authScheme).authenticate(this.credentials, request, this.context);
     }
 
     @Test
@@ -399,74 +417,67 @@ public class TestHttpAuthenticator {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         this.authState.setState(AuthProtocolState.CHALLENGED);
 
-        final LinkedList<AuthOption> authOptions = new LinkedList<>();
+        final LinkedList<AuthScheme> authOptions = new LinkedList<>();
         final AuthScheme authScheme1 = Mockito.mock(AuthScheme.class);
-        Mockito.doThrow(new AuthenticationException()).when(authScheme1).authenticate(
-                Mockito.any(Credentials.class),
+        Mockito.doThrow(new AuthenticationException()).when(authScheme1).generateAuthResponse(
+                Mockito.eq(defaultHost),
                 Mockito.any(HttpRequest.class),
                 Mockito.any(HttpContext.class));
         final AuthScheme authScheme2 = Mockito.mock(AuthScheme.class);
-        Mockito.when(authScheme2.authenticate(
-                Mockito.any(Credentials.class),
+        Mockito.when(authScheme2.generateAuthResponse(
+                Mockito.eq(defaultHost),
                 Mockito.any(HttpRequest.class),
-                Mockito.any(HttpContext.class))).thenReturn(new BasicHeader(HttpHeaders.AUTHORIZATION, "stuff"));
-        authOptions.add(new AuthOption(authScheme1, this.credentials));
-        authOptions.add(new AuthOption(authScheme2, this.credentials));
+                Mockito.any(HttpContext.class))).thenReturn("stuff");
+        authOptions.add(authScheme1);
+        authOptions.add(authScheme2);
         this.authState.update(authOptions);
 
-        this.httpAuthenticator.addAuthResponse(request, authState, context);
+        this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authState, context);
 
         Assert.assertSame(authScheme2, this.authState.getAuthScheme());
-        Assert.assertSame(this.credentials, this.authState.getCredentials());
         Assert.assertNull(this.authState.getAuthOptions());
 
         Assert.assertTrue(request.containsHeader(HttpHeaders.AUTHORIZATION));
-
-        Mockito.verify(authScheme1, Mockito.times(1)).authenticate(this.credentials, request, this.context);
-        Mockito.verify(authScheme2, Mockito.times(1)).authenticate(this.credentials, request, this.context);
     }
 
     @Test
     public void testAuthSuccess() throws Exception {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         this.authState.setState(AuthProtocolState.SUCCESS);
-        this.authState.update(this.authScheme, this.credentials);
+        this.authState.update(this.authScheme);
 
         Mockito.when(this.authScheme.isConnectionBased()).thenReturn(Boolean.FALSE);
-        Mockito.when(this.authScheme.authenticate(
-                Mockito.any(Credentials.class),
+        Mockito.when(this.authScheme.generateAuthResponse(
+                Mockito.eq(defaultHost),
                 Mockito.any(HttpRequest.class),
-                Mockito.any(HttpContext.class))).thenReturn(new BasicHeader(HttpHeaders.AUTHORIZATION, "stuff"));
+                Mockito.any(HttpContext.class))).thenReturn("stuff");
 
-        this.httpAuthenticator.addAuthResponse(request, authState, context);
+        this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authState, context);
 
         Assert.assertSame(this.authScheme, this.authState.getAuthScheme());
-        Assert.assertSame(this.credentials, this.authState.getCredentials());
         Assert.assertNull(this.authState.getAuthOptions());
 
         Assert.assertTrue(request.containsHeader(HttpHeaders.AUTHORIZATION));
-
-        Mockito.verify(this.authScheme).authenticate(this.credentials, request, this.context);
     }
 
     @Test
     public void testAuthSuccessConnectionBased() throws Exception {
         final HttpRequest request = new BasicHttpRequest("GET", "/");
         this.authState.setState(AuthProtocolState.SUCCESS);
-        this.authState.update(this.authScheme, this.credentials);
+        this.authState.update(this.authScheme);
 
         Mockito.when(this.authScheme.isConnectionBased()).thenReturn(Boolean.TRUE);
-        Mockito.when(this.authScheme.authenticate(
-                Mockito.any(Credentials.class),
+        Mockito.when(this.authScheme.generateAuthResponse(
+                Mockito.eq(defaultHost),
                 Mockito.any(HttpRequest.class),
-                Mockito.any(HttpContext.class))).thenReturn(new BasicHeader(HttpHeaders.AUTHORIZATION, "stuff"));
+                Mockito.any(HttpContext.class))).thenReturn("stuff");
 
-        this.httpAuthenticator.addAuthResponse(request, authState, context);
+        this.httpAuthenticator.addAuthResponse(defaultHost, ChallengeType.TARGET, request, authState, context);
 
         Assert.assertFalse(request.containsHeader(HttpHeaders.AUTHORIZATION));
 
-        Mockito.verify(this.authScheme, Mockito.never()).authenticate(
-                Mockito.any(Credentials.class),
+        Mockito.verify(this.authScheme, Mockito.never()).generateAuthResponse(
+                Mockito.eq(defaultHost),
                 Mockito.any(HttpRequest.class),
                 Mockito.any(HttpContext.class));
     }

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthentication.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthentication.java?rev=1692371&r1=1692370&r2=1692371&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthentication.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthentication.java Thu Jul 23 10:00:46 2015
@@ -588,14 +588,12 @@ public class TestClientAuthentication ex
 
         final HttpHost target = start();
 
+        final BasicScheme basicScheme = new BasicScheme();
+        basicScheme.initPreemptive(new UsernamePasswordCredentials("test", "test"));
         final HttpClientContext context = HttpClientContext.create();
         final AuthCache authCache = new BasicAuthCache();
-        authCache.put(target, new BasicScheme());
+        authCache.put(target, basicScheme);
         context.setAuthCache(authCache);
-        final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
-        credsProvider.setCredentials(AuthScope.ANY,
-                new UsernamePasswordCredentials("test", "test"));
-        context.setCredentialsProvider(credsProvider);
 
         final HttpGet httpget = new HttpGet("/");
         final HttpResponse response1 = this.httpclient.execute(target, httpget, context);

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientReauthentication.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientReauthentication.java?rev=1692371&r1=1692370&r2=1692371&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientReauthentication.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientReauthentication.java Thu Jul 23 10:00:46 2015
@@ -153,7 +153,7 @@ public class TestClientReauthentication
                     private static final long serialVersionUID = 1L;
 
                     @Override
-                    public String getSchemeName() {
+                    public String getName() {
                         return "MyBasic";
                     }
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestMainClientExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestMainClientExec.java?rev=1692371&r1=1692370&r2=1692371&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestMainClientExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestMainClientExec.java Thu Jul 23 10:00:46 2015
@@ -51,7 +51,6 @@ import org.apache.http.auth.AuthScheme;
 import org.apache.http.auth.AuthScope;
 import org.apache.http.auth.AuthState;
 import org.apache.http.auth.ChallengeType;
-import org.apache.http.auth.NTCredentials;
 import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.http.client.AuthenticationStrategy;
 import org.apache.http.client.NonRepeatableRequestException;
@@ -442,7 +441,7 @@ public class TestMainClientExec {
 
         final AuthState proxyAuthState = new AuthState();
         proxyAuthState.setState(AuthProtocolState.SUCCESS);
-        proxyAuthState.update(new NTLMScheme(), new NTCredentials("user:pass"));
+        proxyAuthState.update(new NTLMScheme());
 
         final HttpClientContext context = new HttpClientContext();
         context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, proxyAuthState);
@@ -475,7 +474,6 @@ public class TestMainClientExec {
         Assert.assertNotNull(finalResponse);
         Assert.assertEquals(200, finalResponse.getStatusLine().getStatusCode());
         Assert.assertNull(proxyAuthState.getAuthScheme());
-        Assert.assertNull(proxyAuthState.getCredentials());
     }
 
     @Test(expected = NonRepeatableRequestException.class)

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestRedirectExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestRedirectExec.java?rev=1692371&r1=1692370&r2=1692371&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestRedirectExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestRedirectExec.java Thu Jul 23 10:00:46 2015
@@ -26,6 +26,10 @@
  */
 package org.apache.http.impl.execchain;
 
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.List;
+
 import org.apache.http.Header;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpException;
@@ -35,8 +39,6 @@ import org.apache.http.HttpResponse;
 import org.apache.http.ProtocolException;
 import org.apache.http.auth.AuthProtocolState;
 import org.apache.http.auth.AuthState;
-import org.apache.http.auth.NTCredentials;
-import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.http.client.RedirectException;
 import org.apache.http.client.RedirectStrategy;
 import org.apache.http.client.config.RequestConfig;
@@ -60,10 +62,6 @@ import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
 
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.util.List;
-
 @SuppressWarnings({"boxing","static-access"}) // test code
 public class TestRedirectExec {
 
@@ -240,10 +238,10 @@ public class TestRedirectExec {
 
         final AuthState targetAuthState = new AuthState();
         targetAuthState.setState(AuthProtocolState.SUCCESS);
-        targetAuthState.update(new BasicScheme(), new UsernamePasswordCredentials("user:pass"));
+        targetAuthState.update(new BasicScheme());
         final AuthState proxyAuthState = new AuthState();
         proxyAuthState.setState(AuthProtocolState.SUCCESS);
-        proxyAuthState.update(new NTLMScheme(), new NTCredentials("user:pass"));
+        proxyAuthState.update(new NTLMScheme());
         context.setAttribute(HttpClientContext.TARGET_AUTH_STATE, targetAuthState);
         context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, proxyAuthState);
 

Modified: httpcomponents/httpclient/trunk/src/docbkx/connmgmt.xml
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/src/docbkx/connmgmt.xml?rev=1692371&r1=1692370&r2=1692371&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/src/docbkx/connmgmt.xml (original)
+++ httpcomponents/httpclient/trunk/src/docbkx/connmgmt.xml Thu Jul 23 10:00:46 2015
@@ -546,7 +546,7 @@ HttpRoutePlanner routePlanner = new Http
             HttpRequest request,
             HttpContext context) throws HttpException {
         return new HttpRoute(target, null,  new HttpHost("someproxy", 8080),
-                "https".equalsIgnoreCase(target.getSchemeName()));
+                "https".equalsIgnoreCase(target.getName()));
     }
 
 };



Mime
View raw message