# Commands covered: http::cookiejar
#
# This file contains a collection of tests for the cookiejar package.
# Sourcing this file into Tcl runs the tests and generates output for errors.
# No output means no errors were found.
#
# Copyright (c) 2014 Donal K. Fellows.
#
# See the file "license.terms" for information on usage and redistribution of
# this file, and for a DISCLAIMER OF ALL WARRANTIES.
package require tcltest 2
namespace import -force ::tcltest::*
testConstraint cookiejar [expr {![catch {
package require cookiejar
}]}]
test http-cookiejar-1.1 {cookie storage: packaging} cookiejar {
package require cookiejar
} 0.1
test http-cookiejar-1.2 {cookie storage: packaging} cookiejar {
package require cookiejar
package require cookiejar
} 0.1
test http-cookiejar-2.1 {cookie storage: basics} -constraints cookiejar -body {
http::cookiejar
} -returnCodes error -result {wrong # args: should be "http::cookiejar method ?arg ...?"}
test http-cookiejar-2.2 {cookie storage: basics} -constraints cookiejar -body {
http::cookiejar ?
} -returnCodes error -result {unknown method "?": must be create, destroy, loglevel or new}
test http-cookiejar-2.3 {cookie storage: basics} -constraints cookiejar -body {
http::cookiejar loglevel
} -result info
test http-cookiejar-2.4 {cookie storage: basics} -constraints cookiejar -body {
http::cookiejar loglevel ?
} -returnCodes error -result {bad log level "?": must be debug, info, warn, or error}
test http-cookiejar-2.5 {cookie storage: basics} -constraints cookiejar -body {
http::cookiejar loglevel ? ?
} -returnCodes error -result {wrong # args: should be "http::cookiejar loglevel ?level?"}
test http-cookiejar-2.6 {cookie storage: basics} -setup {
set old [http::cookiejar loglevel]
} -constraints cookiejar -body {
list [http::cookiejar loglevel] [http::cookiejar loglevel debug] \
[http::cookiejar loglevel] [http::cookiejar loglevel error] \
[http::cookiejar loglevel]
} -cleanup {
http::cookiejar loglevel $old
} -result {info debug debug error error}
test http-cookiejar-2.7 {cookie storage: basics} -setup {
set old [http::cookiejar loglevel]
} -constraints cookiejar -body {
list [http::cookiejar loglevel] [http::cookiejar loglevel d] \
[http::cookiejar loglevel i] [http::cookiejar loglevel w] \
[http::cookiejar loglevel e]
} -cleanup {
http::cookiejar loglevel $old
} -result {info debug info warn error}
test http-cookiejar-3.1 {cookie storage: class} cookiejar {
info object isa object http::cookiejar
} 1
test http-cookiejar-3.2 {cookie storage: class} cookiejar {
info object isa class http::cookiejar
} 1
test http-cookiejar-3.3 {cookie storage: class} cookiejar {
lsort [info object methods http::cookiejar]
} loglevel
test http-cookiejar-3.4 {cookie storage: class} cookiejar {
lsort [info object methods http::cookiejar -all]
} {create destroy loglevel new}
test http-cookiejar-3.5 {cookie storage: class} -setup {
catch {rename ::cookiejar ""}
} -constraints cookiejar -body {
namespace eval :: {http::cookiejar create cookiejar}
} -cleanup {
catch {rename ::cookiejar ""}
} -result ::cookiejar
test http-cookiejar-3.6 {cookie storage: class} -setup {
catch {rename ::cookiejar ""}
} -constraints cookiejar -body {
list [http::cookiejar create ::cookiejar] [info commands ::cookiejar] \
[::cookiejar destroy] [info commands ::cookiejar]
} -cleanup {
catch {rename ::cookiejar ""}
} -result {::cookiejar ::cookiejar {} {}}
test http-cookiejar-3.7 {cookie storage: class} -setup {
catch {rename ::cookiejar ""}
} -constraints cookiejar -body {
http::cookiejar create ::cookiejar foo bar
} -returnCodes error -cleanup {
catch {rename ::cookiejar ""}
} -result {wrong # args: should be "http::cookiejar create ::cookiejar ?path?"}
test http-cookiejar-4.1 {cookie storage: instance} -setup {
http::cookiejar create ::cookiejar
} -constraints cookiejar -body {
cookiejar
} -returnCodes error -cleanup {
::cookiejar destroy
} -result {wrong # args: should be "cookiejar method ?arg ...?"}
test http-cookiejar-4.2 {cookie storage: instance} -setup {
http::cookiejar create ::cookiejar
} -constraints cookiejar -body {
cookiejar ?
} -returnCodes error -cleanup {
::cookiejar destroy
} -result {unknown method "?": must be destroy, forceLoadDomainData, getCookies, lookup or storeCookie}
test http-cookiejar-4.3 {cookie storage: instance} -setup {
http::cookiejar create ::cookiejar
} -constraints cookiejar -body {
lsort [info object methods cookiejar -all]
} -cleanup {
::cookiejar destroy
} -result {destroy forceLoadDomainData getCookies lookup storeCookie}
test http-cookiejar-4.4 {cookie storage: instance} -setup {
http::cookiejar create ::cookiejar
} -constraints cookiejar -body {
cookiejar getCookies
} -returnCodes error -cleanup {
::cookiejar destroy
} -result {wrong # args: should be "cookiejar getCookies proto host path"}
test http-cookiejar-4.5 {cookie storage} -setup {
http::cookiejar create ::cookiejar
} -constraints cookiejar -body {
cookiejar getCookies http www.example.com /
} -cleanup {
::cookiejar destroy
} -result {}
test http-cookiejar-4.6 {cookie storage: instance} -setup {
http::cookiejar create ::cookiejar
} -constraints cookiejar -body {
cookiejar storeCookie
} -returnCodes error -cleanup {
::cookiejar destroy
} -result {wrong # args: should be "cookiejar storeCookie name value options"}
test http-cookiejar-4.7 {cookie storage: instance} -setup {
http::cookiejar create ::cookiejar
} -constraints cookiejar -body {
cookiejar storeCookie foo bar {
persistent 0
secure 0
domain www.example.com
origin www.example.com
path /
hostonly 1
}
} -cleanup {
::cookiejar destroy
} -result {}
test http-cookiejar-4.8 {cookie storage: instance} -setup {
http::cookiejar create ::cookiejar
oo::objdefine ::cookiejar export Database
} -constraints cookiejar -body {
cookiejar storeCookie foo bar {
persistent 0
secure 0
domain www.example.com
origin www.example.com
path /
hostonly 1
}
# Poke inside implementation!
cookiejar Database eval {SELECT count(*) FROM sessionCookies}
} -cleanup {
::cookiejar destroy
} -result 1
test http-cookiejar-4.9 {cookie storage: instance} -setup {
http::cookiejar create ::cookiejar
oo::objdefine ::cookiejar export Database
} -constraints cookiejar -body {
cookiejar storeCookie foo bar {
persistent 0
secure 0
domain www.example.com
origin www.example.com
path /
hostonly 1
}
# Poke inside implementation!
cookiejar Database eval {SELECT count(*) FROM persistentCookies}
} -cleanup {
::cookiejar destroy
} -result 0
test http-cookiejar-4.10 {cookie storage: instance} -setup {
http::cookiejar create ::cookiejar
} -constraints cookiejar -body {
cookiejar storeCookie foo bar [dict replace {
persistent 1
secure 0
domain www.example.com
origin www.example.com
path /
hostonly 1
} expires [expr {[clock seconds]+5}]]
} -cleanup {
::cookiejar destroy
} -result {}
test http-cookiejar-4.11 {cookie storage: instance} -setup {
http::cookiejar create ::cookiejar
oo::objdefine ::cookiejar export Database
} -constraints cookiejar -body {
cookiejar storeCookie foo bar [dict replace {
persistent 1
secure 0
domain www.example.com
origin www.example.com
path /
hostonly 1
} expires [expr {[clock seconds]+5}]]
# Poke inside implementation!
cookiejar Database eval {SELECT count(*) FROM sessionCookies}
} -cleanup {
::cookiejar destroy
} -result 0
test http-cookiejar-4.12 {cookie storage: instance} -setup {
http::cookiejar create ::cookiejar
oo::objdefine ::cookiejar export Database
} -constraints cookiejar -body {
cookiejar storeCookie foo bar [dict replace {
persistent 1
secure 0
domain www.example.com
origin www.example.com
path /
hostonly 1
} expires [expr {[clock seconds]+5}]]
# Poke inside implementation!
cookiejar Database eval {SELECT count(*) FROM persistentCookies}
} -cleanup {
::cookiejar destroy
} -result 1
test http-cookiejar-4.13 {cookie storage: instance} -setup {
http::cookiejar create ::cookiejar
set result {}
} -constraints cookiejar -body {
lappend result [cookiejar getCookies http www.example.com /]
cookiejar storeCookie foo bar {
persistent 0
secure 0
domain www.example.com
origin www.example.com
path /
hostonly 1
}
lappend result [cookiejar getCookies http www.example.com /]
} -cleanup {
::cookiejar destroy
} -result {{} {foo bar}}
test http-cookiejar-4.14 {cookie storage: instance} -setup {
http::cookiejar create ::cookiejar
set result {}
} -constraints cookiejar -body {
lappend result [cookiejar getCookies http www.example.com /]
cookiejar storeCookie foo bar [dict replace {
persistent 1
secure 0
domain www.example.com
origin www.example.com
path /
hostonly 1
} expires [expr {[clock seconds]+5}]]
lappend result [cookiejar getCookies http www.example.com /]
} -cleanup {
::cookiejar destroy
} -result {{} {foo bar}}
test http-cookiejar-4.15 {cookie storage: instance} -setup {
http::cookiejar create ::cookiejar
set result {}
} -constraints cookiejar -body {
lappend result [cookiejar getCookies http www.example.com /]
cookiejar storeCookie foo bar {
persistent 0
secure 0
domain www.example.com
origin www.example.com
path /
hostonly 1
}
cookiejar storeCookie foo bar [dict replace {
persistent 1
secure 0
domain www.example.com
origin www.example.com
path /
hostonly 1
} expires [expr {[clock seconds]+5}]]
lappend result [cookiejar getCookies http www.example.com /]
} -cleanup {
::cookiejar destroy
} -result {{} {foo bar}}
test http-cookiejar-4.16 {cookie storage: instance} -setup {
http::cookiejar create ::cookiejar
set result {}
} -constraints cookiejar -body {
lappend result [cookiejar getCookies http www.example.com /]
cookiejar storeCookie foo1 bar {
persistent 0
secure 0
domain www.example.com
origin www.example.com
path /
hostonly 1
}
cookiejar storeCookie foo2 bar [dict replace {
persistent 1
secure 0
domain www.example.com
origin www.example.com
path /
hostonly 1
} expires [expr {[clock seconds]+5}]]
lappend result [lsort -stride 2 [cookiejar getCookies http www.example.com /]]
} -cleanup {
::cookiejar destroy
} -result {{} {foo1 bar foo2 bar}}
test http-cookiejar-4.17 {cookie storage: instance} -setup {
http::cookiejar create ::cookiejar
} -constraints cookiejar -body {
cookiejar lookup a b c d
} -returnCodes error -cleanup {
::cookiejar destroy
} -result {wrong # args: should be "cookiejar lookup ?host? ?key?"}
test http-cookiejar-4.18 {cookie storage: instance} -setup {
http::cookiejar create ::cookiejar
set result {}
} -constraints cookiejar -body {
lappend result [cookiejar lookup]
lappend result [cookiejar lookup www.example.com]
lappend result [catch {cookiejar lookup www.example.com foo} value] $value
cookiejar storeCookie foo bar {
persistent 0
secure 0
domain www.example.com
origin www.example.com
path /
hostonly 1
}
lappend result [cookiejar lookup]
lappend result [cookiejar lookup www.example.com]
lappend result [cookiejar lookup www.example.com foo]
} -cleanup {
::cookiejar destroy
} -result {{} {} 1 {no such key for that host} www.example.com foo bar}
test http-cookiejar-4.19 {cookie storage: instance} -setup {
http::cookiejar create ::cookiejar
set result {}
} -constraints cookiejar -body {
cookiejar storeCookie foo bar {
persistent 0
secure 0
domain www.example.com
origin www.example.com
path /
hostonly 1
}
cookiejar storeCookie bar foo {
persistent 0
secure 0
domain www.example.org
origin www.example.org
path /
hostonly 1
}
lappend result [lsort [cookiejar lookup]]
lappend result [cookiejar lookup www.example.com]
lappend result [cookiejar lookup www.example.com foo]
lappend result [cookiejar lookup www.example.org]
lappend result [cookiejar lookup www.example.org bar]
} -cleanup {
::cookiejar destroy
} -result {{www.example.com www.example.org} foo bar bar foo}
test http-cookiejar-4.20 {cookie storage: instance} -setup {
http::cookiejar create ::cookiejar
set result {}
} -constraints cookiejar -body {
cookiejar storeCookie foo1 bar1 {
persistent 0
secure 0
domain www.example.com
origin www.example.com
path /
hostonly 1
}
cookiejar storeCookie foo2 bar2 [dict replace {
persistent 1
secure 0
domain www.example.com
origin www.example.com
path /
hostonly 1
} expires [expr {[clock seconds]+5}]]
lappend result [cookiejar lookup]
lappend result [lsort [cookiejar lookup www.example.com]]
lappend result [cookiejar lookup www.example.com foo1]
lappend result [cookiejar lookup www.example.com foo2]
} -cleanup {
::cookiejar destroy
} -result {www.example.com {foo1 foo2} bar1 bar2}
test http-cookiejar-4.21 {cookie storage: instance} -setup {
http::cookiejar create ::cookiejar
set result {}
} -constraints cookiejar -body {
cookiejar storeCookie foo1 bar1 {
persistent 0
secure 0
domain www.example.com
origin www.example.com
path /
hostonly 1
}
cookiejar storeCookie foo2 bar2 {
persistent 0
secure 0
domain www.example.com
origin www.example.com
path /
hostonly 1
}
lappend result [cookiejar lookup]
lappend result [lsort [cookiejar lookup www.example.com]]
lappend result [cookiejar lookup www.example.com foo1]
lappend result [cookiejar lookup www.example.com foo2]
} -cleanup {
::cookiejar destroy
} -result {www.example.com {foo1 foo2} bar1 bar2}
test http-cookiejar-4.22 {cookie storage: instance} -setup {
http::cookiejar create ::cookiejar
set result {}
} -constraints cookiejar -body {
cookiejar forceLoadDomainData x y z
} -returnCodes error -cleanup {
::cookiejar destroy
} -result {wrong # args: should be "cookiejar forceLoadDomainData"}
test http-cookiejar-4.23 {cookie storage: instance} -setup {
http::cookiejar create ::cookiejar
set result {}
} -constraints cookiejar -body {
cookiejar forceLoadDomainData
} -cleanup {
::cookiejar destroy
} -result {}
test http-cookiejar-5.1 {cookie storage: constraints} -setup {
http::cookiejar create ::cookiejar
} -constraints cookiejar -body {
cookiejar forceLoadDomainData
cookiejar storeCookie foo bar {
persistent 0
secure 0
domain com
origin com
path /
hostonly 1
}
cookiejar lookup
} -cleanup {
::cookiejar destroy
} -result {}
test http-cookiejar-5.2 {cookie storage: constraints} -setup {
http::cookiejar create ::cookiejar
} -constraints cookiejar -body {
cookiejar forceLoadDomainData
cookiejar storeCookie foo bar {
persistent 0
secure 0
domain foo.example.com
origin bar.example.org
path /
hostonly 1
}
cookiejar lookup
} -cleanup {
::cookiejar destroy
} -result {}
test http-cookiejar-5.3 {cookie storage: constraints} -setup {
http::cookiejar create ::cookiejar
} -constraints cookiejar -body {
cookiejar forceLoadDomainData
cookiejar storeCookie foo1 bar {
persistent 0
secure 0
domain com
origin www.example.com
path /
hostonly 1
}
cookiejar storeCookie foo2 bar {
persistent 0
secure 0
domain example.com
origin www.example.com
path /
hostonly 1
}
cookiejar lookup
} -cleanup {
::cookiejar destroy
} -result {example.com}
::tcltest::cleanupTests
# Local variables:
# mode: tcl
# End: