ADDED tests/remote.tcl Index: tests/remote.tcl ================================================================== --- /dev/null +++ tests/remote.tcl @@ -0,0 +1,180 @@ +# This file contains Tcl code to implement a remote server that can be +# used during testing of Tcl socket code. This server is used by some +# of the tests in socket.test. +# +# Source this file in the remote server you are using to test Tcl against. +# +# Copyright (c) 1995-1996 Sun Microsystems, Inc. +# +# See the file "license.terms" for information on usage and redistribution +# of this file, and for a DISCLAIMER OF ALL WARRANTIES. +# +# RCS: @(#) $Id: remote.tcl,v 1.1 2000/06/03 00:20:02 awb Exp $ + +# load tls package +package require tls + +# Initialize message delimitor + +# Initialize command array +catch {unset command} +set command(0) "" +set callerSocket "" + +# Detect whether we should print out connection messages etc. +set VERBOSE 1 +if {![info exists VERBOSE]} { + set VERBOSE 0 +} + +proc __doCommands__ {l s} { + global callerSocket VERBOSE + + if {$VERBOSE} { + puts "--- Server executing the following for socket $s:" + puts $l + puts "---" + } + set callerSocket $s + if {[catch {uplevel #0 $l} msg]} { + list error $msg + } else { + list success $msg + } +} + +proc __readAndExecute__ {s} { + global command VERBOSE + + set l [gets $s] + if {[string compare $l "--Marker--Marker--Marker--"] == 0} { + if {[info exists command($s)]} { + puts $s [list error incomplete_command] + } + puts $s "--Marker--Marker--Marker--" + return + } + if {[string compare $l ""] == 0} { + if {[eof $s]} { + if {$VERBOSE} { + puts "Server closing $s, eof from client" + } + close $s + } + return + } + append command($s) $l "\n" + if {[info complete $command($s)]} { + set cmds $command($s) + unset command($s) + puts $s [__doCommands__ $cmds $s] + } + if {[eof $s]} { + if {$VERBOSE} { + puts "Server closing $s, eof from client" + } + close $s + } +} + +proc __accept__ {s a p} { + global VERBOSE + + if {$VERBOSE} { + puts "Server accepts new connection from $a:$p on $s" + } + fileevent $s readable [list __readAndExecute__ $s] + fconfigure $s -buffering line -translation crlf +} + +set serverIsSilent 0 +for {set i 0} {$i < $argc} {incr i} { + if {[string compare -serverIsSilent [lindex $argv $i]] == 0} { + set serverIsSilent 1 + break + } +} +if {![info exists serverPort]} { + if {[info exists env(serverPort)]} { + set serverPort $env(serverPort) + } +} +if {![info exists serverPort]} { + for {set i 0} {$i < $argc} {incr i} { + if {[string compare -port [lindex $argv $i]] == 0} { + if {$i < [expr $argc - 1]} { + set serverPort [lindex $argv [expr $i + 1]] + } + break + } + } +} +if {![info exists serverPort]} { + set serverPort 2048 +} + +if {![info exists serverAddress]} { + if {[info exists env(serverAddress)]} { + set serverAddress $env(serverAddress) + } +} +if {![info exists serverAddress]} { + for {set i 0} {$i < $argc} {incr i} { + if {[string compare -address [lindex $argv $i]] == 0} { + if {$i < [expr $argc - 1]} { + set serverAddress [lindex $argv [expr $i + 1]] + } + break + } + } +} +if {![info exists serverAddress]} { + set serverAddress 0.0.0.0 +} + +if {$serverIsSilent == 0} { + set l "Remote server listening on port $serverPort, IP $serverAddress." + puts "" + puts $l + for {set c [string length $l]} {$c > 0} {incr c -1} {puts -nonewline "-"} + puts "" + puts "" + puts "You have set the Tcl variables serverAddress to $serverAddress and" + puts "serverPort to $serverPort. You can set these with the -address and" + puts "-port command line options, or as environment variables in your" + puts "shell." + puts "" + puts "NOTE: The tests will not work properly if serverAddress is set to" + puts "\"localhost\" or 127.0.0.1." + puts "" + puts "When you invoke tcltest to run the tests, set the variables" + puts "remoteServerPort to $serverPort and remoteServerIP to" + puts "[info hostname]. You can set these as environment variables" + puts "from the shell. The tests will not work properly if you set" + puts "remoteServerIP to \"localhost\" or 127.0.0.1." + puts "" + puts -nonewline "Type Ctrl-C to terminate--> " + flush stdout +} + +if {[catch {set serverSocket \ + [tls::socket -myaddr $serverAddress -server __accept__ \ + -cafile [file join [pwd] certs cacert.pem] \ + -certfile [file join [pwd] certs server.pem] \ + -keyfile [file join [pwd] certs skey.pem] \ + $serverPort]} msg]} { + puts "Server on $serverAddress:$serverPort cannot start: $msg" +} else { + vwait __server_wait_variable__ +} + + + + + + + + + + + Index: tests/tlsIo.test ================================================================== --- tests/tlsIo.test +++ tests/tlsIo.test @@ -8,11 +8,11 @@ # Copyright (c) 1998-2000 Ajuba Solutions. # # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: tlsIo.test,v 1.6 2000/06/02 22:26:12 awb Exp $ +# RCS: @(#) $Id: tlsIo.test,v 1.7 2000/06/03 00:20:02 awb Exp $ # Running socket tests with a remote server: # ------------------------------------------ # # Some tests in socket.test depend on the existence of a remote server to @@ -122,12 +122,14 @@ set remoteProcChan "" set commandSocket "" if {$doTestsWithRemoteServer} { catch {close $commandSocket} - if {[catch {set commandSocket [tls::socket $remoteServerIP \ - $remoteServerPort]}] != 0} { + if {[catch {set commandSocket [tls::socket \ + -certfile $clientCert -cafile $caCert -keyfile $clientKey \ + $remoteServerIP \ + $remoteServerPort]}] != 0} { if {[info commands exec] == ""} { set noRemoteTestReason "can't exec" set doTestsWithRemoteServer 0 } else { set remoteServerIP 127.0.0.1 @@ -138,11 +140,13 @@ -port $remoteServerPort \ -address $remoteServerIP]" \ w+]} \ msg] == 0} { after 1000 - if {[catch {set commandSocket [tls::socket $remoteServerIP \ + if {[catch {set commandSocket [tls::socket \ + -certfile $clientCert -cafile $caCert -keyfile $clientKey \ + $remoteServerIP \ $remoteServerPort]} msg] == 0} { fconfigure $commandSocket -translation crlf -buffering line } else { set noRemoteTestReason $msg set doTestsWithRemoteServer 0 @@ -154,10 +158,11 @@ } } else { fconfigure $commandSocket -translation crlf -buffering line } } +puts stdout "commandSocket: $commandSocket" # Some tests are run only if we are doing testing against a remote server. set ::tcltest::testConstraints(doTestsWithRemoteServer) $doTestsWithRemoteServer if {$doTestsWithRemoteServer == 0} { if {[string first s $::tcltest::verbose] != -1} { @@ -189,11 +194,11 @@ set resp "" while {1} { set line [gets $commandSocket] if {[eof $commandSocket]} { - error "remote server disappaered" + error "remote server disappeared" } if {[string compare $line "--Marker--Marker--Marker--"] == 0} { if {[string compare [lindex $resp 0] error] == 0} { error [lindex $resp 1] } else { @@ -567,14 +572,15 @@ (procedure "tls::socket" line 62) invoked from within "tls::socket -server accept 2828" (file "script" line 1)}} -test socket-2.10 {close on accept, accepted socket lives} {socket pcCrash} { +test socket-2.10 {close on accept, accepted socket lives} {socket knownBug} { set done 0 set timer [after 20000 "set done timed_out"] - set ss [tls::socket -server accept 2830] + set ss [tls::socket -server accept -certfile $serverCert -cafile $caCert \ + -keyfile $serverKey 2830] proc accept {s a p} { global ss close $ss fileevent $s readable "readit $s" fconfigure $s -trans lf @@ -583,26 +589,35 @@ global done gets $s close $s set done 1 } - set cs [tls::socket [info hostname] 2830] - puts $cs hello + set cs [tls::socket -certfile $clientCert -cafile $caCert \ + -keyfile $clientKey [info hostname] 2830] close $cs + vwait done after cancel $timer set done } 1 -test socket-2.11 {detecting new data} {socket pcCrash} { + +test socket-2.11 {detecting new data} {socket knownBug} { proc accept {s a p} { global sock set sock $s + set f [open awb.log w] + puts $f [catch {tls::handshake $sock} err] + puts $f "err: $err" + puts $f "[tls::status $sock]" + close $s } - set s [tls::socket -server accept 2400] + set s [tls::socket -require 0 -request 0 -server accept -certfile $serverCert -cafile $caCert \ + -keyfile $serverKey 2400] set sock "" - set s2 [tls::socket 127.0.0.1 2400] + set s2 [tls::socket -certfile $clientCert -cafile $caCert \ + -keyfile $clientKey 127.0.0.1 2400] vwait sock puts $s2 one flush $s2 after 500 fconfigure $sock -blocking 0 @@ -1122,36 +1137,50 @@ set goterror } 1 test socket-11.1 {tcp connection} {socket doTestsWithRemoteServer} { sendCommand { - set socket9_1_test_server [tls::socket -server accept 2834] + set socket9_1_test_server [tls::socket -server accept \ + -certfile [file join [pwd] certs server.pem] \ + -cafile [file join [pwd] certs caFile.pem] \ + -keyfile [file join [pwd] certs skey.pem] \ + 2834] proc accept {s a p} { puts $s done + tls::handshake $s close $s } } - set s [tls::socket $remoteServerIP 2834] + set s [tls::socket \ + -certfile $clientCert -cafile $caCert -keyfile $clientKey \ + $remoteServerIP 2834] set r [gets $s] close $s sendCommand {close $socket9_1_test_server} set r } done + test socket-11.2 {client specifies its port} {socket doTestsWithRemoteServer} { if {[info exists port]} { incr port } else { set port [expr 2048 + [pid]%1024] } sendCommand { - set socket9_2_test_server [tls::socket -server accept 2835] + set socket9_2_test_server [tls::socket -server accept \ + -certfile [file join [pwd] certs server.pem] \ + -cafile [file join [pwd] certs caFile.pem] \ + -keyfile [file join [pwd] certs skey.pem] \ + 2835] proc accept {s a p} { puts $s $p close $s } } - set s [tls::socket -myport $port $remoteServerIP 2835] + set s [tls::socket \ + -certfile $clientCert -cafile $caCert -keyfile $clientKey \ + -myport $port $remoteServerIP 2835] set r [gets $s] close $s sendCommand {close $socket9_2_test_server} if {$r == $port} { set result ok