Menu

#94 setProxyAuthorization causes IllegalArgumentException

Release_1.5
closed-fixed
Core API (28)
5
2008-04-14
2007-12-30
Snam
No

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.

Discussion

  • Julien HENRY

    Julien HENRY - 2008-04-14

    Logged In: YES
    user_id=1235926
    Originator: NO

    This part of the JWebUnit code is really ugly and dependant on underlying testing engine (here HtmlUnit). I should definitely distinguish proxy configuration and proxy authentication.

    But for now I will use your solution thanks.

     
  • Julien HENRY

    Julien HENRY - 2008-04-14
    • assigned_to: nobody --> henryju
    • status: open --> closed-fixed
     

Log in to post a comment.