Search in sources :

Example 46 with Cookie

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

the class TestCookieNetscapeDraft method testParseWithNegativePort.

public void testParseWithNegativePort() throws Exception {
    Header header = new Header("Set-Cookie", "cookie-name=cookie-value; domain=127.0.0.1; path=/; secure");
    CookieSpec cookiespec = new NetscapeDraftSpec();
    try {
        Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", -80, null, false, header);
        fail("IllegalArgumentException should have been thrown");
    } catch (IllegalArgumentException e) {
    // expected
    }
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) Header(org.apache.commons.httpclient.Header)

Example 47 with Cookie

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

the class TestCookieNetscapeDraft method testParseWithNullHost.

public void testParseWithNullHost() throws Exception {
    Header header = new Header("Set-Cookie", "cookie-name=cookie-value; domain=127.0.0.1; path=/; secure");
    CookieSpec cookiespec = new NetscapeDraftSpec();
    try {
        Cookie[] parsed = cookieParse(cookiespec, null, 80, "/", false, header);
        fail("IllegalArgumentException should have been thrown");
    } catch (IllegalArgumentException e) {
    // expected
    }
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) Header(org.apache.commons.httpclient.Header)

Example 48 with Cookie

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

the class TestCookieNetscapeDraft method testNetscapeCookieFormatting.

/**
 * Tests Netscape specific cookie formatting.
 */
public void testNetscapeCookieFormatting() throws Exception {
    Header header = new Header("Set-Cookie", "name=value; path=/; domain=.mydomain.com");
    CookieSpec cookiespec = new NetscapeDraftSpec();
    Cookie[] cookies = cookiespec.parse("myhost.mydomain.com", 80, "/", false, header);
    cookiespec.validate("myhost.mydomain.com", 80, "/", false, cookies[0]);
    String s = cookiespec.formatCookie(cookies[0]);
    assertEquals("name=value", s);
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) Header(org.apache.commons.httpclient.Header)

Example 49 with Cookie

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

the class TestCookieNetscapeDraft method testParseRelativePath.

public void testParseRelativePath() throws Exception {
    Header header = new Header("Set-Cookie", "name1=value1;Path=whatever");
    CookieSpec cookiespec = new NetscapeDraftSpec();
    Cookie[] parsed = cookieParse(cookiespec, "host", 80, "whatever", true, header);
    assertEquals("Found 1 cookies.", 1, parsed.length);
    assertEquals("Name", "name1", parsed[0].getName());
    assertEquals("Value", "value1", parsed[0].getValue());
    assertEquals("Domain", "host", parsed[0].getDomain());
    assertEquals("Path", "whatever", parsed[0].getPath());
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) Header(org.apache.commons.httpclient.Header)

Example 50 with Cookie

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

the class TestCookieNetscapeDraft method testNetscapeCookieExpireAttribute.

/**
 * Tests Netscape specific expire attribute parsing.
 */
public void testNetscapeCookieExpireAttribute() throws Exception {
    CookieSpec cookiespec = new NetscapeDraftSpec();
    Header header = new Header("Set-Cookie", "name=value; path=/; domain=.mydomain.com; expires=Thu, 01-Jan-2070 00:00:10 GMT; comment=no_comment");
    Cookie[] cookies = cookiespec.parse("myhost.mydomain.com", 80, "/", false, header);
    cookiespec.validate("myhost.mydomain.com", 80, "/", false, cookies[0]);
    header = new Header("Set-Cookie", "name=value; path=/; domain=.mydomain.com; expires=Thu 01-Jan-2070 00:00:10 GMT; comment=no_comment");
    try {
        cookies = cookiespec.parse("myhost.mydomain.com", 80, "/", false, header);
        cookiespec.validate("myhost.mydomain.com", 80, "/", false, cookies[0]);
        fail("MalformedCookieException must have been thrown");
    } catch (MalformedCookieException expected) {
    }
}
Also used : Cookie(org.apache.commons.httpclient.Cookie) Header(org.apache.commons.httpclient.Header)

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