Search in sources :

Example 31 with ThreadSafeCookieStore

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());
}
Also used : CookieStore(org.asynchttpclient.cookie.CookieStore) ThreadSafeCookieStore(org.asynchttpclient.cookie.ThreadSafeCookieStore) Uri(org.asynchttpclient.uri.Uri) ThreadSafeCookieStore(org.asynchttpclient.cookie.ThreadSafeCookieStore)

Example 32 with ThreadSafeCookieStore

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());
}
Also used : CookieStore(org.asynchttpclient.cookie.CookieStore) ThreadSafeCookieStore(org.asynchttpclient.cookie.ThreadSafeCookieStore) Uri(org.asynchttpclient.uri.Uri) ThreadSafeCookieStore(org.asynchttpclient.cookie.ThreadSafeCookieStore)

Example 33 with ThreadSafeCookieStore

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());
}
Also used : CookieStore(org.asynchttpclient.cookie.CookieStore) ThreadSafeCookieStore(org.asynchttpclient.cookie.ThreadSafeCookieStore) ThreadSafeCookieStore(org.asynchttpclient.cookie.ThreadSafeCookieStore)

Example 34 with ThreadSafeCookieStore

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")));
}
Also used : DefaultCookie(io.netty.handler.codec.http.cookie.DefaultCookie) ThreadSafeCookieStore(org.asynchttpclient.cookie.ThreadSafeCookieStore)

Aggregations

ThreadSafeCookieStore (org.asynchttpclient.cookie.ThreadSafeCookieStore)34 CookieStore (org.asynchttpclient.cookie.CookieStore)33 Uri (org.asynchttpclient.uri.Uri)16 Test (org.testng.annotations.Test)5 DefaultCookie (io.netty.handler.codec.http.cookie.DefaultCookie)3 Timer (io.netty.util.Timer)3 TimeUnit (java.util.concurrent.TimeUnit)3 CookieEvictionTask (org.asynchttpclient.cookie.CookieEvictionTask)3 Sets (com.google.common.collect.Sets)2 ClientCookieDecoder (io.netty.handler.codec.http.cookie.ClientCookieDecoder)2 ClientCookieEncoder (io.netty.handler.codec.http.cookie.ClientCookieEncoder)2 Cookie (io.netty.handler.codec.http.cookie.Cookie)2 Collection (java.util.Collection)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Assert.assertTrue (org.testng.Assert.assertTrue)2 AfterClass (org.testng.annotations.AfterClass)2 BeforeClass (org.testng.annotations.BeforeClass)2