You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ol...@apache.org on 2004/04/29 16:28:29 UTC

cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestAuthenticator.java

olegk       2004/04/29 07:28:29

  Modified:    httpclient/src/java/org/apache/commons/httpclient/auth
                        DigestScheme.java
               httpclient/src/test/org/apache/commons/httpclient
                        TestAuthenticator.java
  Log:
  PR #24869 (DigestScheme.authenticate returns invalid authorization string when algorithm is null)
  
  Contributed by Oleg Kalnichevski
  
  Revision  Changes    Path
  1.20      +6 -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.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- DigestScheme.java	18 Apr 2004 23:51:36 -0000	1.19
  +++ DigestScheme.java	29 Apr 2004 14:28:29 -0000	1.20
  @@ -153,6 +153,9 @@
         throws MalformedChallengeException {
           super.processChallenge(challenge);
           
  +        if (getParameter("realm") == null) {
  +            throw new MalformedChallengeException("missing realm in challange");
  +        }
           if (getParameter("nonce") == null) {
               throw new MalformedChallengeException("missing nonce in challange");   
           }
  
  
  
  1.42      +14 -20    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.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- TestAuthenticator.java	27 Feb 2004 19:01:33 -0000	1.41
  +++ TestAuthenticator.java	29 Apr 2004 14:28:29 -0000	1.42
  @@ -169,44 +169,38 @@
   
       // --------------------------------- Test Methods for DigestScheme Authentication
   
  -    public void testDigestAuthenticationWithNoCreds() {
  -        String challenge = "Digest realm=\"realm1\"";
  +    public void testDigestAuthenticationWithNoCreds() throws Exception {
  +        String challenge = "Digest realm=\"realm1\", nonce=\"ABC123\"";
           HttpState state = new HttpState();
           HttpMethod method = new SimpleHttpMethod(new Header("WWW-Authenticate", challenge));
           try {
               AuthScheme authscheme = new DigestScheme();
               authscheme.processChallenge(challenge);
               authenticate(authscheme, method, null, state);
  -            fail("Should have thrown HttpException");
  -        } catch(HttpException e) {
  +            fail("Should have thrown CredentialsNotAvailableException");
  +        } catch(CredentialsNotAvailableException e) {
               // expected
           }
       }
   
  -    public void testDigestAuthenticationWithNoRealm() {
  +    public void testDigestAuthenticationWithNoRealm() throws Exception {
           String challenge = "Digest";
  -        HttpState state = new HttpState();
  -        HttpMethod method = new SimpleHttpMethod(new Header("WWW-Authenticate", challenge));
           try {
               AuthScheme authscheme = new DigestScheme();
               authscheme.processChallenge(challenge);
  -            authenticate(authscheme, method, null, state);
  -            fail("Should have thrown HttpException");
  -        } catch(HttpException e) {
  +            fail("Should have thrown MalformedChallengeException");
  +        } catch(MalformedChallengeException e) {
               // expected
           }
       }
   
  -    public void testDigestAuthenticationWithNoRealm2() {
  +    public void testDigestAuthenticationWithNoRealm2() throws Exception {
           String challenge = "Digest ";
  -        HttpState state = new HttpState();
  -        HttpMethod method = new SimpleHttpMethod(new Header("WWW-Authenticate", challenge));
           try {
               AuthScheme authscheme = new DigestScheme();
               authscheme.processChallenge(challenge);
  -            authenticate(authscheme, method, null, state);
  -            fail("Should have thrown HttpException");
  -        } catch(HttpException e) {
  +            fail("Should have thrown MalformedChallengeException");
  +        } catch(MalformedChallengeException e) {
               // expected
           }
       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org