TEST(CookieDecoderTest, testDecodingCommaSeparatedClientSideCookies) { String source = "$Version=\"1\"; session_id=\"1234\", " + "$Version=\"1\"; session_id=\"1111\"; $Domain=\".cracker.edu\""; Set<Cookie> cookies = CookieDecoder.decode(source); Iterator<Cookie> it = cookies.iterator(); Cookie c; assertTrue(it.hasNext()); c = it.next(); assertEquals(1, c.getVersion()); assertEquals("session_id", c.getName()); assertEquals("1234", c.getValue()); assertNull(c.getPath()); assertNull(c.getComment()); assertNull(c.getCommentUrl()); assertNull(c.getDomain()); assertTrue(c.getPorts().isEmpty()); assertEquals(Long.MIN_VALUE, c.getMaxAge()); assertTrue(it.hasNext()); c = it.next(); assertEquals(1, c.getVersion()); assertEquals("session_id", c.getName()); assertEquals("1111", c.getValue()); assertEquals(".cracker.edu", c.getDomain()); assertNull(c.getPath()); assertNull(c.getComment()); assertNull(c.getCommentUrl()); assertTrue(c.getPorts().isEmpty()); assertEquals(Long.MIN_VALUE, c.getMaxAge()); assertFalse(it.hasNext()); }
TEST(CookieDecoderTest, testDecodingClientSideCookies) { String source = "$Version=\"1\"; " + "Part_Number=\"Riding_Rocket_0023\"; $Path=\"/acme/ammo\"; " + "Part_Number=\"Rocket_Launcher_0001\"; $Path=\"/acme\""; Set<Cookie> cookies = CookieDecoder.decode(source); Iterator<Cookie> it = cookies.iterator(); Cookie c; c = it.next(); assertEquals(1, c.getVersion()); assertEquals("Part_Number", c.getName()); assertEquals("Rocket_Launcher_0001", c.getValue()); assertEquals("/acme", c.getPath()); assertNull(c.getComment()); assertNull(c.getCommentUrl()); assertNull(c.getDomain()); assertTrue(c.getPorts().isEmpty()); assertEquals(Long.MIN_VALUE, c.getMaxAge()); c = it.next(); assertEquals(1, c.getVersion()); assertEquals("Part_Number", c.getName()); assertEquals("Riding_Rocket_0023", c.getValue()); assertEquals("/acme/ammo", c.getPath()); assertNull(c.getComment()); assertNull(c.getCommentUrl()); assertNull(c.getDomain()); assertTrue(c.getPorts().isEmpty()); assertEquals(Long.MIN_VALUE, c.getMaxAge()); assertFalse(it.hasNext()); }
TEST(CookieDecoderTest, testDecodingValuesWithCommasAndEquals) { String src = "A=v=1&lg=en-US,it-IT,it&intl=it&np=1;T=z=E"; Set<Cookie> cookies = CookieDecoder.decode(src); Iterator<Cookie> i = cookies.iterator(); Cookie c = i.next(); assertEquals("A", c.getName()); assertEquals("v=1&lg=en-US,it-IT,it&intl=it&np=1", c.getValue()); c = i.next(); assertEquals("T", c.getName()); assertEquals("z=E", c.getValue()); }
TEST(CookieDecoderTest, testDecodingWeirdNames2) { String src = "HTTPOnly="; Set<Cookie> cookies = CookieDecoder.decode(src); Cookie c = cookies.iterator().next(); assertEquals("HTTPOnly", c.getName()); assertEquals("", c.getValue()); }
TEST(CookieDecoderTest, testDecodingWeirdNames1) { String src = "path=; expires=Mon, 01-Jan-1990 00:00:00 GMT; path=/; domain=.www.google.com"; Set<Cookie> cookies = CookieDecoder.decode(src); Cookie c = cookies.iterator().next(); assertEquals("path", c.getName()); assertEquals("", c.getValue()); assertEquals("/", c.getPath()); }
TEST(CookieDecoderTest, testDecodingQuotedCookie) { String source = "a=\"\"," + "b=\"1\"," + "c=\"\\\"1\\\"2\\\"\"," + "d=\"1\\\"2\\\"3\"," + "e=\"\\\"\\\"\"," + "f=\"1\\\"\\\"2\"," + "g=\"\\\\\"," + "h=\"';,\\x\""; Set<Cookie> cookies = CookieDecoder.decode(source); Iterator<Cookie> it = cookies.iterator(); Cookie c; c = it.next(); assertEquals("a", c.getName()); assertEquals("", c.getValue()); c = it.next(); assertEquals("b", c.getName()); assertEquals("1", c.getValue()); c = it.next(); assertEquals("c", c.getName()); assertEquals("\"1\"2\"", c.getValue()); c = it.next(); assertEquals("d", c.getName()); assertEquals("1\"2\"3", c.getValue()); c = it.next(); assertEquals("e", c.getName()); assertEquals("\"\"", c.getValue()); c = it.next(); assertEquals("f", c.getName()); assertEquals("1\"\"2", c.getValue()); c = it.next(); assertEquals("g", c.getName()); assertEquals("\\", c.getValue()); c = it.next(); assertEquals("h", c.getName()); assertEquals("';,\\x", c.getValue()); assertFalse(it.hasNext()); }
CGI* CGI::addCookie(QString strName, QString strValue, QDateTime qdtExpiration, QString strDomain, QString strPath, bool bHttpOnly, bool bSecure) { // Iterate over the existing new cookies for (int intCookie = 0; intCookie < this->mNewCookies.size(); ++intCookie) { // Localize the cookie Cookie structNewCookie = this->mNewCookies.at(intCookie); // Check the name if (structNewCookie.getName() == strName) { // Delete the cookie this->mNewCookies.removeAt(intCookie); // We're done break; } } // Create the new structure Cookie structNewCookie(strName, strValue, qdtExpiration, strDomain, strPath, bHttpOnly, bSecure); // Add the cookie to the instance this->mNewCookies.append(structNewCookie); // Return the instance return this; }
string CookieList::escapeCookies() const { string cookie_parameter(""); bool first = true; auto it = cookie_list_.cbegin(); while(it != cookie_list_.cend()) { if(first == true) { first = false; } else { cookie_parameter += ";"; } Cookie cookie = (*it); cookie_parameter += (cookie.getName() + "=" + cookie.getValue()); ++it; } return cookie_parameter; }
TEST(CookieDecoderTest, testDecodingGoogleAnalyticsCookie) { String source = "ARPT=LWUKQPSWRTUN04CKKJI; " + "kw-2E343B92-B097-442c-BFA5-BE371E0325A2=unfinished furniture; " + "__utma=48461872.1094088325.1258140131.1258140131.1258140131.1; " + "__utmb=48461872.13.10.1258140131; __utmc=48461872; " + "__utmz=48461872.1258140131.1.1.utmcsr=overstock.com|utmccn=(referral)|utmcmd=referral|utmcct=/Home-Garden/Furniture/Clearance,/clearance,/32/dept.html"; Set<Cookie> cookies = CookieDecoder.decode(source); Iterator<Cookie> it = cookies.iterator(); Cookie c; c = it.next(); assertEquals("__utma", c.getName()); assertEquals("48461872.1094088325.1258140131.1258140131.1258140131.1", c.getValue()); c = it.next(); assertEquals("__utmb", c.getName()); assertEquals("48461872.13.10.1258140131", c.getValue()); c = it.next(); assertEquals("__utmc", c.getName()); assertEquals("48461872", c.getValue()); c = it.next(); assertEquals("__utmz", c.getName()); assertEquals("48461872.1258140131.1.1.utmcsr=overstock.com|utmccn=(referral)|utmcmd=referral|utmcct=/Home-Garden/Furniture/Clearance,/clearance,/32/dept.html", c.getValue()); c = it.next(); assertEquals("ARPT", c.getName()); assertEquals("LWUKQPSWRTUN04CKKJI", c.getValue()); c = it.next(); assertEquals("kw-2E343B92-B097-442c-BFA5-BE371E0325A2", c.getName()); assertEquals("unfinished furniture", c.getValue()); assertFalse(it.hasNext()); }
void Cookies::clear(Cookie & cookie) { cookie.setValue("deleted"); cookie.setExpires(QDateTime::fromTime_t(0)); m_cookies[cookie.getName()] = cookie; }
void Cookies::set(const Cookie & cookie) { m_cookies[cookie.getName()] = cookie; }