Search in sources :

Example 81 with Cookie

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

the class TestCookieCompatibilitySpec method testParseWithExpires.

public void testParseWithExpires() throws Exception {
    Header header = new Header("Set-Cookie", "cookie-name=cookie-value;Expires=Thu, 01-Jan-1970 00:00:10 GMT");
    CookieSpec cookiespec = new CookieSpecBase();
    Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", 80, "/", true, header);
    assertEquals("Found 1 cookie.", 1, parsed.length);
    assertEquals("Name", "cookie-name", parsed[0].getName());
    assertEquals("Value", "cookie-value", parsed[0].getValue());
    assertEquals("Domain", "127.0.0.1", parsed[0].getDomain());
    assertEquals("Path", "/", parsed[0].getPath());
    assertTrue("Secure", !parsed[0].getSecure());
    assertEquals(new Date(10000L), parsed[0].getExpiryDate());
    assertTrue("Comment", null == parsed[0].getComment());
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) Header(org.apache.commons.httpclient.Header) Date(java.util.Date)

Example 82 with Cookie

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

the class TestCookieCompatibilitySpec method testMatchNullHost.

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

Example 83 with Cookie

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

the class TestCookieCompatibilitySpec method testCookieMatch3.

public void testCookieMatch3() throws Exception {
    CookieSpec cookiespec = new CookieSpecBase();
    Cookie cookie = new Cookie(".whatever.com", "name", "value", "/", null, false);
    assertTrue(cookiespec.match(".really.whatever.com", 80, "/", false, cookie));
}
Also used : Cookie(org.apache.commons.httpclient.Cookie)

Example 84 with Cookie

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

the class TestCookieCompatibilitySpec method testParseSimple.

public void testParseSimple() throws Exception {
    Header header = new Header("Set-Cookie", "cookie-name=cookie-value");
    CookieSpec cookiespec = new CookieSpecBase();
    Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", 80, "/path/path", false, header);
    assertEquals("Found 1 cookie.", 1, parsed.length);
    assertEquals("Name", "cookie-name", parsed[0].getName());
    assertEquals("Value", "cookie-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", "/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 85 with Cookie

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

the class TestCookieCompatibilitySpec method testParseWithBlankHost.

public void testParseWithBlankHost() throws Exception {
    Header header = new Header("Set-Cookie", "cookie-name=cookie-value; domain=127.0.0.1; path=/; secure");
    CookieSpec cookiespec = new CookieSpecBase();
    try {
        Cookie[] parsed = cookieParse(cookiespec, "  ", 80, "/", false, header);
        fail("IllegalArgumentException should have been thrown");
    } catch (IllegalArgumentException e) {
    // expected
    }
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) Header(org.apache.commons.httpclient.Header)

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