1# Commands covered:  http::cookiejar
2#
3# This file contains a collection of tests for the cookiejar package.
4# Sourcing this file into Tcl runs the tests and generates output for errors.
5# No output means no errors were found.
6#
7# Copyright © 2014 Donal K. Fellows.
8#
9# See the file "license.terms" for information on usage and redistribution of
10# this file, and for a DISCLAIMER OF ALL WARRANTIES.
11
12if {"::tcltest" ni [namespace children]} {
13    package require tcltest 2.5
14    namespace import -force ::tcltest::*
15}
16
17::tcltest::loadTestedCommands
18
19testConstraint notMacCI [expr {![info exists ::env(MAC_CI)]}]
20testConstraint sqlite3 [expr {[testConstraint notMacCI] && ![catch {
21    package require sqlite3
22}]}]
23testConstraint cookiejar [expr {[testConstraint sqlite3] && ![catch {
24    package require cookiejar
25}]}]
26
27set COOKIEJAR_VERSION 0.2.0
28test http-cookiejar-1.1 "cookie storage: packaging" {cookiejar} {
29    package require cookiejar
30} $COOKIEJAR_VERSION
31test http-cookiejar-1.2 "cookie storage: packaging" {cookiejar} {
32    package require cookiejar
33    package require cookiejar
34} $COOKIEJAR_VERSION
35
36test http-cookiejar-2.1 "cookie storage: basics" -constraints {
37    cookiejar
38} -returnCodes error -body {
39    http::cookiejar
40} -result {wrong # args: should be "http::cookiejar method ?arg ...?"}
41test http-cookiejar-2.2 "cookie storage: basics" -constraints {
42    cookiejar
43} -returnCodes error -body {
44    http::cookiejar ?
45} -result {unknown method "?": must be configure, create, destroy or new}
46test http-cookiejar-2.3 "cookie storage: basics" -constraints {
47    cookiejar
48} -body {
49    http::cookiejar configure
50} -result {-domainfile -domainlist -domainrefresh -loglevel -offline -purgeold -retain -vacuumtrigger}
51test http-cookiejar-2.4 "cookie storage: basics" -constraints {
52    cookiejar
53} -returnCodes error -body {
54    http::cookiejar configure a b c d e
55} -result {wrong # args: should be "http::cookiejar configure ?optionName? ?optionValue?"}
56test http-cookiejar-2.5 "cookie storage: basics" -constraints {
57    cookiejar
58} -returnCodes error -body {
59    http::cookiejar configure a
60} -result {bad option "a": must be -domainfile, -domainlist, -domainrefresh, -loglevel, -offline, -purgeold, -retain, or -vacuumtrigger}
61test http-cookiejar-2.6 "cookie storage: basics" -constraints {
62    cookiejar
63} -returnCodes error -body {
64    http::cookiejar configure -d
65} -result {ambiguous option "-d": must be -domainfile, -domainlist, -domainrefresh, -loglevel, -offline, -purgeold, -retain, or -vacuumtrigger}
66test http-cookiejar-2.7 "cookie storage: basics" -setup {
67    set old [http::cookiejar configure -loglevel]
68} -constraints {cookiejar} -body {
69    list [http::cookiejar configure -loglevel] \
70	[http::cookiejar configure -loglevel debug] \
71	[http::cookiejar configure -loglevel] \
72	[http::cookiejar configure -loglevel error] \
73	[http::cookiejar configure -loglevel]
74} -cleanup {
75    http::cookiejar configure -loglevel $old
76} -result {info debug debug error error}
77test http-cookiejar-2.8 "cookie storage: basics" -setup {
78    set old [http::cookiejar configure -loglevel]
79} -constraints {cookiejar} -body {
80    list [http::cookiejar configure -loglevel] \
81	[http::cookiejar configure -loglevel d] \
82	[http::cookiejar configure -loglevel i] \
83	[http::cookiejar configure -loglevel w] \
84	[http::cookiejar configure -loglevel e]
85} -cleanup {
86    http::cookiejar configure -loglevel $old
87} -result {info debug info warn error}
88test http-cookiejar-2.9 "cookie storage: basics" -body {
89    http::cookiejar configure -off
90} -constraints {cookiejar} -match glob -result *
91test http-cookiejar-2.10 "cookie storage: basics" -setup {
92    set oldval [http::cookiejar configure -offline]
93} -constraints {cookiejar} -body {
94    http::cookiejar configure -offline true
95} -cleanup {
96    catch {http::cookiejar configure -offline $oldval}
97} -result 1
98test http-cookiejar-2.11 "cookie storage: basics" -setup {
99    set oldval [http::cookiejar configure -offline]
100} -constraints {cookiejar} -body {
101    http::cookiejar configure -offline nonbool
102} -cleanup {
103    catch {http::cookiejar configure -offline $oldval}
104} -returnCodes error -result {expected boolean value but got "nonbool"}
105test http-cookiejar-2.12 "cookie storage: basics" -setup {
106    set oldval [http::cookiejar configure -purgeold]
107} -constraints {cookiejar} -body {
108    http::cookiejar configure -purge nonint
109} -cleanup {
110    catch {http::cookiejar configure -purgeold $oldval}
111} -returnCodes error -result {expected positive integer but got "nonint"}
112test http-cookiejar-2.13 "cookie storage: basics" -setup {
113    set oldval [http::cookiejar configure -domainrefresh]
114} -constraints {cookiejar} -body {
115    http::cookiejar configure -domainref nonint
116} -cleanup {
117    catch {http::cookiejar configure -domainrefresh $oldval}
118} -returnCodes error -result {expected positive integer but got "nonint"}
119test http-cookiejar-2.14 "cookie storage: basics" -setup {
120    set oldval [http::cookiejar configure -domainrefresh]
121} -constraints {cookiejar} -body {
122    http::cookiejar configure -domainref -42
123} -cleanup {
124    catch {http::cookiejar configure -domainrefresh $oldval}
125} -returnCodes error -result {expected positive integer but got "-42"}
126test http-cookiejar-2.15 "cookie storage: basics" -setup {
127    set oldval [http::cookiejar configure -domainrefresh]
128    set result unset
129    set tracer [http::cookiejar create tracer]
130} -constraints {cookiejar} -body {
131    oo::objdefine $tracer method PostponeRefresh {} {
132	set ::result set
133	next
134    }
135    http::cookiejar configure -domainref 12345
136    return $result
137} -cleanup {
138    $tracer destroy
139    catch {http::cookiejar configure -domainrefresh $oldval}
140} -result set
141
142test http-cookiejar-3.1 "cookie storage: class" {cookiejar} {
143    info object isa object http::cookiejar
144} 1
145test http-cookiejar-3.2 "cookie storage: class" {cookiejar} {
146    info object isa class http::cookiejar
147} 1
148test http-cookiejar-3.3 "cookie storage: class" {cookiejar} {
149    lsort [info object methods http::cookiejar]
150} {configure}
151test http-cookiejar-3.4 "cookie storage: class" {cookiejar} {
152    lsort [info object methods http::cookiejar -all]
153} {configure create destroy new}
154test http-cookiejar-3.5 "cookie storage: class" -setup {
155    catch {rename ::cookiejar ""}
156} -constraints {cookiejar} -body {
157    namespace eval :: {http::cookiejar create cookiejar}
158} -cleanup {
159    catch {rename ::cookiejar ""}
160} -result ::cookiejar
161test http-cookiejar-3.6 "cookie storage: class" -setup {
162    catch {rename ::cookiejar ""}
163} -constraints {cookiejar} -body {
164    list [http::cookiejar create ::cookiejar] [info commands ::cookiejar] \
165	    [::cookiejar destroy] [info commands ::cookiejar]
166} -cleanup {
167    catch {rename ::cookiejar ""}
168} -result {::cookiejar ::cookiejar {} {}}
169test http-cookiejar-3.7 "cookie storage: class" -setup {
170    catch {rename ::cookiejar ""}
171} -constraints {cookiejar} -body {
172    http::cookiejar create ::cookiejar foo bar
173} -returnCodes error -cleanup {
174    catch {rename ::cookiejar ""}
175} -result {wrong # args: should be "http::cookiejar create ::cookiejar ?path?"}
176test http-cookiejar-3.8 "cookie storage: class" -setup {
177    catch {rename ::cookiejar ""}
178    set f [makeFile "" cookiejar]
179    file delete $f
180} -constraints {cookiejar} -body {
181    list [file exists $f] [http::cookiejar create ::cookiejar $f] \
182	[file exists $f]
183} -cleanup {
184    catch {rename ::cookiejar ""}
185    removeFile $f
186} -result {0 ::cookiejar 1}
187test http-cookiejar-3.9 "cookie storage: class" -setup {
188    catch {rename ::cookiejar ""}
189    set f [makeFile "bogus content for a database" cookiejar]
190} -constraints {cookiejar} -body {
191    http::cookiejar create ::cookiejar $f
192} -returnCodes error -cleanup {
193    catch {rename ::cookiejar ""}
194    removeFile $f
195} -match glob -result *
196test http-cookiejar-3.10 "cookie storage: class" -setup {
197    catch {rename ::cookiejar ""}
198    set dir [makeDirectory cookiejar]
199} -constraints {cookiejar} -body {
200    http::cookiejar create ::cookiejar $dir
201} -returnCodes error -cleanup {
202    catch {rename ::cookiejar ""}
203    removeDirectory $dir
204} -match glob -result *
205
206test http-cookiejar-4.1 "cookie storage: instance" -setup {
207    http::cookiejar create ::cookiejar
208} -constraints {cookiejar} -body {
209    cookiejar
210} -returnCodes error -cleanup {
211    ::cookiejar destroy
212} -result {wrong # args: should be "cookiejar method ?arg ...?"}
213test http-cookiejar-4.2 "cookie storage: instance" -setup {
214    http::cookiejar create ::cookiejar
215} -constraints {cookiejar} -body {
216    cookiejar ?
217} -returnCodes error -cleanup {
218    ::cookiejar destroy
219} -result {unknown method "?": must be destroy, forceLoadDomainData, getCookies, lookup, policyAllow or storeCookie}
220test http-cookiejar-4.3 "cookie storage: instance" -setup {
221    http::cookiejar create ::cookiejar
222} -constraints {cookiejar} -body {
223    lsort [info object methods cookiejar -all]
224} -cleanup {
225    ::cookiejar destroy
226} -result {destroy forceLoadDomainData getCookies lookup policyAllow storeCookie}
227test http-cookiejar-4.4 "cookie storage: instance" -setup {
228    http::cookiejar create ::cookiejar
229} -constraints {cookiejar} -body {
230    cookiejar getCookies
231} -returnCodes error -cleanup {
232    ::cookiejar destroy
233} -result {wrong # args: should be "cookiejar getCookies proto host path"}
234test http-cookiejar-4.5 "cookie storage" -setup {
235    http::cookiejar create ::cookiejar
236} -constraints {cookiejar} -body {
237    cookiejar getCookies http www.example.com /
238} -cleanup {
239    ::cookiejar destroy
240} -result {}
241test http-cookiejar-4.6 "cookie storage: instance" -setup {
242    http::cookiejar create ::cookiejar
243} -constraints {cookiejar} -body {
244    cookiejar storeCookie
245} -returnCodes error -cleanup {
246    ::cookiejar destroy
247} -result {wrong # args: should be "cookiejar storeCookie options"}
248test http-cookiejar-4.7 "cookie storage: instance" -setup {
249    http::cookiejar create ::cookiejar
250} -constraints {cookiejar} -body {
251    cookiejar storeCookie {
252	key foo
253	value bar
254	secure 0
255	domain www.example.com
256	origin www.example.com
257	path /
258	hostonly 1
259    }
260} -cleanup {
261    ::cookiejar destroy
262} -result {}
263test http-cookiejar-4.8 "cookie storage: instance" -setup {
264    http::cookiejar create ::cookiejar
265    oo::objdefine ::cookiejar export Database
266} -constraints {cookiejar} -body {
267    cookiejar storeCookie {
268	key foo
269	value bar
270	secure 0
271	domain www.example.com
272	origin www.example.com
273	path /
274	hostonly 1
275    }
276    # Poke inside implementation!
277    cookiejar Database eval {SELECT count(*) FROM sessionCookies}
278} -cleanup {
279    ::cookiejar destroy
280} -result 1
281test http-cookiejar-4.9 "cookie storage: instance" -setup {
282    http::cookiejar create ::cookiejar
283    oo::objdefine ::cookiejar export Database
284} -constraints {cookiejar} -body {
285    cookiejar storeCookie {
286	key foo
287	value bar
288	secure 0
289	domain www.example.com
290	origin www.example.com
291	path /
292	hostonly 1
293    }
294    # Poke inside implementation!
295    cookiejar Database eval {SELECT count(*) FROM persistentCookies}
296} -cleanup {
297    ::cookiejar destroy
298} -result 0
299test http-cookiejar-4.10 "cookie storage: instance" -setup {
300    http::cookiejar create ::cookiejar
301} -constraints {cookiejar} -body {
302    cookiejar storeCookie [dict replace {
303	key foo
304	value bar
305	secure 0
306	domain www.example.com
307	origin www.example.com
308	path /
309	hostonly 1
310    } expires [expr {[clock seconds]+5}]]
311} -cleanup {
312    ::cookiejar destroy
313} -result {}
314test http-cookiejar-4.11 "cookie storage: instance" -setup {
315    http::cookiejar create ::cookiejar
316    oo::objdefine ::cookiejar export Database
317} -constraints {cookiejar} -body {
318    cookiejar storeCookie [dict replace {
319	key foo
320	value bar
321	secure 0
322	domain www.example.com
323	origin www.example.com
324	path /
325	hostonly 1
326    } expires [expr {[clock seconds]+5}]]
327    # Poke inside implementation!
328    cookiejar Database eval {SELECT count(*) FROM sessionCookies}
329} -cleanup {
330    ::cookiejar destroy
331} -result 0
332test http-cookiejar-4.12 "cookie storage: instance" -setup {
333    http::cookiejar create ::cookiejar
334    oo::objdefine ::cookiejar export Database
335} -constraints {cookiejar} -body {
336    cookiejar storeCookie [dict replace {
337	key foo
338	value bar
339	secure 0
340	domain www.example.com
341	origin www.example.com
342	path /
343	hostonly 1
344    } expires [expr {[clock seconds]+5}]]
345    # Poke inside implementation!
346    cookiejar Database eval {SELECT count(*) FROM persistentCookies}
347} -cleanup {
348    ::cookiejar destroy
349} -result 1
350test http-cookiejar-4.13 "cookie storage: instance" -setup {
351    http::cookiejar create ::cookiejar
352    set result {}
353} -constraints {cookiejar} -body {
354    lappend result [cookiejar getCookies http www.example.com /]
355    cookiejar storeCookie {
356	key foo
357	value bar
358	secure 0
359	domain www.example.com
360	origin www.example.com
361	path /
362	hostonly 1
363    }
364    lappend result [cookiejar getCookies http www.example.com /]
365} -cleanup {
366    ::cookiejar destroy
367} -result {{} {foo bar}}
368test http-cookiejar-4.14 "cookie storage: instance" -setup {
369    http::cookiejar create ::cookiejar
370    set result {}
371} -constraints {cookiejar} -body {
372    lappend result [cookiejar getCookies http www.example.com /]
373    cookiejar storeCookie [dict replace {
374	key foo
375	value bar
376	secure 0
377	domain www.example.com
378	origin www.example.com
379	path /
380	hostonly 1
381    } expires [expr {[clock seconds]+5}]]
382    lappend result [cookiejar getCookies http www.example.com /]
383} -cleanup {
384    ::cookiejar destroy
385} -result {{} {foo bar}}
386test http-cookiejar-4.15 "cookie storage: instance" -setup {
387    http::cookiejar create ::cookiejar
388    set result {}
389} -constraints {cookiejar} -body {
390    lappend result [cookiejar getCookies http www.example.com /]
391    cookiejar storeCookie {
392	key foo
393	value bar
394	secure 0
395	domain www.example.com
396	origin www.example.com
397	path /
398	hostonly 1
399    }
400    cookiejar storeCookie [dict replace {
401	key foo
402	value bar
403	secure 0
404	domain www.example.com
405	origin www.example.com
406	path /
407	hostonly 1
408    } expires [expr {[clock seconds]+5}]]
409    lappend result [cookiejar getCookies http www.example.com /]
410} -cleanup {
411    ::cookiejar destroy
412} -result {{} {foo bar}}
413test http-cookiejar-4.16 "cookie storage: instance" -setup {
414    http::cookiejar create ::cookiejar
415    set result {}
416} -constraints {cookiejar} -body {
417    lappend result [cookiejar getCookies http www.example.com /]
418    cookiejar storeCookie {
419	key foo1
420	value bar
421	secure 0
422	domain www.example.com
423	origin www.example.com
424	path /
425	hostonly 1
426    }
427    cookiejar storeCookie [dict replace {
428	key foo2
429	value bar
430	secure 0
431	domain www.example.com
432	origin www.example.com
433	path /
434	hostonly 1
435    } expires [expr {[clock seconds]+5}]]
436    lappend result [lsort -stride 2 [cookiejar getCookies http www.example.com /]]
437} -cleanup {
438    ::cookiejar destroy
439} -result {{} {foo1 bar foo2 bar}}
440test http-cookiejar-4.17 "cookie storage: instance" -setup {
441    http::cookiejar create ::cookiejar
442} -constraints {cookiejar} -body {
443    cookiejar lookup a b c d
444} -returnCodes error -cleanup {
445    ::cookiejar destroy
446} -result {wrong # args: should be "cookiejar lookup ?host? ?key?"}
447test http-cookiejar-4.18 "cookie storage: instance" -setup {
448    http::cookiejar create ::cookiejar
449    set result {}
450} -constraints {cookiejar} -body {
451    lappend result [cookiejar lookup]
452    lappend result [cookiejar lookup www.example.com]
453    lappend result [catch {cookiejar lookup www.example.com foo} value] $value
454    cookiejar storeCookie {
455	key foo
456	value bar
457	secure 0
458	domain www.example.com
459	origin www.example.com
460	path /
461	hostonly 1
462    }
463    lappend result [cookiejar lookup]
464    lappend result [cookiejar lookup www.example.com]
465    lappend result [cookiejar lookup www.example.com foo]
466} -cleanup {
467    ::cookiejar destroy
468} -result {{} {} 1 {no such key for that host} www.example.com foo bar}
469test http-cookiejar-4.19 "cookie storage: instance" -setup {
470    http::cookiejar create ::cookiejar
471    set result {}
472} -constraints {cookiejar} -body {
473    cookiejar storeCookie {
474	key foo
475	value bar
476	secure 0
477	domain www.example.com
478	origin www.example.com
479	path /
480	hostonly 1
481    }
482    cookiejar storeCookie {
483	key bar
484	value foo
485	secure 0
486	domain www.example.org
487	origin www.example.org
488	path /
489	hostonly 1
490    }
491    lappend result [lsort [cookiejar lookup]]
492    lappend result [cookiejar lookup www.example.com]
493    lappend result [cookiejar lookup www.example.com foo]
494    lappend result [cookiejar lookup www.example.org]
495    lappend result [cookiejar lookup www.example.org bar]
496} -cleanup {
497    ::cookiejar destroy
498} -result {{www.example.com www.example.org} foo bar bar foo}
499test http-cookiejar-4.20 "cookie storage: instance" -setup {
500    http::cookiejar create ::cookiejar
501    set result {}
502} -constraints {cookiejar} -body {
503    cookiejar storeCookie {
504	key foo1
505	value bar1
506	secure 0
507	domain www.example.com
508	origin www.example.com
509	path /
510	hostonly 1
511    }
512    cookiejar storeCookie [dict replace {
513	key foo2
514	value bar2
515	secure 0
516	domain www.example.com
517	origin www.example.com
518	path /
519	hostonly 1
520    } expires [expr {[clock seconds]+5}]]
521    lappend result [cookiejar lookup]
522    lappend result [lsort [cookiejar lookup www.example.com]]
523    lappend result [cookiejar lookup www.example.com foo1]
524    lappend result [cookiejar lookup www.example.com foo2]
525} -cleanup {
526    ::cookiejar destroy
527} -result {www.example.com {foo1 foo2} bar1 bar2}
528test http-cookiejar-4.21 "cookie storage: instance" -setup {
529    http::cookiejar create ::cookiejar
530    set result {}
531} -constraints {cookiejar} -body {
532    cookiejar storeCookie {
533	key foo1
534	value bar1
535	secure 0
536	domain www.example.com
537	origin www.example.com
538	path /
539	hostonly 1
540    }
541    cookiejar storeCookie {
542	key foo2
543	value bar2
544	secure 0
545	domain www.example.com
546	origin www.example.com
547	path /
548	hostonly 1
549    }
550    lappend result [cookiejar lookup]
551    lappend result [lsort [cookiejar lookup www.example.com]]
552    lappend result [cookiejar lookup www.example.com foo1]
553    lappend result [cookiejar lookup www.example.com foo2]
554} -cleanup {
555    ::cookiejar destroy
556} -result {www.example.com {foo1 foo2} bar1 bar2}
557test http-cookiejar-4.22 "cookie storage: instance" -setup {
558    http::cookiejar create ::cookiejar
559    set result {}
560} -constraints {cookiejar} -body {
561    cookiejar forceLoadDomainData x y z
562} -returnCodes error -cleanup {
563    ::cookiejar destroy
564} -result {wrong # args: should be "cookiejar forceLoadDomainData"}
565test http-cookiejar-4.23 "cookie storage: instance" -setup {
566    http::cookiejar create ::cookiejar
567    set result {}
568} -constraints {cookiejar} -body {
569    cookiejar forceLoadDomainData
570} -cleanup {
571    ::cookiejar destroy
572} -result {}
573test http-cookiejar-4.23.a {cookie storage: instance} -setup {
574    set off [http::cookiejar configure -offline]
575} -constraints {cookiejar} -body {
576    http::cookiejar configure -offline 1
577    [http::cookiejar create ::cookiejar] destroy
578} -cleanup {
579    catch {::cookiejar destroy}
580    http::cookiejar configure -offline $off
581} -result {}
582test http-cookiejar-4.23.b {cookie storage: instance} -setup {
583    set off [http::cookiejar configure -offline]
584} -constraints {cookiejar} -body {
585    http::cookiejar configure -offline 0
586    [http::cookiejar create ::cookiejar] destroy
587} -cleanup {
588    catch {::cookiejar destroy}
589    http::cookiejar configure -offline $off
590} -result {}
591
592test http-cookiejar-5.1 "cookie storage: constraints" -setup {
593    http::cookiejar create ::cookiejar
594    cookiejar forceLoadDomainData
595} -constraints {cookiejar} -body {
596    cookiejar storeCookie {
597	key foo
598	value bar
599	secure 0
600	domain com
601	origin com
602	path /
603	hostonly 1
604    }
605    cookiejar lookup
606} -cleanup {
607    ::cookiejar destroy
608} -result {}
609test http-cookiejar-5.2 "cookie storage: constraints" -setup {
610    http::cookiejar create ::cookiejar
611    cookiejar forceLoadDomainData
612} -constraints {cookiejar} -body {
613    cookiejar storeCookie {
614	key foo
615	value bar
616	secure 0
617	domain foo.example.com
618	origin bar.example.org
619	path /
620	hostonly 1
621    }
622    cookiejar lookup
623} -cleanup {
624    ::cookiejar destroy
625} -result {}
626test http-cookiejar-5.3 "cookie storage: constraints" -setup {
627    http::cookiejar create ::cookiejar
628    cookiejar forceLoadDomainData
629} -constraints {cookiejar} -body {
630    cookiejar storeCookie {
631	key foo1
632	value bar
633	secure 0
634	domain com
635	origin www.example.com
636	path /
637	hostonly 1
638    }
639    cookiejar storeCookie {
640	key foo2
641	value bar
642	secure 0
643	domain example.com
644	origin www.example.com
645	path /
646	hostonly 1
647    }
648    cookiejar lookup
649} -cleanup {
650    ::cookiejar destroy
651} -result {example.com}
652test http-cookiejar-5.4 "cookie storage: constraints" -setup {
653    http::cookiejar create ::cookiejar
654    cookiejar forceLoadDomainData
655} -constraints {cookiejar} -body {
656    cookiejar storeCookie {
657	key foo
658	value bar1
659	secure 0
660	domain www.example.com
661	origin www.example.com
662	path /
663	hostonly 1
664    }
665    cookiejar storeCookie {
666	key foo
667	value bar2
668	secure 0
669	domain example.com
670	origin www.example.com
671	path /
672	hostonly 1
673    }
674    lsort [cookiejar lookup]
675} -cleanup {
676    ::cookiejar destroy
677} -result {example.com www.example.com}
678test http-cookiejar-5.5 "cookie storage: constraints" -setup {
679    http::cookiejar create ::cookiejar
680    cookiejar forceLoadDomainData
681} -constraints {cookiejar} -body {
682    cookiejar storeCookie {
683	key foo1
684	value 1
685	secure 0
686	domain com
687	origin www.example.com
688	path /
689	hostonly 0
690    }
691    cookiejar storeCookie {
692	key foo2
693	value 2
694	secure 0
695	domain com
696	origin www.example.com
697	path /
698	hostonly 1
699    }
700    cookiejar storeCookie {
701	key foo3
702	value 3
703	secure 0
704	domain example.com
705	origin www.example.com
706	path /
707	hostonly 0
708    }
709    cookiejar storeCookie {
710	key foo4
711	value 4
712	secure 0
713	domain example.com
714	origin www.example.com
715	path /
716	hostonly 1
717    }
718    cookiejar storeCookie {
719	key foo5
720	value 5
721	secure 0
722	domain www.example.com
723	origin www.example.com
724	path /
725	hostonly 0
726    }
727    cookiejar storeCookie {
728	key foo6
729	value 6
730	secure 0
731	domain www.example.com
732	origin www.example.com
733	path /
734	hostonly 1
735    }
736    cookiejar storeCookie {
737	key foo7
738	value 7
739	secure 1
740	domain www.example.com
741	origin www.example.com
742	path /
743	hostonly 0
744    }
745    cookiejar storeCookie {
746	key foo8
747	value 8
748	secure 1
749	domain www.example.com
750	origin www.example.com
751	path /
752	hostonly 1
753    }
754    cookiejar storeCookie {
755	key foo9
756	value 9
757	secure 0
758	domain sub.www.example.com
759	origin www.example.com
760	path /
761	hostonly 1
762    }
763    list [cookiejar getCookies http www.example.com /] \
764	[cookiejar getCookies http www2.example.com /] \
765	[cookiejar getCookies https www.example.com /] \
766	[cookiejar getCookies http sub.www.example.com /]
767} -cleanup {
768    ::cookiejar destroy
769} -result {{foo3 3 foo6 6} {foo3 3} {foo3 3 foo6 6 foo8 8} {foo3 3 foo5 5}}
770
771test http-cookiejar-6.1 "cookie storage: expiry and lookup" -setup {
772    http::cookiejar create ::cookiejar
773    oo::objdefine cookiejar export PurgeCookies
774    set result {}
775    proc values cookies {
776	global result
777	lappend result [lsort [lmap {k v} $cookies {set v}]]
778    }
779} -constraints {cookiejar} -body {
780    values [cookiejar getCookies http www.example.com /]
781    cookiejar storeCookie {
782	key foo
783	value session
784	secure 0
785	domain www.example.com
786	origin www.example.com
787	path /
788	hostonly 1
789    }
790    values [cookiejar getCookies http www.example.com /]
791    cookiejar storeCookie [dict replace {
792	key foo
793	value cookie
794	secure 0
795	domain www.example.com
796	origin www.example.com
797	path /
798	hostonly 1
799    } expires [expr {[clock seconds]+1}]]
800    values [cookiejar getCookies http www.example.com /]
801    cookiejar storeCookie {
802	key foo
803	value session-global
804	secure 0
805	domain example.com
806	origin www.example.com
807	path /
808	hostonly 0
809    }
810    values [cookiejar getCookies http www.example.com /]
811    after 2500
812    update
813    values [cookiejar getCookies http www.example.com /]
814    cookiejar PurgeCookies
815    values [cookiejar getCookies http www.example.com /]
816    cookiejar storeCookie {
817	key foo
818	value go-away
819	secure 0
820	domain example.com
821	origin www.example.com
822	path /
823	hostonly 0
824	expires 0
825    }
826    values [cookiejar getCookies http www.example.com /]
827} -cleanup {
828    ::cookiejar destroy
829} -result {{} session cookie {cookie session-global} {cookie session-global} session-global {}}
830
831test http-cookiejar-7.1 "cookie storage: persistence of persistent cookies" -setup {
832    catch {rename ::cookiejar ""}
833    set f [makeFile "" cookiejar]
834    file delete $f
835} -constraints {cookiejar} -body {
836    http::cookiejar create ::cookiejar $f
837    ::cookiejar destroy
838    http::cookiejar create ::cookiejar $f
839} -cleanup {
840    catch {rename ::cookiejar ""}
841    removeFile $f
842} -result ::cookiejar
843test http-cookiejar-7.2 "cookie storage: persistence of persistent cookies" -setup {
844    catch {rename ::cookiejar ""}
845    set f [makeFile "" cookiejar]
846    file delete $f
847    set result {}
848} -constraints {cookiejar} -body {
849    http::cookiejar create ::cookiejar $f
850    cookiejar storeCookie [dict replace {
851	key foo
852	value cookie
853	secure 0
854	domain www.example.com
855	origin www.example.com
856	path /
857	hostonly 1
858    } expires [expr {[clock seconds]+1}]]
859    lappend result [::cookiejar getCookies http www.example.com /]
860    ::cookiejar destroy
861    http::cookiejar create ::cookiejar
862    lappend result [::cookiejar getCookies http www.example.com /]
863    ::cookiejar destroy
864    http::cookiejar create ::cookiejar $f
865    lappend result [::cookiejar getCookies http www.example.com /]
866} -cleanup {
867    catch {rename ::cookiejar ""}
868    removeFile $f
869} -result {{foo cookie} {} {foo cookie}}
870
871::tcltest::cleanupTests
872
873# Local variables:
874# mode: tcl
875# End:
876