Search in sources :

Example 51 with Cookie

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

the class TestCookieRFC2109Spec method testParseDomainEqualsHost.

/**
 * Test domain equals host
 */
public void testParseDomainEqualsHost() throws Exception {
    Header header = new Header("Set-Cookie", "cookie-name=cookie-value; domain=www.b.com; version=1");
    CookieSpec cookiespec = new RFC2109Spec();
    Cookie[] parsed = cookieParse(cookiespec, "www.b.com", 80, "/", false, header);
    assertNotNull(parsed);
    assertEquals(1, parsed.length);
    assertEquals("www.b.com", parsed[0].getDomain());
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) Header(org.apache.commons.httpclient.Header)

Example 52 with Cookie

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

the class TestCookieRFC2109Spec method testParseAttributeNullPath.

public void testParseAttributeNullPath() throws Exception {
    CookieSpec cookiespec = new RFC2109Spec();
    try {
        Cookie cookie = new Cookie();
        cookiespec.parseAttribute(new NameValuePair("path", null), cookie);
        fail("MalformedCookieException must have been thrown");
    } catch (MalformedCookieException expected) {
    }
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) NameValuePair(org.apache.commons.httpclient.NameValuePair)

Example 53 with Cookie

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

the class TestCookieRFC2109Spec method testSecondDomainLevelCookieMatch.

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

Example 54 with Cookie

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

the class TestCookieRFC2109Spec method testNullCookieValueFormatting.

/**
 * Tests if null cookie values are handled correctly.
 */
public void testNullCookieValueFormatting() {
    Cookie cookie = new Cookie(".whatever.com", "name", null, "/", null, false);
    cookie.setDomainAttributeSpecified(true);
    cookie.setPathAttributeSpecified(true);
    CookieSpec cookiespec = new RFC2109Spec();
    String s = cookiespec.formatCookie(cookie);
    assertEquals("$Version=0; name=; $Path=/; $Domain=.whatever.com", s);
    cookie.setVersion(1);
    s = cookiespec.formatCookie(cookie);
    assertEquals("$Version=\"1\"; name=\"\"; $Path=\"/\"; $Domain=\".whatever.com\"", s);
}
Also used : Cookie(org.apache.commons.httpclient.Cookie)

Example 55 with Cookie

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

the class TestCookieRFC2109Spec method testParseWithIllegalDomain1.

/**
 * Domain does not start with a dot
 */
public void testParseWithIllegalDomain1() throws Exception {
    Header header = new Header("Set-Cookie", "cookie-name=cookie-value; domain=a.b.com; version=1");
    CookieSpec cookiespec = new RFC2109Spec();
    try {
        Cookie[] parsed = cookieParse(cookiespec, "www.a.b.com", 80, "/", false, header);
        fail("MalformedCookieException should have been thrown");
    } catch (MalformedCookieException 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