Bugs item #1860745, was opened at 2007-12-30 02:51
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=497982&aid=1860745&group_id=61302

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Core API
Group: Release 1.5
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Ward Bergmans (snamgreb)
Assigned to: Nobody/Anonymous (nobody)
Summary: setProxyAuthorization causes IllegalArgumentException

Initial Comment:
The javadoc of 
net.sourceforge.jwebunit.util.TestContext#setProxyAuthorization(String user, 
String passwd, String host, int port) says:
       Set proxy authentication information for the test context.
       
       user user name (null if none)
       passwd password (null if none)
       host proxy host name (null if applicable to any host).
       port proxy port (negative if applicable to any port).

So the javadoc says that the user and passwd must be null if there are none.
But when you do this: testContext.setProxyAuthorization(null, null, aProxyHost, 
aProxyPort)
and after that you call webTester.beginAt(aRelativeURL), then you get the 
following exception:

java.lang.IllegalArgumentException: Username may not be null
        at 
org.apache.commons.httpclient.UsernamePasswordCredentials.<init>(UsernamePasswordCredentials.java:89)
        at 
com.gargoylesoftware.htmlunit.DefaultCredentialsProvider.addProxyCredentials(DefaultCredentialsProvider.java:129)
        at 
net.sourceforge.jwebunit.htmlunit.HtmlUnitDialog.initWebClient(HtmlUnitDialog.java:661)
        at 
net.sourceforge.jwebunit.htmlunit.HtmlUnitDialog.beginAt(HtmlUnitDialog.java:159)
        at net.sourceforge.jwebunit.junit.WebTester.beginAt(WebTester.java:190)

A possible solution might be to change the 
net.sourceforge.jwebunit.util.TestContext#setProxyAuthorization(String user, 
String passwd, String host, int port) code to:
    public void setProxyAuthorization(String user, String passwd, String host, 
int port) {
        this.proxyUser = user;
        this.proxyPasswd = passwd;
        this.proxyHost = host;
        this.proxyPort = port;
        hasProxyAuth = !(null == user && null == passwd); // This is the 
improved line, the original code was: hasProxyAuth = true;
        //Maybe an extra flag needs to be added...???: hasProxy = true;
    }

This way the flag hasProxyAuth gets false when user and passwd are null, 
otherwise it gets true.
Another improvement might be to rename the method setProxyAuthorization to: 
setProxy.

I haven't tested this solution, because I couldn't set up an Eclipse workspace 
with JWebUnit quick enough. I hope my solution is helpful.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=497982&aid=1860745&group_id=61302

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
JWebUnit-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jwebunit-development

Reply via email to