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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485
  
     | 
    
      # Tests for the uri module.
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright (c) 2000 by Zveno Pty Ltd.
#
# RCS: @(#) $Id: uri.test,v 1.25 2011/03/23 04:39:54 andreas_kupries Exp $
# -------------------------------------------------------------------------
source [file join \
	[file dirname [file dirname [file join [pwd] [info script]]]] \
	devtools testutilities.tcl]
testsNeedTcl     8.2
testsNeedTcltest 1.0
testing {
    useLocal uri.tcl uri
}
# -------------------------------------------------------------------------
# Split tests
test uri-1.0 {uri::split - http w/- nested query} {
    dictsort [uri::split http://test.net/path/path2?query=url?otherquery]
} {fragment {} host test.net path path/path2 port {} pwd {} query query=url?otherquery scheme http user {}}
test uri-1.1 {uri::split - http w/- query} {
    dictsort [uri::split http://test.net/path/path2?query]
} {fragment {} host test.net path path/path2 port {} pwd {} query query scheme http user {}}
test uri-1.2 {uri::split - https w/- query} {
    dictsort [uri::split https://test.net/path/path2?query]
} {fragment {} host test.net path path/path2 port {} pwd {} query query scheme https user {}}
test uri-1.3 {uri::split - http w/- port} {
    dictsort [uri::split http://test.net:8080]
} {fragment {} host test.net path {} port 8080 pwd {} query {} scheme http user {}}
test uri-1.4 {uri::split - https w/- port} {
    dictsort [uri::split https://test.net:8888]
} {fragment {} host test.net path {} port 8888 pwd {} query {} scheme https user {}}
test uri-1.5 {uri::split - ftp} {
    dictsort [uri::split ftp://ftp.test.net/path/to/resource]
} {host ftp.test.net path path/to/resource port {} pwd {} scheme ftp type {} user {}}
test uri-1.6 {uri::split - ftp with userinfo} {
    dictsort [uri::split {ftp://user:passwd@localhost/a/b/c.d}]
} {host localhost path a/b/c.d port {} pwd passwd scheme ftp type {} user user}
test uri-1.7 {uri::split - ftp with type} {
    dictsort [uri::split {ftp://localhost/a/b/c.d;type=i}]
} {host localhost path a/b/c.d port {} pwd {} scheme ftp type i user {}}
test uri-1.8 {uri::split - ftp with port} {
    dictsort [uri::split {ftp://localhost:21/a/b/c.d}]
} {host localhost path a/b/c.d port 21 pwd {} scheme ftp type {} user {}}
test uri-1.9 {uri::split - news with message-id} {
    dictsort [uri::split {news:87lm40t3v7.fsf@dedasys.com}]
} {message-id 87lm40t3v7.fsf@dedasys.com scheme news}
test uri-1.10 {uri::split - news with newsgroup-name} {
    dictsort [uri::split {news:comp.lang.tcl}]
} {newsgroup-name comp.lang.tcl scheme news}
test uri-1.11 {uri::split - ldap simple} {
    dictsort [uri::split {ldap://ldaphost}]
} {attrs {} dn {} extensions {} filter {} host ldaphost port {} scheme ldap scope {}}
test uri-1.12 {uri::split - ldaps with port} {
    dictsort [uri::split {ldaps://h:636/}]
} {attrs {} dn {} extensions {} filter {} host h port 636 scheme ldaps scope {}}
test uri-1.13 {uri::split - ldap search} {
    dictsort [uri::split {ldap://ldaphost/o=mycomp?uid,mail?sub?(uid=pda)}]
} {attrs {uid mail} dn o=mycomp extensions {} filter (uid=pda) host ldaphost port {} scheme ldap scope sub}
test uri-1.14 {uri::split - ldap search with implicit scope an attributes} {
    dictsort [uri::split {ldap://ldaphost:999/o=mycomp???(uid=pda)}]
} {attrs {} dn o=mycomp extensions {} filter (uid=pda) host ldaphost port 999 scheme ldap scope {}}
# -------------------------------------------------------------------------
test uri-2.1 {uri::join - http} {
    uri::join scheme http path / host www.w3.org
} http://www.w3.org/
test uri-2.2 {uri::join - https} {
    uri::join scheme https path / host www.w3.org
} https://www.w3.org/
test uri-2.3 {uri::join - http w/- query} {
    uri::join scheme http query abc=def&ghi=jkl host www.test.net path /path/
} http://www.test.net/path/?abc=def&ghi=jkl
test uri-2.4 {uri::join - https w/- query} {
    uri::join scheme https query abc=def&ghi=jkl host www.test.net path /path/
} https://www.test.net/path/?abc=def&ghi=jkl
test uri-2.5 {uri::join - http w/- port} {
    uri::join scheme http port 8080 host www.test.net path /path/
} http://www.test.net:8080/path/
test uri-2.6 {uri::join - https w/- port} {
    uri::join scheme https port 8888 host www.test.net path /path/
} https://www.test.net:8888/path/
test uri-2.7 {uri::join - ftp} {
    uri::join host ftp.test.net path /my/file scheme ftp
} ftp://ftp.test.net/my/file
test uri-2.8 {uri::join - identity function} {
    eval uri::join [uri::split http://www.w3.org/XML/?abc=def]
} http://www.w3.org/XML/?abc=def
test uri-2.9 {uri::join - ftp userinfo check} {
    eval uri::join scheme ftp host localhost port 21 path /filename user user pwd passwd
} {ftp://user:passwd@localhost:21/filename}
test uri-2.10 {uri::join - ftp userinfo check with no passwd} {
    eval uri::join scheme ftp host localhost path /filename user user
} {ftp://user@localhost/filename}
test uri-2.11 {uri::join - ftp path prefix} {
    eval uri::join scheme ftp host localhost path a/b/c.d
} ftp://localhost/a/b/c.d
test uri-2.12 {uri::join - ftp w/- image type} {
    eval uri::join scheme ftp host localhost path a/b/c.d type i
} {ftp://localhost/a/b/c.d;type=i}
test uri-2.13 {uri::join - ftp w/- ascii type} {
    eval uri::join scheme ftp host localhost path a/b/c.d type a
} {ftp://localhost/a/b/c.d;type=a}
# I am not sure that this shouldn't produce an error. The semi-colon is 
# reserved so in this case with an invalid suffix the semi-colon should
# probably be quoted. [PT]
test uri-2.14 {uri::join - ftp w/- invalid type} {
    eval uri::join scheme ftp host localhost path a/b/c.d type X
} {ftp://localhost/a/b/c.d;type=X}
test uri-2.15 {uri::join - news message-id} {
    eval uri::join scheme news message-id 87lm40t3v7.fsf@dedasys.com
} {news:87lm40t3v7.fsf@dedasys.com}
test uri-2.16 {uri::join - news newsgroup-name} {
    eval uri::join scheme news newsgroup-name comp.lang.tcl
} {news:comp.lang.tcl}
test uri-2.17 {uri::join - ldap simple} {
    uri::join scheme ldap host ldaphost
} {ldap://ldaphost}
test uri-2.18 {uri::join - ldaps with default port} {
    uri::join scheme ldaps host ldaphost port 636
} {ldaps://ldaphost}
test uri-2.19 {uri::join - ldaps with port} {
    uri::join scheme ldaps host ldaphost port 999
} {ldaps://ldaphost:999}
test uri-2.20 {uri::join - ldap search} {
    # I should use "attrs {uid mail}" and not "attrs uid,mail"
    # but this is a perverse effect of the "eval" command
    uri::join attrs uid,mail dn o=mycomp filter (uid=pda) host ldaphost scheme ldap scope sub
} {ldap://ldaphost/o=mycomp?uid,mail?sub?(uid=pda)}
test uri-2.21 {uri::join - ldap search with implicit scope an attributes} {
    uri::join dn o=mycomp filter (uid=pda) host ldaphost port 999 scheme ldap
} {ldap://ldaphost:999/o=mycomp???(uid=pda)}
# -------------------------------------------------------------------------
test uri-3.1 {uri::resolve - relative URL, base trailing slash} {
    uri::resolve http://www.w3.org/path/ test.html
} http://www.w3.org/path/test.html
test uri-3.2 {uri::resolve - relative URL path, base trailing slash} {
    uri::resolve http://www.w3.org/path/ relpath/test.html
} http://www.w3.org/path/relpath/test.html
test uri-3.3 {uri::resolve - relative URL, base no trailing slash} {
    uri::resolve http://www.w3.org/path test.html
} http://www.w3.org/test.html
test uri-3.4 {uri::resolve - relative URL path, base no trailing slash} {
    uri::resolve http://www.w3.org/path relpath/test.html
} http://www.w3.org/relpath/test.html
test uri-3.5 {uri::resolve - relative URL w/- query} {
    uri::resolve http://www.w3.org/path/ test.html?abc=def
} http://www.w3.org/path/test.html?abc=def
test uri-3.6 {uri::resolve - absolute URL} {
    uri::resolve http://www.w3.org/path/ http://test.net/test.html
} http://test.net/test.html
test uri-3.7 {uri::resolve - two queries - one sans path} {
    uri::resolve http://www.example.com/foo/bar.rvt?foo=bar ?shoo=bee
} http://www.example.com/foo/bar.rvt?shoo=bee
test uri-3.8 {uri::resolve - two queries} {
    uri::resolve http://www.example.com/baz/?foo=bar ?shoo=bee
} http://www.example.com/baz/?shoo=bee
test uri-3.9 {uri::resolve - two absolute URL's with queries} {
    uri::resolve http://www.example.com/?foo=bar http://www.example.com/?shoo=bee
} http://www.example.com/?shoo=bee
test uri-3.10 {uri::resolve - two queries,
    one absolute URL, one absolute path} {
    uri::resolve http://www.example.com/baz?foo=bar /baz?shoo=bee
} http://www.example.com/baz?shoo=bee
# -------------------------------------------------------------------------
test uri-4.1 {uri::geturl} {
    set data [info commands]
    set file [makeFile {} __testdata]
    set f [open $file w]
    puts -nonewline $f $data
    close $f
    set token [uri::geturl file://$file]
    removeFile __testdata
    string compare $data [set [subst $token](data)]
} 0
# -------------------------------------------------------------------------
test uri-5.1-0 {uri::canonicalize} {
    uri::canonicalize http://www.test.net/path1/./remove/../path2/resource
} http://www.test.net/path1/path2/resource
test uri-5.2-0 {uri::canonicalize infinite loop} {
    uri::canonicalize http://www.test.net/../path2/resource
} {http://www.test.net/path2/resource}
test uri-5.3-0 {uri::canonicalize} {
    uri::canonicalize http://www.test.net/./path1/./remove/../path2/../resource
} http://www.test.net/path1/resource
test uri-5.4-0 {uri::canonicalize} {
    uri::canonicalize http://www.test.net/./././path1/./remove/../path2/../resource
} http://www.test.net/path1/resource
test uri-5.5-0 {uri::canonicalize} {
    uri::canonicalize http://www.test.net/./././path1/./remove/path2/../../resource
} http://www.test.net/path1/resource
test uri-5.6-0 {uri::canonicalize infinite loop} {
    uri::canonicalize http://www.test.net/../../../path2/resource
} {http://www.test.net/path2/resource}
test uri-5.7-0 {uri::canonicalize} {
    uri::canonicalize http://www.test.net/path1/./remove/../path.html/resource
} http://www.test.net/path1/path.html/resource
test uri-5.8-0 {uri::canonicalize infinite loop} {
    uri::canonicalize http://www.test.net/../path.html/resource
} {http://www.test.net/path.html/resource}
test uri-5.9-0 {uri::canonicalize} {
    uri::canonicalize http://www.test.net/./path1/./remove/../path.html/../resource
} http://www.test.net/path1/resource
test uri-5.10-0 {uri::canonicalize} {
    uri::canonicalize http://www.test.net/./././path1/./remove/../path.html/../resource
} http://www.test.net/path1/resource
test uri-5.11-0 {uri::canonicalize} {
    uri::canonicalize http://www.test.net/./././path1/./remove/path.html/../../resource
} http://www.test.net/path1/resource
test uri-5.12-0 {uri::canonicalize infinite loop} {
    uri::canonicalize http://www.test.net/../../../path.html/resource
} {http://www.test.net/path.html/resource}
test uri-5.13-0 {uri::canonicalize} {
    uri::canonicalize http://www.eldritchpress.org/jc/../help.html
} {http://www.eldritchpress.org/help.html}
test uri-5.14-0 {uri::canonicalize trailing ..} {
    uri::canonicalize http://www.example.com/foo/bar/..
} {http://www.example.com/foo/}
test uri-5.15-0 {uri::canonicalize trailing ..} {
    uri::canonicalize http://www.example.com/..
} {http://www.example.com/}
test uri-5.1-1 {uri::canonicalize} {
    uri::canonicalize ftp://ftp.test.net/path1/./remove/../path2/resource
} ftp://ftp.test.net/path1/path2/resource
test uri-5.2-1 {uri::canonicalize infinite loop} {
    uri::canonicalize ftp://ftp.test.net/../path2/resource
} {ftp://ftp.test.net/path2/resource}
test uri-5.3-1 {uri::canonicalize} {
    uri::canonicalize ftp://ftp.test.net/./path1/./remove/../path2/../resource
} ftp://ftp.test.net/path1/resource
test uri-5.4-1 {uri::canonicalize} {
    uri::canonicalize ftp://ftp.test.net/./././path1/./remove/../path2/../resource
} ftp://ftp.test.net/path1/resource
test uri-5.5-1 {uri::canonicalize} {
    uri::canonicalize ftp://ftp.test.net/./././path1/./remove/path2/../../resource
} ftp://ftp.test.net/path1/resource
test uri-5.6-1 {uri::canonicalize infinite loop} {
    uri::canonicalize ftp://ftp.test.net/../../../path2/resource
} {ftp://ftp.test.net/path2/resource}
test uri-5.7-1 {uri::canonicalize} {
    uri::canonicalize ftp://ftp.test.net/path1/./remove/../path.html/resource
} ftp://ftp.test.net/path1/path.html/resource
test uri-5.8-1 {uri::canonicalize infinite loop} {
    uri::canonicalize ftp://ftp.test.net/../path.html/resource
} {ftp://ftp.test.net/path.html/resource}
test uri-5.9-1 {uri::canonicalize} {
    uri::canonicalize ftp://ftp.test.net/./path1/./remove/../path.html/../resource
} ftp://ftp.test.net/path1/resource
test uri-5.10-1 {uri::canonicalize} {
    uri::canonicalize ftp://ftp.test.net/./././path1/./remove/../path.html/../resource
} ftp://ftp.test.net/path1/resource
test uri-5.11-1 {uri::canonicalize} {
    uri::canonicalize ftp://ftp.test.net/./././path1/./remove/path.html/../../resource
} ftp://ftp.test.net/path1/resource
test uri-5.12-1 {uri::canonicalize infinite loop} {
    uri::canonicalize ftp://ftp.test.net/../../../path.html/resource
} {ftp://ftp.test.net/path.html/resource}
test uri-5.1-2 {uri::canonicalize} {
    uri::canonicalize file://goo.test.net/path1/./remove/../path2/resource
} file://goo.test.net/path1/path2/resource
test uri-5.2-2 {uri::canonicalize infinite loop} {
    uri::canonicalize file://goo.test.net/../path2/resource
} {file://goo.test.net/path2/resource}
test uri-5.3-2 {uri::canonicalize} {
    uri::canonicalize file://goo.test.net/./path1/./remove/../path2/../resource
} file://goo.test.net/path1/resource
test uri-5.4-2 {uri::canonicalize} {
    uri::canonicalize file://goo.test.net/./././path1/./remove/../path2/../resource
} file://goo.test.net/path1/resource
test uri-5.5-2 {uri::canonicalize} {
    uri::canonicalize file://goo.test.net/./././path1/./remove/path2/../../resource
} file://goo.test.net/path1/resource
test uri-5.6-2 {uri::canonicalize infinite loop} {
    uri::canonicalize file://goo.test.net/../../../path2/resource
} {file://goo.test.net/path2/resource}
test uri-5.7-2 {uri::canonicalize} {
    uri::canonicalize file://goo.test.net/path1/./remove/../path.html/resource
} file://goo.test.net/path1/path.html/resource
test uri-5.8-2 {uri::canonicalize infinite loop} {
    uri::canonicalize file://goo.test.net/../path.html/resource
} {file://goo.test.net/path.html/resource}
test uri-5.9-2 {uri::canonicalize} {
    uri::canonicalize file://goo.test.net/./path1/./remove/../path.html/../resource
} file://goo.test.net/path1/resource
test uri-5.10-2 {uri::canonicalize} {
    uri::canonicalize file://goo.test.net/./././path1/./remove/../path.html/../resource
} file://goo.test.net/path1/resource
test uri-5.11-2 {uri::canonicalize} {
    uri::canonicalize file://goo.test.net/./././path1/./remove/path.html/../../resource
} file://goo.test.net/path1/resource
test uri-5.12-2 {uri::canonicalize infinite loop} {
    uri::canonicalize file://goo.test.net/../../../path.html/resource
} {file://goo.test.net/path.html/resource}
test uri-5.1-3 {uri::canonicalize} {
    uri::canonicalize file:///path1/./remove/../path2/resource
} file:///path1/path2/resource
test uri-5.2-3 {uri::canonicalize infinite loop} {
    uri::canonicalize file:///../path2/resource
} {file:///path2/resource}
test uri-5.3-3 {uri::canonicalize} {
    uri::canonicalize file:///./path1/./remove/../path2/../resource
} file:///path1/resource
test uri-5.4-3 {uri::canonicalize} {
    uri::canonicalize file:///./././path1/./remove/../path2/../resource
} file:///path1/resource
test uri-5.5-3 {uri::canonicalize} {
    uri::canonicalize file:///./././path1/./remove/path2/../../resource
} file:///path1/resource
test uri-5.6-3 {uri::canonicalize infinite loop} {
    uri::canonicalize file:///../../../path2/resource
} {file:///path2/resource}
test uri-5.7-3 {uri::canonicalize} {
    uri::canonicalize file:///path1/./remove/../path.html/resource
} file:///path1/path.html/resource
test uri-5.8-3 {uri::canonicalize infinite loop} {
    uri::canonicalize file:///../path.html/resource
} {file:///path.html/resource}
test uri-5.9-3 {uri::canonicalize} {
    uri::canonicalize file:///./path1/./remove/../path.html/../resource
} file:///path1/resource
test uri-5.10-3 {uri::canonicalize} {
    uri::canonicalize file:///./././path1/./remove/../path.html/../resource
} file:///path1/resource
test uri-5.11-3 {uri::canonicalize} {
    uri::canonicalize file:///./././path1/./remove/path.html/../../resource
} file:///path1/resource
test uri-5.12-3 {uri::canonicalize infinite loop} {
    uri::canonicalize file:///../../../path.html/resource
} {file:///path.html/resource}
test uri-6.0 {uri::canonicalize} {
    uri::canonicalize telnet://goo.test.net/
} telnet://goo.test.net/
test uri-7.0 {uri::split & uri::join} {
    set ls [uri::split http://tcl.apache.org/websh/faq.ws3\#generic?foo=bar]
    eval uri::join $ls
} {http://tcl.apache.org/websh/faq.ws3#generic?foo=bar}
# -------------------------------------------------------------------------
test uri-8.0 {uri::split bug #676976, ill. char in scheme} {
    set ls [uri::split ht,tp://tcl.apache.org/websh]
    eval uri::join $ls
} {http:///ht,tp://tcl.apache.org/websh}
# -------------------------------------------------------------------------
test uri-9.0 {uri::split bug #936064, user information} {
    dictsort [uri::split http://foo:bar@baz.com:80/bla/]
} {fragment {} host baz.com path bla/ port 80 pwd bar query {} scheme http user foo}
# -------------------------------------------------------------------------
test uri-10.0 {uri::split bug #3235340, fragments after queries} {
    dictsort [uri::split  http://baz.com/foo?bar=baz#quux]
} {fragment quux host baz.com path foo port {} pwd {} query bar=baz scheme http user {}}
test uri-10.1 {uri::join bug #3235340, fragments after queries} {
    uri::join fragment quux host baz.com path foo port {} pwd {} query bar=baz scheme http user {}
} {http://baz.com/foo?bar=baz#quux}
# -------------------------------------------------------------------------
testsuiteCleanup
return
# -------------------------------------------------------------------------
# Local Variables:
#   mode: tcl
#   indent-tabs-mode: nil
# End:
 
     |