diff options
author | Steve Bennett <steveb@workware.net.au> | 2020-05-02 16:31:08 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2020-05-06 08:29:38 +1000 |
commit | f8be02f204b55daaee5304e8ee99294612b29737 (patch) | |
tree | 90916d75c3ad72ae9b6433174541432fa3375cc9 /tests | |
parent | 3a09c675d2e97915eb46d5d0783ffc60119903ae (diff) | |
download | jimtcl-f8be02f204b55daaee5304e8ee99294612b29737.zip jimtcl-f8be02f204b55daaee5304e8ee99294612b29737.tar.gz jimtcl-f8be02f204b55daaee5304e8ee99294612b29737.tar.bz2 |
tests: add ssl.test
Note that there is currently a problem with ssl and readable events
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/certificate.pem | 28 | ||||
-rw-r--r-- | tests/key.pem | 51 | ||||
-rw-r--r-- | tests/ssl.test | 89 |
3 files changed, 168 insertions, 0 deletions
diff --git a/tests/certificate.pem b/tests/certificate.pem new file mode 100644 index 0000000..2c49fd9 --- /dev/null +++ b/tests/certificate.pem @@ -0,0 +1,28 @@ +-----BEGIN CERTIFICATE----- +MIIEwDCCAqgCCQCFOs3gH4RsKTANBgkqhkiG9w0BAQUFADAiMQswCQYDVQQGEwJh +dTETMBEGA1UEAwwKamltLnRjbC50azAeFw0xOTA5MjQyMzQ2NDFaFw00NzAyMDgy +MzQ2NDFaMCIxCzAJBgNVBAYTAmF1MRMwEQYDVQQDDApqaW0udGNsLnRrMIICIjAN +BgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA0T9HMb5b2WZDIAF7+7KZzwAEiXC5 +misVrY1gmlwvLlSVx1pXKx5KrFpwkBMfDs1Zsi03/D46N+kViOmSJY/h5nxpiTdb +s1Gld2b1RqFbnXcLmx7eWVXXouLDcmzoJM1Y7vh26e9j3Uy4Bsew7zfxgnWmbfOA +9Sg/rHamQFfJ+Ov9NglkAoGPwdIiDWc4+hkKD6HL3B72m3VyD4crDSuTm2vFqUDh +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dhDwucvBwz0ClSiTT3iFjGcTMZ +r9m5x0V15qZSvj1GWp6hSWIG/NwS+4gvv75Jlx83cr+bTlHgDl8h4seEmj8HhPq1 +j9ZXBr9P2ETiD8OVyZAT3hhSwOg= +-----END CERTIFICATE----- diff --git a/tests/key.pem b/tests/key.pem new file mode 100644 index 0000000..67ca6c6 --- /dev/null +++ b/tests/key.pem @@ -0,0 +1,51 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIJKgIBAAKCAgEA0T9HMb5b2WZDIAF7+7KZzwAEiXC5misVrY1gmlwvLlSVx1pX +Kx5KrFpwkBMfDs1Zsi03/D46N+kViOmSJY/h5nxpiTdbs1Gld2b1RqFbnXcLmx7e +WVXXouLDcmzoJM1Y7vh26e9j3Uy4Bsew7zfxgnWmbfOA9Sg/rHamQFfJ+Ov9Nglk +AoGPwdIiDWc4+hkKD6HL3B72m3VyD4crDSuTm2vFqUDhXk+Jw3clNQYXHQrOSpDK +st1qPQtEDTQbrmKhSN6jMBRwcwfo39lCZLN02jEfOC2bwHPe+VgcyfCzWgfKHtPl +hqqanSIndDSAc6aF5hzI1vlT2dZNmSWDZ6QBrwharh25QXcnQhDr/9DyHIjgvojR +OsOiSaT4pVvJRBsVm7N/7kVQKvNdbwB8itz+ubLlb5SYahlZNBMpE9RqgchwAwe0 +SpjILMBHI90/H89SrZPZ4rMitZiIq5/3mBFEy/7Xio/G5jw/Gp3cHa6SMf/6cqhl +l7binB8s8Yd5c8RvdNunczCobKmbnTMDRdsnjnvWFmiaPJZUdcOtftxUCxYP2tEj +apQL8kjC+K4MjCGkde/5lrd8+yRY6GK6zixxfYb1jka/NFdXBaws4gm8amrsFstk +Y3K2GqrVh44/sG7BNqsl4hxkqyHryay7B413+KUrkiET4PqwSHgtJHPayAMCAwEA +AQKCAgEApOLjPCyP/jkaLg9dXtK3ZynRaWh9qSHIXFFqzVhVCYI34Last9qP508B +IlcfAzAIPWJqmoeCouo2QQQlWRoPXeut0iXgSebNp9Bm+ThPlD7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8DMHujlzS +cdUKcFO3OL+eLQazM5M+3qxQuAFDTlBf41d3OJjCOuQ9soBy0Gy9yMhtjFVVmKDw +eArA0lZgskLVcI9JH6bPhv7+5+n26OqMlFjtmbNMwqi/lOoyGwst5b2d9oAMkWQi +QW5pi51MaAwVV8q8NdfUv1twD8lpRV8Rwb2k8rmG5FqSwhOsibSwpu8gf4WYow== +-----END RSA PRIVATE KEY----- diff --git a/tests/ssl.test b/tests/ssl.test new file mode 100644 index 0000000..a15c4d6 --- /dev/null +++ b/tests/ssl.test @@ -0,0 +1,89 @@ +source [file dirname [info script]]/testing.tcl + +needs constraint jim +needs cmd socket +needs cmd alarm +needs cmd os.fork +testCmdConstraints load_ssl_certs + +#load_ssl_certs [file dirname [info script]]/certs +#load_ssl_certs /etc/ssl/certs + +# Let's set up a client and a server where the client +# simply echos everything back to the server + +set s [socket stream.server 1443] +if {[os.fork] == 0} { + # child + set c [[socket stream [$s sockname]] ssl] + $c buffering none + $s close + sleep 0.25 + $c readable { + set buf [$c read 1] + if {[string length $buf] == 0} { + incr ssldone + $c close + } else { + $c puts -nonewline $buf + } + } + vwait ssldone + exit 99 +} + +# Now set up the server +set certpath [file dirname [info script]] +set cs [[$s accept addr] ssl -server $certpath/certificate.pem $certpath/key.pem] +$s close +defer { + $cs close +} + +# At this point, $cs is the server connection to the client in the child process + +test ssl-1.1 {puts/gets} { + $cs puts hello + $cs gets +} hello + +# XXX this test does not work because of the interaction between +# ssl buffering and readable +alarm 1 +test ssl-1.2 {puts/gets} { + $cs puts -nonewline again + lmap p [range 5] { + set c [$cs read 1] + set c + } +} {a g a i n} +alarm 0 + +test ssl-2.1 {https to google.com, gets} -body { + set c [[socket stream www.google.com:443] ssl] + $c puts -nonewline "GET / HTTP/1.0\r\n\r\n" + $c close w + set lines {} + while {[$c gets buf] >= 0} { + lappend lines $buf + } + $c close + join $lines \n +} -match glob -result {HTTP/1.0 200 OK*</html>} + +test ssl-2.2 {https to google.com, read} -body { + set c [[socket stream www.google.com:443] ssl] + $c puts -nonewline "GET / HTTP/1.0\r\n\r\n" + $c close w + set buf [$c read] +} -match glob -result {HTTP/1.0 200 OK*</html>} + +test ssl-2.3 {ssl to google.com on port 80} -body { + # Try to talk SSL to a non-SSL server + set c [[socket stream www.google.com:80] ssl] + $c puts -nonewline "GET / HTTP/1.0\r\n\r\n" + $c close w + set buf [$c read] +} -returnCodes error -match glob -result {error:*} + +testreport |