1 IN: io.sockets.secure.tests
2 USING: accessors kernel namespaces io io.sockets
3 io.sockets.secure io.encodings.ascii io.streams.duplex
4 io.backend.unix classes words destructors threads tools.test
5 concurrency.promises byte-arrays locals calendar io.timeouts
6 io.sockets.secure.unix.debug ;
8 \ <secure-config> must-infer
9 { 1 0 } [ [ ] with-secure-context ] must-infer-as
11 [ ] [ <promise> "port" set ] unit-test
13 :: server-test ( quot -- )
16 "127.0.0.1" 0 <inet4> <secure> ascii <server> [
17 dup addr>> addrspec>> port>> "port" get fulfill
23 ] "SSL server test" spawn drop ;
25 : client-test ( -- string )
27 "127.0.0.1" "port" get ?promise <inet4> <secure> ascii <client> drop contents
28 ] with-secure-context ;
30 [ ] [ [ class name>> write ] server-test ] unit-test
32 [ "secure" ] [ client-test ] unit-test
34 ! Now, see what happens if the server closes the connection prematurely
35 [ ] [ <promise> "port" set ] unit-test
41 input-stream get stream>> handle>> f >>connected drop
45 [ client-test ] [ premature-close? ] must-fail-with
47 ! Now, try validating the certificate. This should fail because its
48 ! actually an invalid certificate
49 [ ] [ <promise> "port" set ] unit-test
51 [ ] [ [ drop "hi" write ] server-test ] unit-test
55 "localhost" "port" get ?promise <inet> <secure> ascii
58 ] [ certificate-verify-error? ] must-fail-with
60 ! Client-side handshake timeout
61 [ ] [ <promise> "port" set ] unit-test
65 "127.0.0.1" 0 <inet4> ascii <server> [
66 dup addr>> port>> "port" get fulfill
67 accept drop 1 minutes sleep dispose
69 ] "Silly server" spawn drop
73 1 seconds secure-socket-timeout [
76 ] [ io-timeout? ] must-fail-with
78 ! Server-side handshake timeout
79 [ ] [ <promise> "port" set ] unit-test
83 "127.0.0.1" "port" get ?promise
84 <inet4> ascii <client> drop 1 minutes sleep dispose
85 ] "Silly client" spawn drop
89 1 seconds secure-socket-timeout [
91 "127.0.0.1" 0 <inet4> <secure> ascii <server> [
92 dup addr>> addrspec>> port>> "port" get fulfill
93 accept drop dup stream-read1 drop dispose
97 ] [ io-timeout? ] must-fail-with
99 ! Client socket shutdown timeout
101 ! Until I sort out two-stage handshaking, I can't do much here
103 [ ] [ <promise> "port" set ] unit-test
108 "127.0.0.1" 0 <inet4> <secure> ascii <server> [
109 dup addr>> addrspec>> port>> "port" get fulfill
110 accept drop 1 minutes sleep dispose
113 ] "Silly server" spawn drop
117 1 seconds secure-socket-timeout [
119 "127.0.0.1" "port" get ?promise <inet4> <secure>
120 ascii <client> drop dispose
121 ] with-secure-context
123 ] [ io-timeout? ] must-fail-with
125 ! Server socket shutdown timeout
126 [ ] [ <promise> "port" set ] unit-test
131 "127.0.0.1" "port" get ?promise
132 <inet4> <secure> ascii <client> drop 1 minutes sleep dispose
134 ] "Silly client" spawn drop
138 1 seconds secure-socket-timeout [
140 "127.0.0.1" 0 <inet4> <secure> ascii <server> [
141 dup addr>> addrspec>> port>> "port" get fulfill
146 ] [ io-timeout? ] must-fail-with