Search in sources :

Example 16 with Cookie

use of io.undertow.server.handlers.Cookie in project undertow by undertow-io.

the class CookiesTestCase method testEqualsInValueNotAllowed.

@Test
public void testEqualsInValueNotAllowed() {
    Map<String, Cookie> cookies = Cookies.parseRequestCookies(2, false, Arrays.asList("CUSTOMER=WILE_E_COYOTE=THE_COYOTE; SHIPPING=FEDEX"));
    Cookie cookie = cookies.get("CUSTOMER");
    Assert.assertNotNull(cookie);
    Assert.assertEquals("WILE_E_COYOTE", cookie.getValue());
    cookie = cookies.get("SHIPPING");
    Assert.assertNotNull(cookie);
    Assert.assertEquals("FEDEX", cookie.getValue());
}
Also used : Cookie(io.undertow.server.handlers.Cookie) UnitTest(io.undertow.testutils.category.UnitTest) Test(org.junit.Test)

Example 17 with Cookie

use of io.undertow.server.handlers.Cookie in project undertow by undertow-io.

the class CookiesTestCase method testSimpleJSONObjectInRequestCookies.

@Test
public void testSimpleJSONObjectInRequestCookies() {
    Map<String, Cookie> cookies = Cookies.parseRequestCookies(2, true, Arrays.asList("CUSTOMER={\"v1\":1, \"id\":\"some_unique_id\", \"c\":\"http://www.google.com?q=love me\"};" + " $Domain=LOONEY_TUNES; $Version=1; $Path=/; SHIPPING=FEDEX"));
    Cookie cookie = cookies.get("CUSTOMER");
    Assert.assertEquals("CUSTOMER", cookie.getName());
    Assert.assertEquals("{\"v1\":1, \"id\":\"some_unique_id\", \"c\":\"http://www.google.com?q=love me\"}", cookie.getValue());
    Assert.assertEquals("LOONEY_TUNES", cookie.getDomain());
    Assert.assertEquals(1, cookie.getVersion());
    Assert.assertEquals("/", cookie.getPath());
    cookie = cookies.get("SHIPPING");
    Assert.assertEquals("SHIPPING", cookie.getName());
    Assert.assertEquals("FEDEX", cookie.getValue());
    Assert.assertEquals("LOONEY_TUNES", cookie.getDomain());
    Assert.assertEquals(1, cookie.getVersion());
    Assert.assertEquals("/", cookie.getPath());
}
Also used : Cookie(io.undertow.server.handlers.Cookie) UnitTest(io.undertow.testutils.category.UnitTest) Test(org.junit.Test)

Example 18 with Cookie

use of io.undertow.server.handlers.Cookie in project undertow by undertow-io.

the class CookiesTestCase method testComplexJSONObjectInRequestCookies.

@Test
public void testComplexJSONObjectInRequestCookies() {
    Map<String, Cookie> cookies = Cookies.parseRequestCookies(2, false, Arrays.asList("CUSTOMER={ \"accounting\" : [ { \"firstName\" : \"John\", \"lastName\" : \"Doe\", \"age\" : 23 }," + " { \"firstName\" : \"Mary\",  \"lastName\" : \"Smith\", \"age\" : 32 }], " + "\"sales\" : [ { \"firstName\" : \"Sally\", \"lastName\" : \"Green\", \"age\" : 27 }, " + "{ \"firstName\" : \"Jim\", \"lastName\" : \"Galley\", \"age\" : 41 } ] };" + " $Domain=LOONEY_TUNES; $Version=1; $Path=/; SHIPPING=FEDEX"));
    Cookie cookie = cookies.get("CUSTOMER");
    Assert.assertEquals("CUSTOMER", cookie.getName());
    Assert.assertEquals("{ \"accounting\" : [ { \"firstName\" : \"John\", \"lastName\" : \"Doe\", \"age\" : 23 }," + " { \"firstName\" : \"Mary\",  \"lastName\" : \"Smith\", \"age\" : 32 }], " + "\"sales\" : [ { \"firstName\" : \"Sally\", \"lastName\" : \"Green\", \"age\" : 27 }, " + "{ \"firstName\" : \"Jim\", \"lastName\" : \"Galley\", \"age\" : 41 } ] }", cookie.getValue());
    Assert.assertEquals("LOONEY_TUNES", cookie.getDomain());
    Assert.assertEquals(1, cookie.getVersion());
    Assert.assertEquals("/", cookie.getPath());
    cookie = cookies.get("SHIPPING");
    Assert.assertEquals("SHIPPING", cookie.getName());
    Assert.assertEquals("FEDEX", cookie.getValue());
    Assert.assertEquals("LOONEY_TUNES", cookie.getDomain());
    Assert.assertEquals(1, cookie.getVersion());
    Assert.assertEquals("/", cookie.getPath());
}
Also used : Cookie(io.undertow.server.handlers.Cookie) UnitTest(io.undertow.testutils.category.UnitTest) Test(org.junit.Test)

