1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
|
source [file join \
[file dirname [file dirname [file join [pwd] [info script]]]] \
devtools testutilities.tcl]
testsNeedTcl 8.5
testsNeedTcltest 2.0
# Constraints depending on package availability
tcltest::testConstraint have_tls [expr {![catch {package require tls}]}]
tcltest::testConstraint have_twapi [expr {![catch {package require twapi}]}]
puts "- have_tls = [expr {![catch {package require tls}]}]"
puts "- have_twapi = [expr {![catch {package require twapi}]}]"
# uri and base64
testing {
useLocal autoproxy.tcl autoproxy
}
# May need to change these to your proxy
set proxy_host 147.135.210.114
set proxy_port 54566
# Clear the autoproxy package state for each test
proc packageReset {} {
array set ::autoproxy::options {
authProc "" basic "" no_proxy "" proxy_host "" proxy_port ""
tls_package tls
}
}
test autoproxy-1.0.0 "autoproxy::init standard" -setup {
packageReset
} -body {
autoproxy::init http://localhost:13128 "hosta,hostb"
list [autoproxy::cget -host] \
[autoproxy::cget -port] \
[autoproxy::cget -no_proxy]
} -result {localhost 13128 {hosta hostb}}
test autoproxy-1.0.1 "autoproxy::init standard, auth" -setup {
packageReset
} -body {
autoproxy::init http://user:secret@localhost:13128 "hosta,hostb"
list [autoproxy::cget -host] \
[autoproxy::cget -port] \
[autoproxy::cget -no_proxy] \
[base64::decode [lindex [autoproxy::cget -basic] 1 1]]
} -result {localhost 13128 {hosta hostb} user:secret}
test autoproxy-1.0.2 "autoproxy::init standard, override" -setup {
packageReset
} -body {
autoproxy::init http://proxyone:13128 "hosta,hostb"
autoproxy::init http://proxytwo:13129 "hostc,hostd"
list [autoproxy::cget -host] \
[autoproxy::cget -port] \
[autoproxy::cget -no_proxy]
} -result {proxytwo 13129 {hostc hostd}}
test autoproxy-1.0.3 "autoproxy::init standard, auth, override" -setup {
packageReset
} -body {
autoproxy::init http://user:secret@localhost:13128 "hosta,hostb"
autoproxy::init http://luser:passwd@proxy:13129 "hostc,hostd"
list [autoproxy::cget -host] \
[autoproxy::cget -port] \
[autoproxy::cget -no_proxy] \
[base64::decode [lindex [autoproxy::cget -basic] 1 1]]
} -result {proxy 13129 {hostc hostd} luser:passwd}
test autoproxy-1.0.4 "autoproxy::init standard, colons" -setup {
packageReset
} -body {
autoproxy::init http://localhost:13128 "hosta;hostb"
list [autoproxy::cget -host] \
[autoproxy::cget -port] \
[autoproxy::cget -no_proxy]
} -result {localhost 13128 {hosta hostb}}
test autoproxy-1.1.0 "autoproxy::configure -host" -setup {
packageReset
} -body {
autoproxy::configure -host proxyhost
autoproxy::cget -host
} -result {proxyhost}
test autoproxy-1.1.1 "autoproxy::configure -port" -setup {
packageReset
} -body {
autoproxy::configure -port 3128
autoproxy::cget -port
} -result {3128}
test autoproxy-1.1.2 "autoproxy::configure -proxy_host" -setup {
packageReset
} -body {
autoproxy::configure -proxy_host proxyhost
autoproxy::cget -proxy_host
} -result {proxyhost}
test autoproxy-1.1.3 "autoproxy::configure -proxy_port" -setup {
packageReset
} -body {
autoproxy::configure -proxy_port 3128
autoproxy::cget -proxy_port
} -result {3128}
test autoproxy-1.1.4 "autoproxy::configure -no_proxy" -setup {
packageReset
} -body {
autoproxy::configure -no_proxy "localhost otherhost"
autoproxy::cget -no_proxy
} -result {localhost otherhost}
test autoproxy-1.1.5 "autoproxy::configure -no_proxy override" -setup {
packageReset
} -body {
autoproxy::configure -no_proxy "localhost otherhost"
autoproxy::configure -no_proxy "althost"
autoproxy::cget -no_proxy
} -result {althost}
test autoproxy-1.1.6 "autoproxy::configure -authProc" -setup {
packageReset
} -body {
autoproxy::configure -authProc my_auth_proc
autoproxy::cget -authProc
} -result {my_auth_proc}
test autoproxy-1.2.0 "autoproxy::configure -basic set details" -setup {
packageReset
} -body {
autoproxy::configure -basic -user test -password secret -realm tcllib
autoproxy::cget -basic
} -result {Proxy-Authorization {Basic dGVzdDpzZWNyZXQ=}}
test autoproxy-1.2.1 "autoproxy::configure -basic confirm encoding" -setup {
packageReset
} -body {
autoproxy::configure -basic -user test -password secret -realm tcllib
base64::decode [lindex [autoproxy::cget -basic] 1 1]
} -result {test:secret}
test autoproxy-1.2.2 "autoproxy::configure -basic reset" -setup {
packageReset
autoproxy::configure -basic -user test -password secret -realm tcllib
} -body {
autoproxy::configure -basic --
autoproxy::cget -basic
} -result {}
test autoproxy-1.2.3 "autoproxy::configure -basic reset (2)" -setup {
packageReset
autoproxy::configure -basic -user test -password secret -realm tcllib
} -body {
autoproxy::configure -basic
autoproxy::cget -basic
} -result {}
test autoproxy-1.2.4.0 "autoproxy::configure -tls_package tls" -setup {
packageReset
} -body {
autoproxy::configure -tls_package tls
autoproxy::cget -tls_package
} -result tls
test autoproxy-1.2.4.1 "autoproxy::configure -tls_package twapi" -setup {
packageReset
} -body {
autoproxy::configure -tls_package twapi
autoproxy::cget -tls_package
} -result twapi
test autoproxy-1.2.4.2 "autoproxy::configure -tls_package dummy" -setup {
packageReset
} -body {
autoproxy::configure -tls_package dummy
} -result "Invalid TLS package option 'dummy'. Must be 'tls' or 'twapi'" -returnCodes error
test autoproxy-2.0.0 "autoproxy::tls_socket (tls) with proxy" -constraints {
have_tls
} -setup {
packageReset
package require http
autoproxy::configure -proxy_host $proxy_host -proxy_port $proxy_port
} -body {
http::register https 443 autoproxy::tls_socket
set tok [http::geturl https://www.example.com]
http::status $tok
} -cleanup {
http::cleanup $tok
} -result ok
test autoproxy-2.0.1 "autoproxy::tls_socket (twapi) with proxy" -constraints {
have_twapi
} -setup {
packageReset
package require http
autoproxy::configure -proxy_host $proxy_host -proxy_port $proxy_port -tls_package twapi
} -body {
http::register https 443 autoproxy::tls_socket
set tok [http::geturl https://www.example.com]
http::status $tok
} -cleanup {
http::cleanup $tok
} -result ok
test autoproxy-2.1.0 "autoproxy::tls_socket (tls) without proxy" -constraints {
have_tls
} -setup {
packageReset
package require http
autoproxy::configure -proxy_host "" -proxy_port $proxy_port
} -body {
http::register https 443 autoproxy::tls_socket
set tok [http::geturl https://www.example.com]
http::status $tok
} -cleanup {
http::cleanup $tok
} -result ok
test autoproxy-2.1.1 "autoproxy::tls_socket (twapi) without proxy" -constraints {
have_twapi
} -setup {
packageReset
package require http
autoproxy::configure -proxy_host "" -proxy_port $proxy_port -tls_package twapi
} -body {
http::register https 443 autoproxy::tls_socket
set tok [http::geturl https://www.example.com]
http::status $tok
} -cleanup {
http::cleanup $tok
} -result ok
testsuiteCleanup
# Local variables:
# mode: tcl
# indent-tabs-mode: nil
# End:
|