Search in sources :

Example 86 with Cookie

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

the class TestCookieCompatibilitySpec method testDomainCaseInsensitivity.

/**
 * Tests whether domain attribute check is case-insensitive.
 */
public void testDomainCaseInsensitivity() throws Exception {
    Header header = new Header("Set-Cookie", "name=value; path=/; domain=.whatever.com");
    CookieSpec cookiespec = new CookieSpecBase();
    Cookie[] parsed = cookieParse(cookiespec, "www.WhatEver.com", 80, "/", false, header);
    assertNotNull(parsed);
    assertEquals(1, parsed.length);
    assertEquals(".whatever.com", parsed[0].getDomain());
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) Header(org.apache.commons.httpclient.Header)

Example 87 with Cookie

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

the class TestCookieCompatibilitySpec method testValidateNullPath.

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

Example 88 with Cookie

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

the class TestCookieCompatibilitySpec method testParseMultipleDifferentPaths.

public void testParseMultipleDifferentPaths() throws Exception {
    Header header = new Header("Set-Cookie", "name1=value1;Version=1;Path=/commons,name1=value2;Version=1;" + "Path=/commons/httpclient;Version=1");
    CookieSpec cookiespec = new CookieSpecBase();
    Cookie[] parsed = cookieParse(cookiespec, ".apache.org", 80, "/commons/httpclient", true, header);
    HttpState state = new HttpState();
    state.addCookies(parsed);
    Cookie[] cookies = state.getCookies();
    assertEquals("Wrong number of cookies.", 2, cookies.length);
    assertEquals("Name", "name1", cookies[0].getName());
    assertEquals("Value", "value1", cookies[0].getValue());
    assertEquals("Name", "name1", cookies[1].getName());
    assertEquals("Value", "value2", cookies[1].getValue());
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) Header(org.apache.commons.httpclient.Header) HttpState(org.apache.commons.httpclient.HttpState)

Example 89 with Cookie

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

the class TestCookieCompatibilitySpec method testParseWithPathMismatch.

public void testParseWithPathMismatch() throws Exception {
    Header header = new Header("Set-Cookie", "cookie-name=cookie-value; path=/path/path/path");
    CookieSpec cookiespec = new CookieSpecBase();
    try {
        Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", 80, "/path", 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)

Example 90 with Cookie

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

the class TestCookieCompatibilitySpec method testParseAttributeNullExpires.

public void testParseAttributeNullExpires() throws Exception {
    CookieSpec cookiespec = new CookieSpecBase();
    Cookie cookie = new Cookie();
    try {
        cookiespec.parseAttribute(new NameValuePair("expires", 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)

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