Example 19 with Cookie

use of io.undertow.server.handlers.Cookie in project undertow by undertow-io.

the class CookiesTestCase method testParsingSetCookieHeaderV0.

@Test
public void testParsingSetCookieHeaderV0() {
    Cookie cookie = Cookies.parseSetCookieHeader("CUSTOMER=WILE_E_COYOTE; path=/; expires=Wednesday, 09-Nov-99 23:12:40 GMT");
    Assert.assertEquals("CUSTOMER", cookie.getName());
    Assert.assertEquals("WILE_E_COYOTE", cookie.getValue());
    Assert.assertEquals("/", cookie.getPath());
    Assert.assertEquals(date(1999, 11, 9, 23, 12, 40), cookie.getExpires());
    cookie = Cookies.parseSetCookieHeader("SHIPPING=FEDEX; path=/foo; secure");
    Assert.assertEquals("SHIPPING", cookie.getName());
    Assert.assertEquals("FEDEX", cookie.getValue());
    Assert.assertEquals("/foo", cookie.getPath());
    Assert.assertTrue(cookie.isSecure());
    cookie = Cookies.parseSetCookieHeader("SHIPPING=FEDEX");
    Assert.assertEquals("SHIPPING", cookie.getName());
    Assert.assertEquals("FEDEX", cookie.getValue());
}
Also used : Cookie(io.undertow.server.handlers.Cookie) UnitTest(io.undertow.testutils.category.UnitTest) Test(org.junit.Test)

Example 20 with Cookie

use of io.undertow.server.handlers.Cookie in project undertow by undertow-io.

the class CookiesTestCase method testParsingSetCookieHeaderV1.

@Test
public void testParsingSetCookieHeaderV1() {
    Cookie cookie = Cookies.parseSetCookieHeader("Customer=\"WILE_E_COYOTE\"; Version=\"1\"; Path=\"/acme\"");
    Assert.assertEquals("Customer", cookie.getName());
    Assert.assertEquals("WILE_E_COYOTE", cookie.getValue());
    Assert.assertEquals("/acme", cookie.getPath());
    Assert.assertEquals(1, cookie.getVersion());
    cookie = Cookies.parseSetCookieHeader("SHIPPING=\"FEDEX\"; path=\"/foo\"; secure; Version=\"1\";");
    Assert.assertEquals("SHIPPING", cookie.getName());
    Assert.assertEquals("FEDEX", cookie.getValue());
    Assert.assertEquals("/foo", cookie.getPath());
    Assert.assertTrue(cookie.isSecure());
    Assert.assertEquals(1, cookie.getVersion());
}
Also used : Cookie(io.undertow.server.handlers.Cookie) UnitTest(io.undertow.testutils.category.UnitTest) Test(org.junit.Test)

Aggregations

Cookie (io.undertow.server.handlers.Cookie)21 UnitTest (io.undertow.testutils.category.UnitTest)12 Test (org.junit.Test)12 CookieImpl (io.undertow.server.handlers.CookieImpl)4 HttpString (io.undertow.util.HttpString)2 NotificationReceiver (io.undertow.security.api.NotificationReceiver)1 SecurityNotification (io.undertow.security.api.SecurityNotification)1 Account (io.undertow.security.idm.Account)1 Session (io.undertow.server.session.Session)1 HeaderMap (io.undertow.util.HeaderMap)1 HeaderValues (io.undertow.util.HeaderValues)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 HttpCookie (org.springframework.http.HttpCookie)1 ResponseCookie (org.springframework.http.ResponseCookie)1 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)1