Search in sources :

Example 91 with Cookie

use of org.apache.commons.httpclient.Cookie in project ecf by eclipse.

the class TestCookieCompatibilitySpec method testParseNoValue.

public void testParseNoValue() throws Exception {
    Header header = new Header("Set-Cookie", "cookie-name=");
    CookieSpec cookiespec = new CookieSpecBase();
    Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", 80, "/", false, header);
    assertEquals("Found 1 cookie.", 1, parsed.length);
    assertEquals("Name", "cookie-name", parsed[0].getName());
    assertEquals("Value", "", parsed[0].getValue());
    assertTrue("Comment", null == parsed[0].getComment());
    assertTrue("ExpiryDate", null == parsed[0].getExpiryDate());
    // assertTrue("isToBeDiscarded",parsed[0].isToBeDiscarded());
    assertTrue("isPersistent", !parsed[0].isPersistent());
    assertEquals("Domain", "127.0.0.1", parsed[0].getDomain());
    assertEquals("Path", "/", parsed[0].getPath());
    assertTrue("Secure", !parsed[0].getSecure());
    assertEquals("Version", 0, parsed[0].getVersion());
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) Header(org.apache.commons.httpclient.Header)

Example 92 with Cookie

use of org.apache.commons.httpclient.Cookie in project ecf by eclipse.

the class TestCookieCompatibilitySpec method testSecondDomainLevelCookieMatch1.

public void testSecondDomainLevelCookieMatch1() throws Exception {
    Cookie cookie = new Cookie(".sourceforge.net", "name", null, "/", null, false);
    cookie.setDomainAttributeSpecified(true);
    cookie.setPathAttributeSpecified(true);
    CookieSpec cookiespec = new CookieSpecBase();
    assertTrue(cookiespec.match("sourceforge.net", 80, "/", false, cookie));
}
Also used : Cookie(org.apache.commons.httpclient.Cookie)

Example 93 with Cookie

use of org.apache.commons.httpclient.Cookie in project ecf by eclipse.

the class TestCookieCompatibilitySpec method testMatchInvalidPort.

public void testMatchInvalidPort() throws Exception {
    CookieSpec cookiespec = new CookieSpecBase();
    Cookie cookie = new Cookie();
    try {
        cookiespec.match("host", -80, "/", false, cookie);
        fail("IllegalArgumentException must have been thrown");
    } catch (IllegalArgumentException expected) {
    }
}
Also used : Cookie(org.apache.commons.httpclient.Cookie)

Example 94 with Cookie

use of org.apache.commons.httpclient.Cookie in project ecf by eclipse.

the class TestCookieCompatibilitySpec method testGenericCookieFormatting.

/**
 * Tests generic cookie formatting.
 */
public void testGenericCookieFormatting() throws Exception {
    Header header = new Header("Set-Cookie", "name=value; path=/; domain=.mydomain.com");
    CookieSpec cookiespec = new CookieSpecBase();
    Cookie[] cookies = cookiespec.parse("myhost.mydomain.com", 80, "/", false, header);
    cookiespec.validate("myhost.mydomain.com", 80, "/", false, cookies[0]);
    String s = cookiespec.formatCookie(cookies[0]);
    assertEquals("name=value", s);
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) Header(org.apache.commons.httpclient.Header)

Example 95 with Cookie

use of org.apache.commons.httpclient.Cookie in project ecf by eclipse.

the class TestCookieCompatibilitySpec method testMatchNullPath.

public void testMatchNullPath() throws Exception {
    CookieSpec cookiespec = new CookieSpecBase();
    Cookie cookie = new Cookie();
    try {
        cookiespec.match("host", 80, null, false, cookie);
        fail("IllegalArgumentException must have been thrown");
    } catch (IllegalArgumentException expected) {
    }
}
Also used : Cookie(org.apache.commons.httpclient.Cookie)

Aggregations

Cookie (org.apache.commons.httpclient.Cookie)136 Header (org.apache.commons.httpclient.Header)69 NameValuePair (org.apache.commons.httpclient.NameValuePair)13 CookieSpec (org.apache.commons.httpclient.cookie.CookieSpec)8 Test (org.junit.jupiter.api.Test)8 HttpState (org.apache.commons.httpclient.HttpState)5 HashMap (java.util.HashMap)4 HttpException (org.apache.commons.httpclient.HttpException)4 URI (org.apache.commons.httpclient.URI)3 ApiException (org.zaproxy.zap.extension.api.ApiException)3 ZimbraCookie (com.zimbra.common.util.ZimbraCookie)2 IOException (java.io.IOException)2 Date (java.util.Date)2 StringTokenizer (java.util.StringTokenizer)2 JSONException (net.sf.json.JSONException)2 JSONObject (net.sf.json.JSONObject)2 HttpClient (org.apache.commons.httpclient.HttpClient)2 URIException (org.apache.commons.httpclient.URIException)2 WSSecurityException (com.ibm.websphere.security.WSSecurityException)1 CredentialDestroyedException (com.ibm.websphere.security.auth.CredentialDestroyedException)1