static void expires_server_ahead() { char *string; time_t t = time(NULL)+1000; char *server_date = dStrdup(ctime(&t)); time_t expt = t + 1000; char *exp_date = dStrdup(ctime(&expt)); string = dStrconcat("name=val; expires=", exp_date, NULL); a_Cookies_set(string, "e2000s1000.com", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "e2000s1000.com", "/"); a_Cookies_set(string, "e2000s1000s.com", "/", server_date); expect(__LINE__, "Cookie: name=val\r\n", "http", "e2000s1000s.com", "/"); expt = t - 500; /* past for the server, future for us */ dFree(exp_date); exp_date = dStrdup(ctime(&expt)); string = dStrconcat("name=val; expires=", exp_date, NULL); a_Cookies_set(string, "e500s1000.com", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "e500s1000.com", "/"); a_Cookies_set(string, "e500s1000s.com", "/", server_date); expect(__LINE__, "", "http", "e500s1000s.com", "/"); expt = t; /* expire at future-for-us server date */ dFree(exp_date); exp_date = dStrdup(ctime(&expt)); string = dStrconcat("name=val; expires=", exp_date, NULL); a_Cookies_set(string, "e1000s1000.com", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "e1000s1000.com", "/"); a_Cookies_set(string, "e1000s1000s.com", "/", server_date); expect(__LINE__, "", "http", "e1000s1000s.com", "/"); expt = time(NULL); /* now */ dFree(exp_date); exp_date = dStrdup(ctime(&expt)); string = dStrconcat("name=val; expires=", exp_date, NULL); a_Cookies_set(string, "e0s1000.com", "/", NULL); expect(__LINE__, "", "http", "e0s1000.com", "/"); a_Cookies_set(string, "e0s1000s.com", "/", server_date); expect(__LINE__, "", "http", "e0s1000s.com", "/"); dFree(exp_date); dFree(server_date); }
static void path() { a_Cookies_set("name=val; path=/", "p1.com", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "p1.com", "/"); a_Cookies_set("name=val; path=/dir1", "p2.com", "/dir2", NULL); expect(__LINE__, "", "http", "p2.com", "/"); expect(__LINE__, "", "http", "p2.com", "/d"); expect(__LINE__, "Cookie: name=val\r\n", "http", "p2.com", "/dir1"); expect(__LINE__, "Cookie: name=val\r\n", "http", "p2.com", "/dir1/"); expect(__LINE__, "", "http", "p2.com", "/dir2"); expect(__LINE__, "", "http", "p2.com", "/dir11"); a_Cookies_set("name=val; path=dir1", "p3.com", "/dir2", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "p3.com", "/"); expect(__LINE__, "Cookie: name=val\r\n", "http", "p3.com", "/dir1"); expect(__LINE__, "Cookie: name=val\r\n", "http", "p3.com", "/dir2"); a_Cookies_set("name=val; path=/dir1/", "p4.com", "/dir2", NULL); expect(__LINE__, "", "http", "p4.com", "/"); /* this next one strikes me as a bit odd, personally, but I suppose it's not * a big deal */ expect(__LINE__, "", "http", "p4.com", "/dir1"); expect(__LINE__, "", "http", "p4.com", "/dir11"); expect(__LINE__, "Cookie: name=val\r\n", "http", "p4.com", "/dir1/"); expect(__LINE__, "Cookie: name=val\r\n", "http", "p4.com", "/dir1/sub"); a_Cookies_set("name=val", "p5.com", "/dir/subdir", NULL); expect(__LINE__, "", "http", "p5.com", "/"); expect(__LINE__, "", "http", "p5.com", "/bir"); expect(__LINE__, "Cookie: name=val\r\n", "http", "p5.com", "/dir"); expect(__LINE__, "Cookie: name=val\r\n", "http", "p5.com", "/dir/"); a_Cookies_set("name=val", "p6.com", "/dir/subdir/", NULL); expect(__LINE__, "", "http", "p6.com", "/dir/"); expect(__LINE__, "Cookie: name=val\r\n", "http", "p6.com", "/dir/subdir"); expect(__LINE__, "Cookie: name=val\r\n", "http", "p6.com", "/dir/subdir/s"); }
/* * Scan, allocate, and set things according to header info. * (This function needs the whole header to work) */ static void Cache_parse_header(CacheEntry_t *entry) { char *header = entry->Header->str; char *Length, *Type, *location_str, *encoding; #ifndef DISABLE_COOKIES Dlist *Cookies; #endif Dlist *warnings; void *data; int i; _MSG("Cache_parse_header\n"); if (entry->Header->len > 12) { if (header[9] == '1' && header[10] == '0' && header[11] == '0') { /* 100: Continue. The "real" header has not come yet. */ MSG("An actual 100 Continue header!\n"); entry->Flags &= ~CA_GotHeader; dStr_free(entry->Header, 1); entry->Header = dStr_new(""); return; } if (header[9] == '3' && header[10] == '0' && (location_str = Cache_parse_field(header, "Location"))) { /* 30x: URL redirection */ DilloUrl *location_url = a_Url_new(location_str,URL_STR_(entry->Url)); if (prefs.filter_auto_requests == PREFS_FILTER_SAME_DOMAIN && !a_Url_same_organization(entry->Url, location_url)) { /* don't redirect; just show body like usual (if any) */ MSG("Redirection not followed from %s to %s\n", URL_HOST(entry->Url), URL_STR(location_url)); a_Url_free(location_url); } else { entry->Flags |= CA_Redirect; if (header[11] == '1') entry->Flags |= CA_ForceRedirect; /* 301 Moved Permanently */ else if (header[11] == '2') entry->Flags |= CA_TempRedirect; /* 302 Temporary Redirect */ if (URL_FLAGS(location_url) & (URL_Post + URL_Get) && dStrAsciiCasecmp(URL_SCHEME(location_url), "dpi") == 0 && dStrAsciiCasecmp(URL_SCHEME(entry->Url), "dpi") != 0) { /* Forbid dpi GET and POST from non dpi-generated urls */ MSG("Redirection Denied! '%s' -> '%s'\n", URL_STR(entry->Url), URL_STR(location_url)); a_Url_free(location_url); } else { entry->Location = location_url; } } dFree(location_str); } else if (strncmp(header + 9, "401", 3) == 0) { entry->Auth = Cache_parse_multiple_fields(header, "WWW-Authenticate"); } else if (strncmp(header + 9, "404", 3) == 0) { entry->Flags |= CA_NotFound; } } if ((warnings = Cache_parse_multiple_fields(header, "Warning"))) { for (i = 0; (data = dList_nth_data(warnings, i)); ++i) { MSG_HTTP("%s\n", (char *)data); dFree(data); } dList_free(warnings); } /* * Get Transfer-Encoding and initialize decoder */ encoding = Cache_parse_field(header, "Transfer-Encoding"); entry->TransferDecoder = a_Decode_transfer_init(encoding); if ((Length = Cache_parse_field(header, "Content-Length")) != NULL) { if (encoding) { /* * If Transfer-Encoding is present, Content-Length must be ignored. * If the Transfer-Encoding is non-identity, it is an error. */ if (dStrAsciiCasecmp(encoding, "identity")) MSG_HTTP("Content-Length and non-identity Transfer-Encoding " "headers both present.\n"); } else { entry->Flags |= CA_GotLength; entry->ExpectedSize = MAX(strtol(Length, NULL, 10), 0); } dFree(Length); } dFree(encoding); /* free Transfer-Encoding */ #ifndef DISABLE_COOKIES if ((Cookies = Cache_parse_multiple_fields(header, "Set-Cookie"))) { CacheClient_t *client; for (i = 0; (client = dList_nth_data(ClientQueue, i)); ++i) { if (client->Url == entry->Url) { DilloWeb *web = client->Web; if (!web->requester || a_Url_same_organization(entry->Url, web->requester)) { char *server_date = Cache_parse_field(header, "Date"); a_Cookies_set(Cookies, entry->Url, server_date); dFree(server_date); break; } } } if (i >= dList_length(ClientQueue)) { MSG("Cache: cookies not accepted from '%s'\n", URL_STR(entry->Url)); } for (i = 0; (data = dList_nth_data(Cookies, i)); ++i) dFree(data); dList_free(Cookies); } #endif /* !DISABLE_COOKIES */ /* * Get Content-Encoding and initialize decoder */ encoding = Cache_parse_field(header, "Content-Encoding"); entry->ContentDecoder = a_Decode_content_init(encoding); dFree(encoding); if (entry->ExpectedSize > 0) { if (entry->ExpectedSize > HUGE_FILESIZE) { entry->Flags |= CA_HugeFile; } /* Avoid some reallocs. With MAX_INIT_BUF we avoid a SEGFAULT * with huge files (e.g. iso files). * Note: the buffer grows automatically. */ dStr_free(entry->Data, 1); entry->Data = dStr_sized_new(MIN(entry->ExpectedSize, MAX_INIT_BUF)); } /* Get Content-Type */ if ((Type = Cache_parse_field(header, "Content-Type"))) { /* This HTTP Content-Type is not trusted. It's checked against real data * in Cache_process_queue(); only then CA_GotContentType becomes true. */ a_Cache_set_content_type(entry->Url, Type, "http"); _MSG("TypeHdr {%s} {%s}\n", Type, URL_STR(entry->Url)); _MSG("TypeMeta {%s}\n", entry->TypeMeta); dFree(Type); } Cache_ref_data(entry); }
int main() { if (Cookies_rc_check()) { MSG("If you change cookiesrc, remember to stop the DPIs via dpidc.\n"); return 1; } a_Cookies_set("name=val", "ordinary.com", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "ordinary.com", "/"); toomany(); maxage(); expires_server_ahead(); expires_server_behind(); expires_extremes(); expires_date_formats(); a_Cookies_set("name=val; expires=\"Sun Jan 10 00:00:00 2038\"", "quoted-date.org", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "quoted-date.org", "/"); a_Cookies_set("name=val; expires=\"Sun Jan 11 00:00:00 1970\"", "quoted-pastdate.org", "/", NULL); expect(__LINE__, "", "http", "quoted-pastdate.org", "/"); path(); /* LEADING/TRAILING DOTS AND A LITTLE PUBLIC SUFFIX */ a_Cookies_set("name=val; domain=co.il", "www.co.il", "/", NULL); expect(__LINE__, "", "http", "www.co.il", "/"); a_Cookies_set("name=val; domain=.co.il", "www.co.il", "/", NULL); expect(__LINE__, "", "http", "www.co.il", "/"); a_Cookies_set("name=val; domain=co.il.", "www.co.il.", "/", NULL); expect(__LINE__, "", "http", "www.co.il.", "/"); a_Cookies_set("name=val; domain=.co.il.", "www.co.il.", "/", NULL); expect(__LINE__, "", "http", ".www.co.il.", "/"); a_Cookies_set("name=val; domain=co.org", "www.co.org", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "www.co.org", "/"); a_Cookies_set("name=val; domain=.cp.org", "www.cp.org", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "www.cp.org", "/"); /* DOTDOMAIN */ a_Cookies_set("name=val; domain=.dotdomain.org", "dotdomain.org", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "dotdomain.org", "/"); expect(__LINE__, "Cookie: name=val\r\n", "http", "www.dotdomain.org", "/"); /* HOST_ONLY */ a_Cookies_set("name=val; domain=.hostonly.org", "hostonly.org", "/", NULL); a_Cookies_set("name2=val2", "hostonly.org", "/", NULL); a_Cookies_set("name3=val3; domain=hostonly.org", "hostonly.org", "/", NULL); expect(__LINE__, "Cookie: name=val; name2=val2; name3=val3\r\n", "http", "hostonly.org", "/"); a_Cookies_set("name=new; domain=.hostonly.org", "hostonly.org", "/", NULL); expect(__LINE__, "Cookie: name=new; name2=val2; name3=val3\r\n", "http", "hostonly.org", "/"); a_Cookies_set("name2=new2", "hostonly.org", "/", NULL); expect(__LINE__, "Cookie: name=new; name2=new2; name3=val3\r\n", "http", "hostonly.org", "/"); a_Cookies_set("name3=new3; domain=hostonly.org", "hostonly.org", "/", NULL); expect(__LINE__, "Cookie: name=new; name2=new2; name3=new3\r\n", "http", "hostonly.org", "/"); /* SUBDOMAIN */ a_Cookies_set("name=val; domain=www.subdomain.com", "subdomain.com", "/", NULL); a_Cookies_set("name=val; domain=.www.subdomain.com", "subdomain.com", "/", NULL); expect(__LINE__, "", "http", "subdomain.com", "/"); expect(__LINE__, "", "http", "www.subdomain.com", "/"); /* SUPERDOMAIN(?) */ a_Cookies_set("name=val; domain=.supdomain.com", "www.supdomain.com", "/", NULL); a_Cookies_set("name2=val2; domain=supdomain.com", "www.supdomain.com", "/", NULL); expect(__LINE__, "Cookie: name=val; name2=val2\r\n", "http", "sub2.sub.supdomain.com", "/"); expect(__LINE__, "Cookie: name=val; name2=val2\r\n", "http", "www.supdomain.com", "/"); expect(__LINE__, "Cookie: name=val; name2=val2\r\n", "http", "supdomain.com", "/"); /* UNRELATED */ a_Cookies_set("name=val; domain=another.com", "unrelated.com", "/", NULL); expect(__LINE__, "", "http", "another.com", "/"); a_Cookies_set("name=val; domain=another.com", "a.org", "/", NULL); expect(__LINE__, "", "http", "another.com", "/"); a_Cookies_set("name=val; domain=another.com", "badguys.com", "/", NULL); expect(__LINE__, "", "http", "another.com", "/"); a_Cookies_set("name=val; domain=another.com", "more.badguys.com", "/", NULL); expect(__LINE__, "", "http", "another.com", "/"); a_Cookies_set("name=val; domain=another.com", "verybadguys.com", "/", NULL); expect(__LINE__, "", "http", "another.com", "/"); a_Cookies_set("name=val; domain=similar.com", "imilar.com", "/", NULL); a_Cookies_set("name2=val2; domain=similar.com", "ssimilar.com", "/", NULL); a_Cookies_set("name3=val3; domain=.similar.com", "imilar.com", "/", NULL); a_Cookies_set("name4=val4; domain=.similar.com", "timilar.com", "/", NULL); a_Cookies_set("name4=val4; domain=.similar.com", "tiimilar.com", "/", NULL); expect(__LINE__, "", "http", "similar.com", "/"); /* SECURE */ a_Cookies_set("name=val; secure", "secure.com", "/", NULL); expect(__LINE__, "", "http", "secure.com", "/"); expect(__LINE__, "Cookie: name=val\r\n", "https", "secure.com", "/"); /* HTTPONLY */ a_Cookies_set("name=val; HttpOnly", "httponly.net", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "httponly.net", "/"); /* GIBBERISH ATTR IGNORED */ a_Cookies_set("name=val; ldkfals", "gibberish.net", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "gibberish.net", "/"); /* WHITESPACE/DELIMITERS */ a_Cookies_set(" name=val ", "whitespace.net", "/", NULL); a_Cookies_set("name2=val2;", "whitespace.net", "/", NULL); expect(__LINE__, "Cookie: name=val; name2=val2\r\n", "http", "whitespace.net", "/"); /* NAMELESS/VALUELESS */ a_Cookies_set("value", "nonameval.org", "/", NULL); a_Cookies_set("name=", "nonameval.org", "/", NULL); a_Cookies_set("name2= ", "nonameval.org", "/", NULL); expect(__LINE__, "Cookie: name=; name2=\r\n", "http", "nonameval.org", "/"); a_Cookies_set("=val2", "nonameval.org", "/", NULL); expect(__LINE__, "Cookie: name=; name2=\r\n", "http", "nonameval.org", "/"); /* SOME IP ADDRS */ a_Cookies_set("name=val", "FEDC:BA98:7654:3210:FEDC:BA98:7654:3210", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "FEDC:BA98:7654:3210:FEDC:BA98:7654:3210", "/"); a_Cookies_set("name=val", "::FFFF:129.144.52.38", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "::FFFF:129.144.52.38", "/"); a_Cookies_set("name=val", "127.0.0.1", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "127.0.0.1", "/"); a_Cookies_set("name=val; domain=128.0.0.1", "128.0.0.1", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "128.0.0.1", "/"); a_Cookies_set("name=val; domain=130.0.0.1", "129.0.0.1", "/", NULL); expect(__LINE__, "", "http", "129.0.0.1", "/"); expect(__LINE__, "", "http", "130.0.0.1", "/"); a_Cookies_set("name=val", "2.0.0.1", "/", NULL); a_Cookies_set("name=bad; domain=22.0.0.1", "2.0.0.1", "/", NULL); a_Cookies_set("name=bad; domain=.0.0.1", "2.0.0.1", "/", NULL); a_Cookies_set("name=bad; domain=not-ip.org", "2.0.0.1", "/", NULL); expect(__LINE__, "", "http", "22.0.0.1", "/"); expect(__LINE__, "", "http", "not-ip.org", "/"); expect(__LINE__, "Cookie: name=val\r\n", "http", "2.0.0.1", "/"); #if 0 HAD BEEN PLAYING AROUND WITH REAL PUBLIC SUFFIX a_Cookies_set("name=val;domain=sub.sub.yokohama.jp", "sub.sub.yokohama.jp", "/", NULL); MSG("sub sub yokohama should work: %s\n", a_Cookies_get_query("http", "sub.sub.yokohama.jp", "/")); a_Cookies_set("name=val; domain=sub.tokyo.jp", "sub.sub.tokyo.jp", "/", NULL); MSG("sub tokyo jp should fail: %s\n", a_Cookies_get_query("http", "sub.sub.tokyo.jp", "/")); a_Cookies_set("name=val; domain=pref.chiba.jp", "sub.pref.chiba.jp", "/", NULL); MSG("pref chiba jp should succeed: %s\n", a_Cookies_get_query("http", "sub.pref.chiba.jp", "/")); a_Cookies_set("name=val; domain=org", "www.dillo.org", "/", NULL); a_Cookies_set("name=val; domain=org", "dillo.org", "/", NULL); a_Cookies_set("name=val; domain=org", ".dillo.org", "/", NULL); a_Cookies_set("name=val; domain=org.", ".dillo.org", "/", NULL); a_Cookies_set("name=val; domain=org.", ".dillo.org.", "/", NULL); MSG("org should fail: %s\n", a_Cookies_get_query("http", "www.dillo.org", "/")); #endif MSG("TESTS: passed: %u failed: %u\n", passed, failed); MSG("Now that everything is full of fake cookies, you should run " "'dpidc stop', plus delete cookies.txt if necessary.\n"); return 0; }
/* * On 11 Aug 2009, Dan Winship posted to the http-state list with a bunch of * date formats he'd gathered. Let's work from that. I'll include his comments * below in double quotes. */ static void expires_date_formats() { /* "Revised Netscape spec format" */ a_Cookies_set("name=val; expires=Mon, 10-Dec-2037 17:02:24 GMT", "format1.com", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "format1.com", "/"); /* "rfc1123-date" */ a_Cookies_set("name=val; expires=Wed, 09 Dec 2037 16:27:23 GMT", "format2.com", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "format2.com", "/"); /* "4-digit-year version of Netscape spec example (see below). * Seems to only come from sites using PHP, but it's not PHP * itself; maybe some framework?" */ a_Cookies_set("name=val; expires=Thursday, 01-Jan-2036 00:00:00 GMT", "format3.com", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "format3.com", "/"); /* "The not-quite-asctime format used by Amazon." */ a_Cookies_set("name=val; expires=Mon Dec 10 16:32:30 2037 GMT", "format4.com", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "format4.com", "/"); /* "The syntax used by the example text in the Netscape spec, * although the actual grammar uses abbreviated weekday names" */ a_Cookies_set("name=val; expires=Wednesday, 01-Jan-37 00:00:00 GMT", "format5.com", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "format5.com", "/"); /* "Original Netscape spec" */ a_Cookies_set("name=val; expires=Mon, 10-Dec-37 20:35:03 GMT", "format6.com", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "format6.com", "/"); /* "If this had '01 Jan' it would be an rfc1123-date. This *is* a * legitimate rfc822 date, though not an rfc2822 date because 'GMT' * is deprecated in favor of '+0000' there." */ a_Cookies_set("name=val; expires=Wed, 1 Jan 2035 00:00:00 GMT", "format7.com", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "format7.com", "/"); /* "Would match the 'weird php' syntax above if it was '08-Dec'" */ a_Cookies_set("name=val; expires=Saturday, 8-Dec-2035 21:24:09 GMT", "format8.com", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "format8.com", "/"); /* "God only knows what they were thinking. This came from a hit-tracker * site, and it's possible that it's just totally broken and no one parses * it 'correctly'" */ a_Cookies_set("name=val; expires=Thu, 31 Dec 23:55:55 2037 GMT", "format9.com", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "format9.com", "/"); /* "Another kind of rfc822 / nearly-rfc1123 date, using superfluous * whitespace." */ a_Cookies_set("name=val; expires=Sun, 9 Dec 2036 13:42:05 GMT", "formata.com", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "formata.com", "/"); /* "Another kind of 'lets throw components together at random'. The * site that this cookie came has apparently been fixed since then. * (It uses the Netscape spec format now.)" */ a_Cookies_set("name=val; expires=Wed Dec 12 2037 08:44:07 GMT-0500 (EST)", "formatb.com", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "formatb.com", "/"); a_Cookies_set("name=val; expires=Sun, 1-Jan-2035 00:00:00 GMT", "formatc.com", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "formatc.com", "/"); /* ...and the remaining handful that he encountered once or twice were * far too broken to deserve our attention (e.g., times like "13:57:2"). */ /* Now here's what github was sending in 2015. */ a_Cookies_set("name=val; expires=Sat, 07 Jul 2035 21:41:24 -0000", "formatd.com", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "formatd.com", "/"); }
static void expires_extremes() { time_t t; char *server_date; a_Cookies_set("name=val; expires=Fri Dec 13 20:45:52 1801", "expmin.com", "/", NULL); expect(__LINE__, "", "http", "expmin.com", "/"); a_Cookies_set("name=val; expires=Fri Dec 13 20:45:52 1901", "expmin2.com", "/", NULL); expect(__LINE__, "", "http", "expmin2.com", "/"); a_Cookies_set("name=val; expires=Wed Dec 31 23:59:59 1969", "expneg.com", "/", NULL); expect(__LINE__, "", "http", "expneg.com", "/"); a_Cookies_set("name=val; expires=Thu, 01-January-70 00:00:00 GMT", "expepoch.com", "/", NULL); expect(__LINE__, "", "http", "expepoch.com", "/"); /* TODO: revisit these tests in a few decades */ a_Cookies_set("name=val; expires=Tue Jan 19 03:14:07 2038", "expmax.com", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "expmax.com", "/"); a_Cookies_set("name=val; expires=Sun January 1 00:00:00 2040", "pastmax.com", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "pastmax.com", "/"); t = time(NULL)+1000; server_date = dStrdup(ctime(&t)); a_Cookies_set("name=val; expires=Fri Dec 13 20:45:52 1901", "expmina.com", "/", server_date); expect(__LINE__, "", "http", "expmina.com", "/"); a_Cookies_set("name=val; expires=Wed Dec 31 23:59:59 1969", "expnega.com", "/", server_date); expect(__LINE__, "", "http", "expnega.com", "/"); a_Cookies_set("name=val; expires=Thu Jan 1 00:00:00 1970", "expepocha.com", "/", server_date); expect(__LINE__, "", "http", "expepocha.com", "/"); a_Cookies_set("name=val; expires=Tue Jan 19 03:14:07 2038", "expmaxa.com", "/", server_date); expect(__LINE__, "Cookie: name=val\r\n", "http", "expmaxa.com", "/"); a_Cookies_set("name=val; expires=Thu, 01-Jan-40 00:00:00 GMT", "pastmaxa.com", "/", server_date); expect(__LINE__, "Cookie: name=val\r\n", "http", "pastmaxa.com", "/"); t = time(NULL)-1000; dFree(server_date); server_date = dStrdup(ctime(&t)); a_Cookies_set("name=val; expires=Fri Dec 13 20:45:52 1901", "expminb.com", "/", server_date); expect(__LINE__, "", "http", "expminb.com", "/"); a_Cookies_set("name=val; expires=Wed Dec 31 23:59:59 1969", "expnegb.com", "/", server_date); expect(__LINE__, "", "http", "expnegb.com", "/"); a_Cookies_set("name=val; expires=Thu Jan 1 00:00:00 1970", "expepochb.com", "/", server_date); expect(__LINE__, "", "http", "expepochb.com", "/"); a_Cookies_set("name=val; expires=Tue Jan 19 03:14:07 2038", "expmaxb.com", "/", server_date); expect(__LINE__, "Cookie: name=val\r\n", "http", "expmaxb.com", "/"); a_Cookies_set("name=val; expires=Sun Jan 1 00:00:00 2040", "pastmaxb.com", "/", server_date); expect(__LINE__, "Cookie: name=val\r\n", "http", "pastmaxb.com", "/"); dFree(server_date); }
static void maxage() { time_t t = time(NULL)+1000; char *server_date = dStrdup(ctime(&t)); a_Cookies_set("name=val; max-age=0", "maxage0.com", "/", NULL); expect(__LINE__, "", "http", "maxage0.com", "/"); a_Cookies_set("name=val; max-age=-0", "maxage-0.com", "/", NULL); expect(__LINE__, "", "http", "maxage-0.com", "/"); a_Cookies_set("name=val; max-age=100", "maxage100.com", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "maxage100.com", "/"); a_Cookies_set("name=val; max-age=-100", "maxage-100.com", "/", NULL); expect(__LINE__, "", "http", "maxage-100.com", "/"); a_Cookies_set("name=val; max-age=2000000000", "maxage2bil.com", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "maxage2bil.com", "/"); a_Cookies_set("name=val; max-age=3000000000", "maxage3bil.com", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "maxage3bil.com", "/"); a_Cookies_set("name=val; max-age=7000000000", "maxage7bil.com", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "maxage7bil.com", "/"); a_Cookies_set("name=val; max-age=-2000000000", "maxage-2bil.com", "/",NULL); expect(__LINE__, "", "http", "maxage-2bil.com", "/"); a_Cookies_set("name=val; max-age=-3000000000", "maxage-3bil.com", "/",NULL); expect(__LINE__, "", "http", "maxage-3bil.com", "/"); a_Cookies_set("name=val; max-age=-7000000000", "maxage-7bil.com", "/",NULL); expect(__LINE__, "", "http", "maxage-7bil.com", "/"); /* just having a server date shouldn't matter */ a_Cookies_set("name=val; max-age=0", "maxage0s.com", "/", server_date); expect(__LINE__, "", "http", "maxage0s.com", "/"); a_Cookies_set("name=val; max-age=100", "maxage100s.com", "/", server_date); expect(__LINE__, "Cookie: name=val\r\n", "http", "maxage100s.com", "/"); a_Cookies_set("name=val; max-age=-100", "maxage-100s.com", "/",server_date); expect(__LINE__, "", "http", "maxage-100s.com", "/"); /* MAX-AGE and EXPIRES */ a_Cookies_set("name=val; max-age=90; expires=Wed Jan 20 01:26:32 2010", "maxagelater.com", "/", NULL); expect(__LINE__, "Cookie: name=val\r\n", "http", "maxagelater.com", "/"); a_Cookies_set("name=val; max-age=90; expires=Wed Jan 20 01:26:32 2010", "maxagelaters.com", "/", server_date); expect(__LINE__, "Cookie: name=val\r\n", "http", "maxagelaters.com", "/"); dFree(server_date); }
static void toomany() { a_Cookies_set("1=1", "toomany.com", "/", NULL); a_Cookies_set("2=1", "toomany.com", "/", NULL); a_Cookies_set("3=1", "toomany.com", "/", NULL); a_Cookies_set("4=1", "toomany.com", "/", NULL); a_Cookies_set("5=1", "toomany.com", "/", NULL); a_Cookies_set("6=1", "toomany.com", "/", NULL); a_Cookies_set("7=1", "toomany.com", "/path/", NULL); a_Cookies_set("8=1", "toomany.com", "/", NULL); a_Cookies_set("9=1", "toomany.com", "/", NULL); a_Cookies_set("10=1", "toomany.com", "/", NULL); a_Cookies_set("11=1", "toomany.com", "/", NULL); a_Cookies_set("12=1", "toomany.com", "/", NULL); a_Cookies_set("13=1", "toomany.com", "/", NULL); a_Cookies_set("14=1", "toomany.com", "/", NULL); a_Cookies_set("15=1", "toomany.com", "/", NULL); a_Cookies_set("16=1", "toomany.com", "/", NULL); a_Cookies_set("17=1", "toomany.com", "/", NULL); a_Cookies_set("18=1", "toomany.com", "/", NULL); a_Cookies_set("19=1", "toomany.com", "/", NULL); a_Cookies_set("20=1", "toomany.com", "/", NULL); a_Cookies_set("21=1", "toomany.com", "/", NULL); /* 1 was oldest and discarded */ expect(__LINE__, "Cookie: 7=1; 2=1; 3=1; 4=1; 5=1; 6=1; 8=1; 9=1; 10=1; " "11=1; 12=1; 13=1; 14=1; 15=1; 16=1; 17=1; 18=1; 19=1; " "20=1; 21=1\r\n", "http", "toomany.com", "/path/"); sleep(1); /* touch all of them except #7 (path matching) */ expect(__LINE__, "Cookie: 2=1; 3=1; 4=1; 5=1; 6=1; 8=1; 9=1; 10=1; " "11=1; 12=1; 13=1; 14=1; 15=1; 16=1; 17=1; 18=1; 19=1; " "20=1; 21=1\r\n", "http", "toomany.com", "/"); a_Cookies_set("22=1", "toomany.com", "/", NULL); /* 7 was oldest and discarded */ expect(__LINE__, "Cookie: 2=1; 3=1; 4=1; 5=1; 6=1; 8=1; 9=1; 10=1; " "11=1; 12=1; 13=1; 14=1; 15=1; 16=1; 17=1; 18=1; 19=1; " "20=1; 21=1; 22=1\r\n", "http", "toomany.com", "/path/"); }