Search in sources :

Example 36 with Cookie

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

the class TestCookieCompatibilitySpec method testParseWithAll.

public void testParseWithAll() throws Exception {
    Header header = new Header("Set-Cookie", "cookie-name=cookie-value;Version=1;Path=/commons;Domain=.apache.org;" + "Comment=This is a comment.;secure;Expires=Thu, 01-Jan-1970 00:00:10 GMT");
    CookieSpec cookiespec = new CookieSpecBase();
    Cookie[] parsed = cookieParse(cookiespec, ".apache.org", 80, "/commons/httpclient", 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", ".apache.org", parsed[0].getDomain());
    assertEquals("Path", "/commons", parsed[0].getPath());
    assertTrue("Secure", parsed[0].getSecure());
    assertEquals(new Date(10000L), parsed[0].getExpiryDate());
    assertEquals("Comment", "This is a comment.", parsed[0].getComment());
    assertEquals("Version", 0, parsed[0].getVersion());
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) Header(org.apache.commons.httpclient.Header) Date(java.util.Date)

Example 37 with Cookie

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

the class TestCookieCompatibilitySpec method testParseWithQuotes.

public void testParseWithQuotes() throws Exception {
    Header header = new Header("Set-Cookie", " cookie-name  =  \" cookie-value \" ;path=/");
    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 38 with Cookie

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

the class TestCookieCompatibilitySpec method testGenericCookieFormattingAsHeader.

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

Example 39 with Cookie

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

the class TestCookieCompatibilitySpec method testParseAttributeBlankPath.

public void testParseAttributeBlankPath() throws Exception {
    CookieSpec cookiespec = new CookieSpecBase();
    Cookie cookie = new Cookie();
    cookiespec.parseAttribute(new NameValuePair("path", "   "), cookie);
    assertEquals("/", cookie.getPath());
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) NameValuePair(org.apache.commons.httpclient.NameValuePair)

Example 40 with Cookie

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

the class TestCookieCompatibilitySpec method testParseWithSecure.

public void testParseWithSecure() throws Exception {
    Header header = new Header("Set-Cookie", "cookie-name=cookie-value; secure");
    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());
    assertTrue("Comment", null == parsed[0].getComment());
}
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