2017-12-17 21:02:29 -05:00
|
|
|
USING: accessors calendar classes concurrency.conditions
|
|
|
|
concurrency.mailboxes concurrency.promises continuations
|
|
|
|
destructors io io.backend.unix io.encodings.ascii io.sockets
|
|
|
|
io.sockets.secure io.sockets.secure.debug io.streams.duplex
|
|
|
|
io.timeouts kernel locals namespaces threads tools.test ;
|
2017-12-17 19:49:52 -05:00
|
|
|
QUALIFIED-WITH: concurrency.messaging qm
|
2017-12-17 21:02:29 -05:00
|
|
|
IN: io.sockets.secure.tests
|
2008-05-17 18:45:56 -04:00
|
|
|
|
|
|
|
{ 1 0 } [ [ ] with-secure-context ] must-infer-as
|
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{ } [ <promise> "port" set ] unit-test
|
2008-05-17 18:45:56 -04:00
|
|
|
|
2017-12-17 21:02:29 -05:00
|
|
|
:: server-test ( quot -- )
|
2008-05-17 18:45:56 -04:00
|
|
|
[
|
|
|
|
[
|
2016-03-02 18:29:59 -05:00
|
|
|
"127.0.0.1" 0 <inet4> f <secure> ascii <server> [
|
2008-05-17 18:45:56 -04:00
|
|
|
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
|
2017-12-17 21:02:29 -05:00
|
|
|
] "SSL server test" qm:spawn-linked drop
|
|
|
|
! This is hideous.
|
|
|
|
! If we fail with a timeout, the test is passing.
|
|
|
|
! If we fail with something besides a timeout, rethrow it and fail the test.
|
|
|
|
[ qm:my-mailbox 200 milliseconds mailbox-get-timeout drop ]
|
|
|
|
[ dup timed-out-error? [ drop ] [ rethrow ] if ] recover ;
|
2017-12-17 19:49:52 -05:00
|
|
|
|
|
|
|
: ?promise-test ( mailbox -- obj )
|
|
|
|
340 milliseconds ?promise-timeout ;
|
2008-05-17 18:45:56 -04:00
|
|
|
|
2008-06-15 23:49:54 -04:00
|
|
|
: client-test ( -- string )
|
2008-05-17 18:45:56 -04:00
|
|
|
<secure-config> [
|
2017-12-17 19:49:52 -05:00
|
|
|
"127.0.0.1" "port" get ?promise-test <inet4> f <secure> ascii <client> drop
|
|
|
|
1 seconds
|
|
|
|
[ stream-contents ] with-timeout*
|
2008-05-19 21:43:28 -04:00
|
|
|
] with-secure-context ;
|
2008-05-17 18:45:56 -04:00
|
|
|
|
2017-12-17 19:49:52 -05:00
|
|
|
! { } [ [ class-of name>> write "done" my-mailbox mailbox-put ] server-test ] unit-test
|
2015-07-03 12:39:59 -04:00
|
|
|
{ } [ [ class-of name>> write ] server-test ] unit-test
|
2008-05-17 18:45:56 -04:00
|
|
|
|
2015-07-03 12:39:59 -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
|
2015-07-03 12:39:59 -04:00
|
|
|
{ } [ <promise> "port" set ] unit-test
|
2008-05-17 18:45:56 -04:00
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{ } [
|
2008-05-17 18:45:56 -04:00
|
|
|
[
|
2008-05-19 21:43:28 -04:00
|
|
|
drop
|
|
|
|
"hello" write flush
|
2008-05-22 01:29:19 -04:00
|
|
|
input-stream get stream>> handle>> f >>connected drop
|
2008-05-19 21:43:28 -04:00
|
|
|
] server-test
|
2008-05-17 18:45:56 -04:00
|
|
|
] unit-test
|
|
|
|
|
2011-02-26 00:05:56 -05:00
|
|
|
! Actually, this should not be an error since many HTTPS servers
|
|
|
|
! (eg, google.com) do this.
|
|
|
|
|
|
|
|
! [ client-test ] [ premature-close? ] must-fail-with
|
2015-07-03 12:39:59 -04:00
|
|
|
{ "hello" } [ client-test ] unit-test
|
2008-05-19 21:43:28 -04:00
|
|
|
|
|
|
|
! Now, try validating the certificate. This should fail because its
|
|
|
|
! actually an invalid certificate
|
2015-07-03 12:39:59 -04:00
|
|
|
{ } [ <promise> "port" set ] unit-test
|
2008-05-19 21:43:28 -04:00
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{ } [ [ drop "hi" write ] server-test ] unit-test
|
2008-05-19 21:43:28 -04:00
|
|
|
|
2008-05-17 18:45:56 -04:00
|
|
|
[
|
|
|
|
<secure-config> [
|
2017-12-17 19:49:52 -05:00
|
|
|
"localhost" "port" get ?promise-test <inet> f <secure> ascii
|
2008-05-17 18:45:56 -04:00
|
|
|
<client> drop dispose
|
|
|
|
] with-secure-context
|
|
|
|
] [ certificate-verify-error? ] must-fail-with
|
2008-05-21 02:36:30 -04:00
|
|
|
|
|
|
|
! Client-side handshake timeout
|
2015-07-03 12:39:59 -04:00
|
|
|
{ } [ <promise> "port" set ] unit-test
|
2008-05-21 02:36:30 -04:00
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{ } [
|
2008-05-21 02:36:30 -04:00
|
|
|
[
|
2012-08-25 22:44:22 -04:00
|
|
|
[
|
2015-07-02 13:34:01 -04:00
|
|
|
"127.0.0.1" 0 <inet4> ascii <server> &dispose
|
2012-08-25 22:44:22 -04:00
|
|
|
dup addr>> port>> "port" get fulfill
|
|
|
|
accept drop &dispose 1 minutes sleep
|
|
|
|
] with-destructors
|
2008-05-21 02:36:30 -04:00
|
|
|
] "Silly server" spawn drop
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[
|
|
|
|
1 seconds secure-socket-timeout [
|
|
|
|
client-test
|
|
|
|
] with-variable
|
|
|
|
] [ io-timeout? ] must-fail-with
|
|
|
|
|
|
|
|
! Server-side handshake timeout
|
2015-07-03 12:39:59 -04:00
|
|
|
{ } [ <promise> "port" set ] unit-test
|
2008-05-21 02:36:30 -04:00
|
|
|
|
2015-07-03 12:39:59 -04:00
|
|
|
{ } [
|
2008-05-21 02:36:30 -04:00
|
|
|
[
|
2012-08-25 22:44:22 -04:00
|
|
|
[
|
2017-12-17 19:49:52 -05:00
|
|
|
"127.0.0.1" "port" get ?promise-test
|
2012-08-25 22:44:22 -04:00
|
|
|
<inet4> ascii <client> drop &dispose 1 minutes sleep
|
|
|
|
] with-destructors
|
2008-05-21 02:36:30 -04:00
|
|
|
] "Silly client" spawn drop
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[
|
|
|
|
1 seconds secure-socket-timeout [
|
|
|
|
[
|
2012-08-25 22:44:22 -04:00
|
|
|
[
|
2016-03-02 18:29:59 -05:00
|
|
|
"127.0.0.1" 0 <inet4> f <secure> ascii <server> [
|
2012-08-25 22:44:22 -04:00
|
|
|
dup addr>> addrspec>> port>> "port" get fulfill
|
|
|
|
accept drop &dispose dup stream-read1 drop
|
|
|
|
] with-disposal
|
|
|
|
] with-destructors
|
2008-05-21 02:36:30 -04:00
|
|
|
] with-test-context
|
|
|
|
] with-variable
|
|
|
|
] [ io-timeout? ] must-fail-with
|
|
|
|
|
|
|
|
! Client socket shutdown timeout
|
|
|
|
|
2008-05-22 01:29:19 -04:00
|
|
|
! Until I sort out two-stage handshaking, I can't do much here
|
2008-05-21 02:36:30 -04:00
|
|
|
[
|
2008-05-22 01:29:19 -04:00
|
|
|
[ ] [ <promise> "port" set ] unit-test
|
2015-07-02 13:34:01 -04:00
|
|
|
|
2008-05-22 01:29:19 -04:00
|
|
|
[ ] [
|
2008-05-21 02:36:30 -04:00
|
|
|
[
|
2008-05-22 01:29:19 -04:00
|
|
|
[
|
2012-08-25 22:44:22 -04:00
|
|
|
[
|
2016-03-02 18:29:59 -05:00
|
|
|
"127.0.0.1" 0 <inet4> f <secure> ascii <server> [
|
2012-08-25 22:44:22 -04:00
|
|
|
dup addr>> addrspec>> port>> "port" get fulfill
|
|
|
|
accept drop &dispose 1 minutes sleep
|
|
|
|
] with-disposal
|
|
|
|
] with-test-context
|
|
|
|
] with-destructors
|
2008-05-22 01:29:19 -04:00
|
|
|
] "Silly server" spawn drop
|
|
|
|
] unit-test
|
2015-07-02 13:34:01 -04:00
|
|
|
|
2008-05-22 01:29:19 -04:00
|
|
|
[
|
|
|
|
1 seconds secure-socket-timeout [
|
|
|
|
<secure-config> [
|
2017-12-17 19:49:52 -05:00
|
|
|
"127.0.0.1" "port" get ?promise-test <inet4> f <secure>
|
2008-05-22 01:29:19 -04:00
|
|
|
ascii <client> drop dispose
|
|
|
|
] with-secure-context
|
|
|
|
] with-variable
|
|
|
|
] [ io-timeout? ] must-fail-with
|
2015-07-02 13:34:01 -04:00
|
|
|
|
2008-05-22 01:29:19 -04:00
|
|
|
! Server socket shutdown timeout
|
|
|
|
[ ] [ <promise> "port" set ] unit-test
|
2015-07-02 13:34:01 -04:00
|
|
|
|
2008-05-22 01:29:19 -04:00
|
|
|
[ ] [
|
2008-05-21 16:54:27 -04:00
|
|
|
[
|
2008-05-22 01:29:19 -04:00
|
|
|
[
|
2012-08-25 22:44:22 -04:00
|
|
|
[
|
2017-12-17 19:49:52 -05:00
|
|
|
"127.0.0.1" "port" get ?promise-test
|
2016-03-02 18:29:59 -05:00
|
|
|
<inet4> f <secure> ascii <client> drop &dispose 1 minutes sleep
|
2012-08-25 22:44:22 -04:00
|
|
|
] with-test-context
|
|
|
|
] with-destructors
|
2008-05-22 01:29:19 -04:00
|
|
|
] "Silly client" spawn drop
|
|
|
|
] unit-test
|
2015-07-02 13:34:01 -04:00
|
|
|
|
2008-05-22 01:29:19 -04:00
|
|
|
[
|
2012-08-25 22:44:22 -04:00
|
|
|
[
|
|
|
|
1 seconds secure-socket-timeout [
|
|
|
|
[
|
2016-03-02 18:29:59 -05:00
|
|
|
"127.0.0.1" 0 <inet4> f <secure> ascii <server> [
|
2012-08-25 22:44:22 -04:00
|
|
|
dup addr>> addrspec>> port>> "port" get fulfill
|
|
|
|
accept drop &dispose
|
|
|
|
] with-disposal
|
|
|
|
] with-test-context
|
|
|
|
] with-variable
|
|
|
|
] with-destructors
|
2008-05-22 01:29:19 -04:00
|
|
|
] [ io-timeout? ] must-fail-with
|
|
|
|
] drop
|