use of org.asynchttpclient.cookie.ThreadSafeCookieStore in project async-http-client by AsyncHttpClient.
the class CookieStoreTest method shouldAlsoServeNonSecureCookiesBasedOnTheUriScheme.
// rfc6265#section-1 Cookies for a given host are shared across all the ports on that host
private void shouldAlsoServeNonSecureCookiesBasedOnTheUriScheme() {
CookieStore store = new ThreadSafeCookieStore();
store.add(Uri.create("https://foo.org/moodle/"), ClientCookieDecoder.LAX.decode("cookie1=VALUE1; Path=/"));
store.add(Uri.create("https://foo.org:443/moodle/login"), ClientCookieDecoder.LAX.decode("cookie1=VALUE2; Path=/"));
store.add(Uri.create("https://foo.org:443/moodle/login"), ClientCookieDecoder.LAX.decode("cookie1=VALUE3; Path=/; HttpOnly"));
Uri uri = Uri.create("https://foo.org/moodle/login");
assertTrue(store.getAll().size() == 1);
assertTrue(store.get(uri).get(0).value().equals("VALUE3"));
assertTrue(!store.get(uri).get(0).isSecure());
}
use of org.asynchttpclient.cookie.ThreadSafeCookieStore in project async-http-client by AsyncHttpClient.
the class CookieStoreTest method shouldServeSecureCookiesForSpecificallyRetrievedHttpUriScheme.
// rfc6265#section-1 Cookies for a given host are shared across all the ports on that host
private void shouldServeSecureCookiesForSpecificallyRetrievedHttpUriScheme() {
CookieStore store = new ThreadSafeCookieStore();
store.add(Uri.create("https://foo.org/moodle/"), ClientCookieDecoder.LAX.decode("cookie1=VALUE1; Path=/"));
store.add(Uri.create("https://foo.org:443/moodle/login"), ClientCookieDecoder.LAX.decode("cookie1=VALUE2; Path=/"));
store.add(Uri.create("https://foo.org:443/moodle/login"), ClientCookieDecoder.LAX.decode("cookie1=VALUE3; Path=/; Secure"));
Uri uri = Uri.create("https://foo.org/moodle/login");
assertTrue(store.get(uri).size() == 1);
assertTrue(store.get(uri).get(0).value().equals("VALUE3"));
assertTrue(store.get(uri).get(0).isSecure());
}
use of org.asynchttpclient.cookie.ThreadSafeCookieStore in project async-http-client by AsyncHttpClient.
the class CookieStoreTest method handleCookiePathInCaseSensitiveManner.
// RFC 2965 sec. 3.3.3
private void handleCookiePathInCaseSensitiveManner() {
CookieStore store = new ThreadSafeCookieStore();
store.add(Uri.create("http://www.foo.com/foo/bar"), ClientCookieDecoder.LAX.decode("ALPHA=VALUE1"));
assertTrue(store.get(Uri.create("http://www.FoO.com/Foo/bAr")).isEmpty());
}
use of org.asynchttpclient.cookie.ThreadSafeCookieStore in project async-http-client by AsyncHttpClient.
the class CookieStoreTest method shouldCleanExpiredCookieFromUnderlyingDataStructure.
private void shouldCleanExpiredCookieFromUnderlyingDataStructure() throws Exception {
ThreadSafeCookieStore store = new ThreadSafeCookieStore();
store.add(Uri.create("https://foo.org/moodle/"), getCookie("JSESSIONID", "FOO", 1));
store.add(Uri.create("https://bar.org/moodle/"), getCookie("JSESSIONID", "BAR", 1));
store.add(Uri.create("https://bar.org/moodle/"), new DefaultCookie("UNEXPIRED_BAR", "BAR"));
store.add(Uri.create("https://foobar.org/moodle/"), new DefaultCookie("UNEXPIRED_FOOBAR", "FOOBAR"));
assertTrue(store.getAll().size() == 4);
Thread.sleep(2000);
store.evictExpired();
assertTrue(store.getUnderlying().size() == 2);
Collection<String> unexpiredCookieNames = store.getAll().stream().map(Cookie::name).collect(Collectors.toList());
assertTrue(unexpiredCookieNames.containsAll(Sets.newHashSet("UNEXPIRED_BAR", "UNEXPIRED_FOOBAR")));
}
Aggregations