From: Stephen D. <sd...@us...> - 2005-04-12 06:21:35
|
Update of /cvsroot/naviserver/naviserver/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22726/tests Modified Files: test.nscfg Added Files: ns_conn_host.test ns_hashpath.test ns_pagepath.test ns_serverpath.test Log Message: * include/ns.h: * nsd/nsd.h: * nsd/info.c: * nsd/proc.c: * nsd/return.c: * nsd/server.c: * nsd/fastpath.c: * nsd/pathname.c: New concept: server root. Callback can be registered to create the server root, defaults to statically assigned 'serverroot' from config, or host-based if enabled. Many virtual hosting options added. (RFE #1159471) * nsd/conn.c: Add callback to generate current location. If none registered, uses host-header and falls back to driver's location. Add new Ns_ConnAppendLocation() as preferred method of access, depreciated Ns_ConnLocation(). * nsd/tclcmds.c: Add vhost related Tcl commands: ns_serverpath ns_pagepath ns_hashpath ns_serverrootproc ns_locationproc. * ns_pagepath.test: * ns_conn_host.test: * ns_serverpath.test: * ns_hashpath.test: * tests/test.nscfg: Add tests for vhost related commands. More location tests needed... --- NEW FILE: ns_conn_host.test --- # # $Header: /cvsroot/naviserver/naviserver/tests/ns_conn_host.test,v 1.1 2005/04/12 06:21:24 sdeasey Exp $ # package require tcltest 2.2 namespace import -force ::tcltest::* eval ::tcltest::configure $argv if {[ns_config test listenport]} { testConstraint serverListen true } set driverlocation http://[ns_config "ns/server/test/module/nssock" hostname] set self ${driverlocation}:[ns_config "ns/server/test/module/nssock" port] test ns_conn_location-1.1 {http 1.1 host} -constraints serverListen -setup { ns_eval {{ proc conn_location_request {args} { ns_return 200 text/plain [ns_conn location] } }} ns_register_proc GET /location conn_location_request } -body { set id [ns_http queue GET $self/location] ns_http wait $id location set location } -cleanup { ns_eval {{ rename conn_location_request {} }} ns_unregister_proc GET /location ns_http cleanup unset -nocomplain id location } -result $self unset -nocomplain driverhost self cleanupTests --- NEW FILE: ns_hashpath.test --- # # $Header: /cvsroot/naviserver/naviserver/tests/ns_hashpath.test,v 1.1 2005/04/12 06:21:24 sdeasey Exp $ # package require tcltest 2.2 namespace import -force ::tcltest::* eval ::tcltest::configure $argv test ns_hashpath-1.1 {basic syntax} -body { ns_hashpath } -returnCodes error -result {wrong # args: should be "ns_hashpath string levels"} test ns_hashpath-1.2 {basic syntax} -body { ns_hashpath "" 0 } -returnCodes error -result {levels must be an interger greater than zero} test ns_hashpath-1.3 {basic syntax} -body { ns_hashpath "" -1 } -returnCodes error -result {levels must be an interger greater than zero} test ns_hashpath-1.4 {basic syntax} -body { ns_hashpath "" notanum } -returnCodes error -result {levels must be an interger greater than zero} test ns_hashpath-2.1 {paths} -body { ns_hashpath x 1 } -result /x test ns_hashpath-2.2 {paths} -body { ns_hashpath xxx 1 } -result /x test ns_hashpath-2.3 {paths} -body { ns_hashpath xxx 2 } -result /x/x test ns_hashpath-2.4 {paths} -body { ns_hashpath xxx 3 } -result /x/x/x test ns_hashpath-3.1 {short paths} -body { ns_hashpath x 2 } -result /x/_ test ns_hashpath-3.1 {short paths} -body { ns_hashpath x 3 } -result /x/_/_ test ns_hashpath-3.1 {short paths} -body { ns_hashpath xx 3 } -result /x/x/_ cleanupTests --- NEW FILE: ns_serverpath.test --- # # $Header: /cvsroot/naviserver/naviserver/tests/ns_serverpath.test,v 1.1 2005/04/12 06:21:24 sdeasey Exp $ # package require tcltest 2.2 namespace import -force ::tcltest::* eval ::tcltest::configure $argv set serverroot [file join [ns_config "test" home] \ [ns_config "ns/server/test/fastpath" serverdir]] set vhosts [ns_config "ns/server/test/vhost" hostprefix] test ns_serverpath-1.1 {basic path} -body { ns_serverpath } -result $serverroot test ns_serverpath-1.2 {basic path} -body { ns_serverpath foo bar } -result ${serverroot}/foo/bar test ns_serverpath-1.3 {basic path} -body { ns_serverpath -- foo bar } -result ${serverroot}/foo/bar test ns_serverpath-2.1 {host path} -body { ns_serverpath -host example.com } -result ${serverroot}/${vhosts}/e/x/a/example.com test ns_serverpath-2.2 {host path} -body { ns_serverpath -host EXAMPLE.COM } -result ${serverroot}/${vhosts}/e/x/a/example.com test ns_serverpath-2.3 {host path} -body { ns_serverpath -host www.example.com } -result ${serverroot}/${vhosts}/e/x/a/example.com test ns_serverpath-2.4 {host path} -body { ns_serverpath -host www.example.com:80 } -result ${serverroot}/${vhosts}/e/x/a/example.com test ns_serverpath-2.5 {host path} -body { ns_serverpath -host 1 } -result ${serverroot}/${vhosts}/1/_/_/1 test ns_serverpath-2.6 {host path} -body { ns_serverpath -host "" } -result ${serverroot} test ns_serverpath-3.1 {bad host} -body { ns_serverpath -host " " } -result ${serverroot} test ns_serverpath-3.2 {bad host} -body { ns_serverpath -host / } -result ${serverroot} test ns_serverpath-3.3 {bad host} -body { ns_serverpath -host ../example.com } -result ${serverroot} test ns_serverpath-3.4 {bad host} -body { ns_serverpath -host www.example.com//naughty } -result ${serverroot} test ns_serverpath-3.5 {bad host} -body { ns_serverpath -host www.example.com/../naughty } -result ${serverroot} test ns_serverpath-3.6 {bad host} -body { ns_serverpath -host .. 2dots } -result ${serverroot}/2dots test ns_serverpath-3.6 {bad host} -body { ns_serverpath -host ... 3dots } -result ${serverroot}/3dots unset -nocomplain serverroot vhosts cleanupTests Index: test.nscfg =================================================================== RCS file: /cvsroot/naviserver/naviserver/tests/test.nscfg,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test.nscfg 3 Apr 2005 06:38:01 -0000 1.1 --- test.nscfg 12 Apr 2005 06:21:24 -0000 1.2 *************** *** 1,10 **** # ! # ... # set servername test ns_section "ns/parameters" ! ns_param home ./tests ns_section "ns/servers" --- 1,37 ---- # ! # Configuration file for server to run tests in command mode. ! # ! # $Header$ # set servername test + + + # + # Parameters for test scripts. + # + + ns_section "test" + ns_param servername $servername + ns_param home [pwd]/tests + + for {set port 8000} {$port < 8100} {incr port} { + if {![catch { + close [ns_socklisten 127.0.0.1 $port] + } msg]} { + break + } + } + ns_param listenport [expr $port < 8100 ? $port : 0] + + + + # + # Test server configuration. + # + ns_section "ns/parameters" ! ns_param home [ns_config "test" home] ns_section "ns/servers" *************** *** 12,19 **** ns_section "ns/server/${servername}" - ns_param pageroot servers/server1/pages ns_param enabletclpages true ns_section "ns/server/${servername}/tcl" ns_param initfile ../nsd/init.tcl ns_param library ../tcl --- 39,66 ---- ns_section "ns/server/${servername}" ns_param enabletclpages true + ns_section "ns/server/${servername}/fastpath" + ns_param serverdir testserver + ns_param pagedir pages + + ns_section "ns/server/${servername}/vhost" + ns_param enabled true + ns_param hostprefix vhosts + ns_param hosthashlevel 3 + ns_param stripport yes + ns_param stripwww yes + ns_section "ns/server/${servername}/tcl" ns_param initfile ../nsd/init.tcl ns_param library ../tcl + + ns_section "ns/server/${servername}/module/nssock" + ns_param port [ns_config "test" listenport] + ns_param hostname localhost + ns_param address 127.0.0.1 + + ns_section "ns/server/${servername}/modules" + if {[ns_config "test" listenport]} { + ns_param nssock [ns_config "test" home]/../nssock/nssock.so + } --- NEW FILE: ns_pagepath.test --- # # See: ns_serverpath.test for tests which thoroughly exercise the -host switch. # # $Header: /cvsroot/naviserver/naviserver/tests/ns_pagepath.test,v 1.1 2005/04/12 06:21:24 sdeasey Exp $ # package require tcltest 2.2 namespace import -force ::tcltest::* eval ::tcltest::configure $argv set serverroot [file join [ns_config "test" home] \ [ns_config "ns/server/test/fastpath" serverdir] ] set pagedir [ns_config "ns/server/test/fastpath" pagedir] set vhosts [ns_config "ns/server/test/vhost" hostprefix] test ns_pagepath-1.1 {basic path} -body { ns_pagepath } -result ${serverroot}/${pagedir} test ns_pagepath-1.2 {basic path} -body { ns_pagepath x y } -result ${serverroot}/${pagedir}/x/y test ns_pagepath-1.3 {basic path} -body { ns_pagepath -- x y } -result ${serverroot}/${pagedir}/x/y test ns_pagepath-2.1 {host path} -body { ns_pagepath -host www.example.com } -result ${serverroot}/${vhosts}/e/x/a/example.com/${pagedir} test ns_pagepath-2.2 {host path} -body { ns_pagepath -host www.example.com -- } -result ${serverroot}/${vhosts}/e/x/a/example.com/${pagedir} test ns_pagepath-2.3 {host path} -body { ns_pagepath -host www.example.com -- x } -result ${serverroot}/${vhosts}/e/x/a/example.com/${pagedir}/x test ns_pagepath-2.4 {host path} -body { ns_pagepath -host www.example.com x y } -result ${serverroot}/${vhosts}/e/x/a/example.com/${pagedir}/x/y unset -nocomplain serverroot pagedir vhosts cleanupTests |