Search in sources :

Example 31 with Cookie

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

the class TestCookieCompatibilitySpec method testParseWithComment.

public void testParseWithComment() throws Exception {
    Header header = new Header("Set-Cookie", "cookie-name=cookie-value; comment=\"This is a comment.\"");
    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());
    assertTrue("ExpiryDate", null == parsed[0].getExpiryDate());
    assertEquals("Comment", "This is a comment.", parsed[0].getComment());
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) Header(org.apache.commons.httpclient.Header)

Example 32 with Cookie

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

the class TestCookieCompatibilitySpec method testParseWithWhiteSpace.

public void testParseWithWhiteSpace() 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, "/", false, 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());
    assertTrue("ExpiryDate", null == parsed[0].getExpiryDate());
    assertTrue("Comment", null == parsed[0].getComment());
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) Header(org.apache.commons.httpclient.Header)

Example 33 with Cookie

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

the class TestCookieCompatibilitySpec method testMatchNullCookieDomain.

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

Example 34 with Cookie

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

the class TestCookieCompatibilitySpec method testValidateInvalidPort.

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

Example 35 with Cookie

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

the class TestCookieCompatibilitySpec method testParseMultipleSamePaths.

public void testParseMultipleSamePaths() throws Exception {
    Header header = new Header("Set-Cookie", "name1=value1;Version=1;Path=/commons,name1=value2;Version=1;Path=/commons");
    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("Found 1 cookies.", 1, cookies.length);
    assertEquals("Name", "name1", cookies[0].getName());
    assertEquals("Value", "value2", cookies[0].getValue());
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) Header(org.apache.commons.httpclient.Header) HttpState(org.apache.commons.httpclient.HttpState)

Aggregations

Cookie (org.apache.commons.httpclient.Cookie)140 Header (org.apache.commons.httpclient.Header)69 NameValuePair (org.apache.commons.httpclient.NameValuePair)13 HttpState (org.apache.commons.httpclient.HttpState)11 HttpClient (org.apache.commons.httpclient.HttpClient)8 CookieSpec (org.apache.commons.httpclient.cookie.CookieSpec)8 Test (org.junit.jupiter.api.Test)8 GetMethod (org.apache.commons.httpclient.methods.GetMethod)6 ZMailbox (com.zimbra.client.ZMailbox)4 IOException (java.io.IOException)4 URI (java.net.URI)4 HashMap (java.util.HashMap)4 HttpException (org.apache.commons.httpclient.HttpException)4 Test (org.junit.Test)4 ZimbraCookie (com.zimbra.common.util.ZimbraCookie)3 Account (com.zimbra.cs.account.Account)3 Map (java.util.Map)3 URI (org.apache.commons.httpclient.URI)3 ApiException (org.zaproxy.zap.extension.api.ApiException)3 ZAuthToken (com.zimbra.common.auth.ZAuthToken)2