Search in sources :

Example 26 with Cookie

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

the class TestCookieCompatibilitySpec method testSecurityError.

public void testSecurityError() throws Exception {
    String headerValue = "custno=12345;comment=test; version=1," + "name=John;version=1;max-age=600;secure;domain=jakarta.apache.org";
    Header header = new Header("set-cookie", headerValue);
    CookieSpec cookiespec = new CookieSpecBase();
    try {
        Cookie[] cookies = cookieParse(cookiespec, "www.apache.org", 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)

Example 27 with Cookie

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

the class TestCookieCompatibilitySpec method testFormatOneCookie.

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

Example 28 with Cookie

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

the class TestCookieCompatibilitySpec method testValidateInvalidCookieVersion.

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

Example 29 with Cookie

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

the class TestCookieCompatibilitySpec method testCookieWithComma.

/**
 * Tests if malformatted expires attribute is parsed correctly.
 */
public void testCookieWithComma() throws Exception {
    Header header = new Header("Set-Cookie", "name=value; expires=\"Thu, 01-Jan-1970 00:00:00 GMT");
    CookieSpec cookiespec = new CookieSpecBase();
    try {
        Cookie[] cookies = cookiespec.parse("localhost", 80, "/", false, header);
        fail("MalformedCookieException should have been thrown");
    } catch (MalformedCookieException expected) {
    }
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) Header(org.apache.commons.httpclient.Header)

Example 30 with Cookie

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

the class TestCookieCompatibilitySpec method testParse2.

/**
 * Test no spaces
 */
public void testParse2() throws Exception {
    String headerValue = "custno=12345;comment=test; version=1," + "name=John;version=1;max-age=600;secure;domain=.apache.org";
    Header header = new Header("set-cookie", headerValue);
    CookieSpec cookiespec = new CookieSpecBase();
    Cookie[] cookies = cookieParse(cookiespec, "www.apache.org", 80, "/", false, header);
    assertEquals(2, cookies.length);
    assertEquals("custno", cookies[0].getName());
    assertEquals("12345", cookies[0].getValue());
    assertEquals("test", cookies[0].getComment());
    assertEquals(0, cookies[0].getVersion());
    assertEquals("www.apache.org", cookies[0].getDomain());
    assertEquals("/", cookies[0].getPath());
    assertFalse(cookies[0].getSecure());
    assertEquals("name", cookies[1].getName());
    assertEquals("John", cookies[1].getValue());
    assertEquals(null, cookies[1].getComment());
    assertEquals(0, cookies[1].getVersion());
    assertEquals(".apache.org", cookies[1].getDomain());
    assertEquals("/", cookies[1].getPath());
    assertTrue(cookies[1].getSecure());
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) Header(org.apache.commons.httpclient.Header)

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