commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mbe...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestAuthenticator.java
Date Mon, 08 Sep 2003 02:00:03 GMT
mbecke      2003/09/07 19:00:03

  Modified:    httpclient/src/java/org/apache/commons/httpclient/auth
                        DigestScheme.java
               httpclient/src/test/org/apache/commons/httpclient
                        TestAuthenticator.java
  Log:
  Adds support for stale digest nonce values.
  PR: 22655
  Submitted by: Michael Becke
  Reviewed by: Oleg Kalnichevski
  
  Revision  Changes    Path
  1.7       +19 -3     jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/DigestScheme.java
  
  Index: DigestScheme.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/DigestScheme.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DigestScheme.java	13 Aug 2003 19:57:10 -0000	1.6
  +++ DigestScheme.java	8 Sep 2003 02:00:03 -0000	1.7
  @@ -104,6 +104,22 @@
       };
   
       /**
  +     * Gets an ID based upon the realm and the nonce value.  This ensures that requests
  +     * to the same realm with different nonce values will succeed.  This differentiation
  +     * allows servers to request re-authentication using a fresh nonce value.
  +     */
  +    public String getID() {
  +        
  +        String id = getRealm();
  +        String nonce = getParameter("nonce");
  +        if (nonce != null) {
  +            id += "-" + nonce;
  +        }
  +        
  +        return id;
  +    }
  +
  +    /**
        * Constructor for the digest authentication scheme.
        * 
        * @param challenge The authentication challenge
  
  
  
  1.29      +38 -4     jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestAuthenticator.java
  
  Index: TestAuthenticator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestAuthenticator.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- TestAuthenticator.java	12 Aug 2003 02:35:17 -0000	1.28
  +++ TestAuthenticator.java	8 Sep 2003 02:00:03 -0000	1.29
  @@ -355,6 +355,40 @@
           checkAuthorization(cred, method.getName(), method.getRequestHeader("Authorization").getValue());
       }
   
  +    public void testDigestAuthenticationWithStaleNonce() throws Exception {
  +        
  +        String headers =
  +            "HTTP/1.1 401 OK\r\n" +
  +            "Connection: close\r\n" +
  +            "Content-Length: 0\r\n" +
  +            "WWW-Authenticate: Digest realm=\"realm1\", nonce=\"ABC123\"\r\n";
  +        String headers2 =
  +            "HTTP/1.1 401 OK\r\n" +
  +            "Connection: close\r\n" +
  +            "Content-Length: 0\r\n" +
  +            "WWW-Authenticate: Digest realm=\"realm1\", nonce=\"321CBA\", stale=\"true\"\r\n";
  +        String headers3 = 
  +            "HTTP/1.1 200 OK\r\n" +
  +            "Connection: close\r\n" +
  +            "Server: HttpClient Test/2.0\r\n\r\n" +
  +            "stuff\r\n";
  +        
  +        SimpleHttpConnection conn = new SimpleHttpConnection();
  +        
  +        conn.addResponse(headers);
  +        conn.addResponse(headers2);
  +        conn.addResponse(headers3);
  +        UsernamePasswordCredentials cred = new UsernamePasswordCredentials("username","password");
  +        client.getState().setCredentials(null, null, cred);
  +
  +        connectionManager.setConnection(conn);
  +
  +        SimpleHttpMethod method = new SimpleHttpMethod();
  +        method.setDoAuthentication(true);
  +        assertEquals("Authentication failed", 200, client.executeMethod(method));
  +        checkAuthorization(cred, method.getName(), method.getRequestHeader("Authorization").getValue());
  +    }
  +
       public void testDigestAuthenticationWithMultipleRealms() throws Exception {
           String challenge1 = "Digest realm=\"realm1\"";
           String challenge2 = "Digest realm=\"realm2\"";
  
  
  

Mime
View raw message