factor/extra/io/unix/sockets/secure/secure-tests.factor

66 lines
1.9 KiB
Factor
Raw Normal View History

2008-05-17 18:45:56 -04:00
IN: io.sockets.secure.tests
USING: accessors kernel namespaces io io.sockets
io.sockets.secure io.encodings.ascii io.streams.duplex
classes words destructors threads tools.test
2008-05-19 21:43:28 -04:00
concurrency.promises byte-arrays locals ;
2008-05-17 18:45:56 -04:00
\ <secure-config> must-infer
{ 1 0 } [ [ ] with-secure-context ] must-infer-as
[ ] [ <promise> "port" set ] unit-test
2008-05-19 21:43:28 -04:00
: with-test-context
<secure-config>
"resource:extra/openssl/test/server.pem" >>key-file
"resource:extra/openssl/test/root.pem" >>ca-file
"resource:extra/openssl/test/dh1024.pem" >>dh-file
"password" >>password
swap with-secure-context ;
:: server-test ( quot -- )
2008-05-17 18:45:56 -04:00
[
[
"127.0.0.1" 0 <inet4> <secure> ascii <server> [
dup addr>> addrspec>> port>> "port" get fulfill
accept [
2008-05-19 21:43:28 -04:00
quot call
2008-05-17 18:45:56 -04:00
] curry with-stream
] with-disposal
2008-05-19 21:43:28 -04:00
] with-test-context
] "SSL server test" spawn drop ;
2008-05-17 18:45:56 -04:00
2008-05-19 21:43:28 -04:00
: client-test
2008-05-17 18:45:56 -04:00
<secure-config> [
"127.0.0.1" "port" get ?promise <inet4> <secure> ascii <client> drop contents
2008-05-19 21:43:28 -04:00
] with-secure-context ;
2008-05-17 18:45:56 -04:00
2008-05-19 21:43:28 -04:00
[ ] [ [ class word-name write ] server-test ] unit-test
2008-05-17 18:45:56 -04:00
2008-05-19 21:43:28 -04:00
[ "secure" ] [ client-test ] unit-test
2008-05-17 18:45:56 -04:00
2008-05-19 21:43:28 -04:00
! Now, see what happens if the server closes the connection prematurely
2008-05-17 18:45:56 -04:00
[ ] [ <promise> "port" set ] unit-test
[ ] [
[
2008-05-19 21:43:28 -04:00
drop
input-stream get stream>> handle>> f >>connected drop
"hello" write flush
] server-test
2008-05-17 18:45:56 -04:00
] unit-test
2008-05-19 21:43:28 -04:00
[ client-test ] [ premature-close? ] must-fail-with
! Now, try validating the certificate. This should fail because its
! actually an invalid certificate
[ ] [ <promise> "port" set ] unit-test
[ ] [ [ drop ] server-test ] unit-test
2008-05-17 18:45:56 -04:00
[
<secure-config> [
"localhost" "port" get ?promise <inet> <secure> ascii
<client> drop dispose
] with-secure-context
] [ certificate-verify-error? ] must-fail-with