use of org.apache.http.impl.cookie.BasicClientCookie in project jmeter by apache.
the class TestHC4CookieManager method testCookiePolicyNetscape.
@Test
public void testCookiePolicyNetscape() throws Exception {
man.setCookiePolicy(CookieSpecs.NETSCAPE);
// ensure policy is picked up
man.testStarted();
URL url = new URL("http://www.order.now/sub1/moo.html");
man.addCookieFromHeader("test1=moo1;", url);
man.addCookieFromHeader("test2=moo2;path=/sub1", url);
man.addCookieFromHeader("test2=moo3;path=/", url);
assertEquals(3, man.getCookieCount());
assertEquals("/sub1", man.get(0).getPath());
assertEquals("/sub1", man.get(1).getPath());
assertEquals("/", man.get(2).getPath());
String s = man.getCookieHeaderForURL(url);
assertNotNull(s);
HC4CookieHandler cookieHandler = (HC4CookieHandler) man.getCookieHandler();
List<org.apache.http.cookie.Cookie> c = cookieHandler.getCookiesForUrl(man.getCookies(), url, CookieManager.ALLOW_VARIABLE_COOKIES);
assertEquals("/sub1", c.get(0).getPath());
assertFalse(((BasicClientCookie) c.get(0)).containsAttribute(ClientCookie.PATH_ATTR));
assertEquals("/sub1", c.get(1).getPath());
assertTrue(((BasicClientCookie) c.get(1)).containsAttribute(ClientCookie.PATH_ATTR));
assertEquals("/", c.get(2).getPath());
assertTrue(((BasicClientCookie) c.get(2)).containsAttribute(ClientCookie.PATH_ATTR));
assertEquals("test1=moo1; test2=moo2; test2=moo3", s);
}
use of org.apache.http.impl.cookie.BasicClientCookie in project jmeter by apache.
the class TestHC4CookieManager method testAddCookieFromHeaderWithNoWildcard.
@Test
public void testAddCookieFromHeaderWithNoWildcard() throws Exception {
URL url = new URL("https://subdomain.bt.com/page");
String headerLine = "SMTRYNO=1; path=/";
man.addCookieFromHeader(headerLine, url);
Assert.assertEquals(1, man.getCookieCount());
HC4CookieHandler cookieHandler = (HC4CookieHandler) man.getCookieHandler();
List<org.apache.http.cookie.Cookie> cookies = cookieHandler.getCookiesForUrl(man.getCookies(), url, CookieManager.ALLOW_VARIABLE_COOKIES);
Assert.assertEquals(1, cookies.size());
for (org.apache.http.cookie.Cookie cookie : cookies) {
// See http://tools.ietf.org/html/rfc6265#section-5.2.3
Assert.assertEquals("subdomain.bt.com", cookie.getDomain());
Assert.assertFalse(((BasicClientCookie) cookie).containsAttribute(ClientCookie.DOMAIN_ATTR));
}
// we check that CookieManager returns the cookies for the main domain
URL urlMainDomain = new URL("https://www.bt.com/page");
cookies = cookieHandler.getCookiesForUrl(man.getCookies(), urlMainDomain, CookieManager.ALLOW_VARIABLE_COOKIES);
Assert.assertEquals(0, cookies.size());
}
use of org.apache.http.impl.cookie.BasicClientCookie in project jmeter by apache.
the class HC4CookieHandler method makeCookie.
/**
* Create an HttpClient cookie from a JMeter cookie
*/
@SuppressWarnings("JdkObsolete")
private org.apache.http.cookie.Cookie makeCookie(Cookie jmc) {
long exp = jmc.getExpiresMillis();
BasicClientCookie ret = new BasicClientCookie(jmc.getName(), jmc.getValue());
ret.setDomain(jmc.getDomain());
ret.setPath(jmc.getPath());
// use null for no expiry
ret.setExpiryDate(exp > 0 ? new Date(exp) : null);
ret.setSecure(jmc.getSecure());
ret.setVersion(jmc.getVersion());
if (jmc.isDomainSpecified()) {
ret.setAttribute(ClientCookie.DOMAIN_ATTR, jmc.getDomain());
}
if (jmc.isPathSpecified()) {
ret.setAttribute(ClientCookie.PATH_ATTR, jmc.getPath());
}
return ret;
}
use of org.apache.http.impl.cookie.BasicClientCookie in project zm-mailbox by Zimbra.
the class HttpClientUtil method newHttpState.
public static BasicCookieStore newHttpState(ZAuthToken authToken, String host, boolean isAdmin) {
BasicCookieStore cookieStore = new BasicCookieStore();
if (authToken != null) {
Map<String, String> cookieMap = authToken.cookieMap(isAdmin);
if (cookieMap != null) {
for (Map.Entry<String, String> ck : cookieMap.entrySet()) {
BasicClientCookie cookie = new BasicClientCookie(ck.getKey(), ck.getValue());
cookie.setDomain(host);
cookie.setPath("/");
cookie.setSecure(false);
cookieStore.addCookie(cookie);
}
}
}
return cookieStore;
}
use of org.apache.http.impl.cookie.BasicClientCookie in project zm-mailbox by Zimbra.
the class ZimbraAuthToken method encode.
@Override
public void encode(BasicCookieStore state, boolean isAdminReq, String cookieDomain) throws ServiceException {
String origAuthData = AuthTokenUtil.getOrigAuthData(this);
BasicClientCookie cookie = new BasicClientCookie(ZimbraCookie.authTokenCookieName(isAdminReq), origAuthData);
cookie.setDomain(cookieDomain);
cookie.setPath("/");
cookie.setSecure(false);
state.addCookie(cookie);
}
Aggregations