commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jeri...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestAuthenticator.java
Date Wed, 23 Oct 2002 16:29:41 GMT
jericho     2002/10/23 09:29:40

  Modified:    httpclient/src/test/org/apache/commons/httpclient
                        TestAuthenticator.java
  Log:
  - Patched by Adrian Sutton
  
  His comment:
  This patch was added to the NTLM bug a while back but didn't seem to
  attract any attention so I'll hilight it again.  It applies cleanly both before
  and AFTER the patch I just sent to make NTLM non-static.
  
  Revision  Changes    Path
  1.18      +54 -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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- TestAuthenticator.java	30 Sep 2002 19:42:13 -0000	1.17
  +++ TestAuthenticator.java	23 Oct 2002 16:29:40 -0000	1.18
  @@ -374,7 +374,9 @@
   
       public void testNTLMAuthenticationWithNoCreds() {
           HttpState state = new HttpState();
  -        HttpMethod method = new SimpleHttpMethod(new Header("WWW-Authenticate","NTLM"));
  +        HttpMethod method = new SimpleHttpMethod(new Header("WWW-Authenticate",
  +                    "NTLM"));
  +        method.addRequestHeader("Host", "host");
           try {
               Authenticator.authenticate(method,state);
               fail("Should have thrown HttpException");
  @@ -384,7 +386,9 @@
       }
   
       public void testNTLMAuthenticationWithNullHttpState() throws Exception {
  -        HttpMethod method = new SimpleHttpMethod(new Header("WWW-Authenticate","NTLM"));
  +        HttpMethod method = new SimpleHttpMethod(new Header("WWW-Authenticate",
  +                    "NTLM"));
  +        method.addRequestHeader("Host", "host");
           try {
               Authenticator.authenticate(method,(HttpState)null);
               fail("Should have thrown NullPointerException");
  @@ -395,9 +399,12 @@
   
       public void testNTLMAuthenticationCaseInsensitivity() throws Exception {
           HttpState state = new HttpState();
  -        NTCredentials cred = new NTCredentials("username","password", "host", "domain");
  -        state.setCredentials(null, cred);
  -        HttpMethod method = new SimpleHttpMethod(new Header("WwW-AuThEnTiCaTe","nTlM"));
  +        NTCredentials cred = new NTCredentials("username","password", "host",
  +                "domain");
  +        state.setCredentials("host", cred);
  +        HttpMethod method = new SimpleHttpMethod(new Header("WwW-AuThEnTiCaTe",
  +                    "nTlM"));
  +        method.addRequestHeader("Host", "host");
           assertTrue(Authenticator.authenticate(method,state));
           assertTrue(null != method.getRequestHeader("Authorization"));
       }
  @@ -406,12 +413,16 @@
           String expected = "NTLM TlRMTVNTUAABAAAABlIAAAYABgAkAAAABAAEACAAAABIT" +
               "1NURE9NQUlO";
           HttpState state = new HttpState();
  -        NTCredentials cred = new NTCredentials("username","password", "host", "domain");
  -        state.setCredentials(null, cred);
  -        HttpMethod method = new SimpleHttpMethod(new Header("WWW-Authenticate","NTLM"));
  +        NTCredentials cred = new NTCredentials("username","password", "host",
  +                "domain");
  +        state.setCredentials("host", cred);
  +        HttpMethod method = new SimpleHttpMethod(new Header("WWW-Authenticate",
  +                    "NTLM"));
  +        method.addRequestHeader("Host", "host");
           assertTrue(Authenticator.authenticate(method,state));
           assertTrue(null != method.getRequestHeader("Authorization"));
  -        assertEquals(expected, method.getRequestHeader("Authorization").getValue());
  +        assertEquals(expected,
  +                method.getRequestHeader("Authorization").getValue());
       }
       
       public void testNTLMAuthenticationResponse2() throws Exception {
  @@ -419,7 +430,29 @@
               "AAAAACAAIAEYAAAAEAAQATgAAAAAAAABqAAAABlIAAERPTUFJTlVTRVJOQU1FSE" +
               "9TVAaC+vLxUEHnUtpItj9Dp4kzwQfd61Lztg==";
           HttpState state = new HttpState();
  -        NTCredentials cred = new NTCredentials("username","password", "host", "domain");
  +        NTCredentials cred = new NTCredentials("username","password", "host",
  +                "domain");
  +        state.setCredentials("host", cred);
  +        HttpMethod method = new SimpleHttpMethod(new Header("WWW-Authenticate",
  +            "NTLM TlRMTVNTUAACAAAACgAKADAAAAAGgoEAPc4kP4LtCV8AAAAAAAAAAJ4AngA" +
  +            "6AAAASU5UUkFFUEhPWAIAFABJAE4AVABSAEEARQBQAEgATwBYAAEAEgBCAE8AQQB" +
  +            "SAEQAUgBPAE8ATQAEACgAaQBuAHQAcgBhAGUAcABoAG8AeAAuAGUAcABoAG8AeAA" +
  +            "uAGMAbwBtAAMAPABCAG8AYQByAGQAcgBvAG8AbQAuAGkAbgB0AHIAYQBlAHAAaAB" +
  +            "vAHgALgBlAHAAaABvAHgALgBjAG8AbQAAAAAA"));
  +        method.addRequestHeader("Host", "host");
  +        assertTrue(Authenticator.authenticate(method,state));
  +        assertTrue(null != method.getRequestHeader("Authorization"));
  +        assertEquals(expected,
  +                method.getRequestHeader("Authorization").getValue());
  +    }
  +    
  +    public void testNTLMAuthenticationWithDefaultCreds() throws Exception {
  +        String expected = "NTLM TlRMTVNTUAADAAAAGAAYAFIAAAAAAAAAagAAAAYABgB" +
  +            "AAAAACAAIAEYAAAAEAAQATgAAAAAAAABqAAAABlIAAERPTUFJTlVTRVJOQU1FSE" +
  +            "9TVAaC+vLxUEHnUtpItj9Dp4kzwQfd61Lztg==";
  +        HttpState state = new HttpState();
  +        NTCredentials cred = new NTCredentials("username","password", "host",
  +                "domain");
           state.setCredentials(null, cred);
           HttpMethod method = new SimpleHttpMethod(new Header("WWW-Authenticate",
               "NTLM TlRMTVNTUAACAAAACgAKADAAAAAGgoEAPc4kP4LtCV8AAAAAAAAAAJ4AngA" +
  @@ -427,9 +460,11 @@
               "SAEQAUgBPAE8ATQAEACgAaQBuAHQAcgBhAGUAcABoAG8AeAAuAGUAcABoAG8AeAA" +
               "uAGMAbwBtAAMAPABCAG8AYQByAGQAcgBvAG8AbQAuAGkAbgB0AHIAYQBlAHAAaAB" +
               "vAHgALgBlAHAAaABvAHgALgBjAG8AbQAAAAAA"));
  +        method.addRequestHeader("Host", "host");
           assertTrue(Authenticator.authenticate(method,state));
           assertTrue(null != method.getRequestHeader("Authorization"));
  -        assertEquals(expected, method.getRequestHeader("Authorization").getValue());
  +        assertEquals(expected,
  +                method.getRequestHeader("Authorization").getValue());
       }
   
       /** 
  @@ -437,7 +472,8 @@
        */
       public void testDoAuthenticateFalse() throws Exception {
           HttpState state = new HttpState();
  -        state.setCredentials("Protected", new UsernamePasswordCredentials("name", "pass"));
  +        state.setCredentials("Protected",
  +                new UsernamePasswordCredentials("name", "pass"));
           HttpMethod method = new SimpleHttpMethod();
           method.setDoAuthentication(false);
           SimpleHttpConnection conn = new SimpleHttpConnection();
  @@ -445,13 +481,11 @@
               "HTTP/1.1 401 Unauthorized\r\n" + 
               "WWW-Authenticate: Basic realm=\"Protected\"\r\n" +
               "Connection: close\r\n" +
  -            "Server: HttpClient Test/2.0\r\n"
  -                );
  +            "Server: HttpClient Test/2.0\r\n");
           conn.addResponse( 
               "HTTP/1.1 200 OK\r\n" +
               "Connection: close\r\n" +
  -            "Server: HttpClient Test/2.0\r\n"
  -                ); 
  +            "Server: HttpClient Test/2.0\r\n"); 
           method.execute(state, conn);
           assertNotNull(method.getResponseHeader("WWW-Authenticate"));
           assertNull(method.getRequestHeader("Authorization"));
  
  
  

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


Mime
View raw message