Revision: 565
          http://svn.sourceforge.net/jwebunit/?rev=565&view=rev
Author:   henryju
Date:     2006-09-21 08:51:56 -0700 (Thu, 21 Sep 2006)

Log Message:
-----------
Begin to work on NTLM, Basic and Digest Authentication.

Modified Paths:
--------------
    
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/util/JettySetup.java
    trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/TestContext.java
    trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java

Modified: 
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/util/JettySetup.java
===================================================================
--- 
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/util/JettySetup.java
      2006-09-19 12:16:29 UTC (rev 564)
+++ 
trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/util/JettySetup.java
      2006-09-21 15:51:56 UTC (rev 565)
@@ -11,9 +11,12 @@
 import org.mortbay.jetty.MimeTypes;
 import org.mortbay.jetty.Server;
 import org.mortbay.jetty.bio.SocketConnector;
+import org.mortbay.jetty.security.SecurityHandler;
 import org.mortbay.jetty.webapp.WebAppContext;
 import org.mortbay.xml.XmlConfiguration;
 
+import sun.net.www.protocol.http.NTLMAuthSequence;
+
 import junit.extensions.TestSetup;
 import junit.framework.Test;
 
@@ -63,7 +66,10 @@
             wah.setContextPath(JWebUnitAPITestCase.JETTY_URL);
             URL url = this.getClass().getResource("/testcases/");
             wah.setWar(url.toString());
+//            SecurityHandler security = new SecurityHandler();
+//            wah.setSecurityHandler(security);
             jettyServer.addHandler(wah);
+            
             jettyServer.start();
         } catch (Exception e) {
             e.printStackTrace();

Modified: 
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/TestContext.java
===================================================================
--- trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/TestContext.java 
2006-09-19 12:16:29 UTC (rev 564)
+++ trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/TestContext.java 
2006-09-21 15:51:56 UTC (rev 565)
@@ -6,7 +6,6 @@
 
 import javax.servlet.http.Cookie;
 
-import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
@@ -17,14 +16,17 @@
  * the [EMAIL PROTECTED] net.sourceforge.jwebunit.WebTestCase}or
  * [EMAIL PROTECTED] net.sourceforge.jwebunit.WebTester}.
  * 
+ * @author Julien Henry
  * @author Wilkes Joiner
  * @author Jim Weaver
  */
 public class TestContext {
        private String user;
        private String passwd;
-       private List cookies;
-       private boolean hasAuth;
+    private String domain;
+       private List<Cookie> cookies;
+       private boolean hasBasicAuth = false;
+    private boolean hasNTLMAuth = false;
        private Locale locale = Locale.getDefault();
        private String resourceBundleName;
        private String baseUrl = "http://localhost:8080";;
@@ -36,13 +38,11 @@
         * Construct a test client context.
         */
        public TestContext() {
-               cookies = new ArrayList();
+               cookies = new ArrayList<Cookie>();
        }
 
        /**
-        * Set authentication information for the test context. This 
information is
-        * used by [EMAIL PROTECTED] HttpUnitDialog}to set authorization on the
-        * WebConversation when the dialog is begun.
+        * Set basic authentication information for the test context.
         * 
         * @param user
         *            user name
@@ -52,10 +52,25 @@
        public void setAuthorization(String user, String passwd) {
                this.user = user;
                this.passwd = passwd;
-               hasAuth = true;
+               hasBasicAuth = true;
        }
 
-       /**
+    /**
+     * Set NTLM authentication information for the test context.
+     * 
+     * @param user
+     *            user name
+     * @param passwd
+     *            password
+     */
+    public void setNTLMAuthorization(String user, String passwd, String 
domain) {
+        this.user = user;
+        this.passwd = passwd;
+        this.domain = domain;
+        hasNTLMAuth = true;
+    }
+
+    /**
         * Add a cookie to the test context. These cookies are set on the
         * WebConversation when an [EMAIL PROTECTED] HttpUnitDialog}is begun.
         * 
@@ -69,14 +84,22 @@
        }
 
        /**
-        * Return true if a user / password has been set on the context via
+        * Return true if a basic authentication has been set on the context via
         * [EMAIL PROTECTED] #setAuthorization}.
         */
        public boolean hasAuthorization() {
-               return hasAuth;
+               return hasBasicAuth;
        }
 
-       /**
+    /**
+     * Return true if a NTLM authentication has been set on the context via
+     * [EMAIL PROTECTED] #setNTLMAuthorization}.
+     */
+    public boolean hasNTLMAuthorization() {
+        return hasNTLMAuth;
+    }
+
+    /**
         * Return true if one or more cookies have been added to the test 
context.
         */
        public boolean hasCookies() {
@@ -96,6 +119,13 @@
        public String getPassword() {
                return passwd;
        }
+    
+    /**
+     * Return the user domain.
+     */
+    public String getDomain() {
+        return domain;
+    }
 
        /**
         * Return the cookies which have been added to the test context.

Modified: 
trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java
===================================================================
--- trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java   
2006-09-19 12:16:29 UTC (rev 564)
+++ trunk/jwebunit-core/src/main/java/net/sourceforge/jwebunit/WebTester.java   
2006-09-21 15:51:56 UTC (rev 565)
@@ -162,10 +162,13 @@
     }
 
     private String createUrl(String url) {
-        if (url.startsWith("http://";) || url.startsWith("https://";)
-                || url.startsWith("www.")) {
+        if (url.startsWith("http://";) || url.startsWith("https://";)) {
             return url;
-        } else {
+        } 
+        else if (url.startsWith("www.")) {
+            return "http://"; + url;
+        }
+        else {
             url = url.startsWith("/") ? url.substring(1) : url;
             return getTestContext().getBaseUrl() + url;
         }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jwebunit-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jwebunit-development

Reply via email to