Search in sources :

Example 11 with Cookie

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

the class TestCookieCompatibilitySpec method testFormatSeveralCookiesAsHeader.

public void testFormatSeveralCookiesAsHeader() throws Exception {
    Header header = new Header("Set-Cookie", "name1=value1; path=/; domain=.mydomain.com, name2 = value2 ; path=/; domain=.mydomain.com");
    CookieSpec cookiespec = new CookieSpecBase();
    Cookie[] cookies = cookiespec.parse("myhost.mydomain.com", 80, "/", false, header);
    Header cookieheader = cookiespec.formatCookieHeader(cookies);
    assertEquals("name1=value1; name2=value2", cookieheader.getValue());
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) Header(org.apache.commons.httpclient.Header)

Example 12 with Cookie

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

the class TestCookieCompatibilitySpec method testCookieMismatch2.

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

Example 13 with Cookie

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

the class TestCookieCompatibilitySpec method testCookieNameWithBlanks.

/**
 * Tests if cookie constructor rejects cookie name containing blanks.
 */
public void testCookieNameWithBlanks() throws Exception {
    Header setcookie = new Header("Set-Cookie", "invalid name=");
    CookieSpec cookiespec = new CookieSpecBase();
    Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", 80, "/", false, setcookie);
    assertNotNull(parsed);
    assertEquals(1, parsed.length);
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) Header(org.apache.commons.httpclient.Header)

Example 14 with Cookie

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

the class TestCookieCompatibilitySpec method testParseWithDomain.

public void testParseWithDomain() throws Exception {
    Header header = new Header("Set-Cookie", "cookie-name=cookie-value; Domain=127.0.0.1");
    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 15 with Cookie

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

the class TestCookieCompatibilitySpec method testParseWithWrongDomain.

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

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