]> gitweb.factorcode.org Git - factor.git/commitdiff
io.sockets.secure.unix: simplify tests
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 28 Apr 2023 04:53:46 +0000 (21:53 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 28 Apr 2023 04:54:06 +0000 (21:54 -0700)
basis/io/sockets/secure/unix/unix-tests.factor

index 452acda29f69597769faba692dfe27b5da7f0986..48c8bce4b02a490ff644afa582798c42143f5ef8 100644 (file)
@@ -9,27 +9,18 @@ IN: io.sockets.secure.tests
 
 { 1 0 } [ [ ] with-secure-context ] must-infer-as
 
-{ } [ <promise> "port" set ] unit-test
-
-:: server-test ( quot -- )
+:: server-test ( quot: ( remote -- ) -- )
     [
         [
             "127.0.0.1" 0 <inet4> f <secure> ascii <server> [
                 dup addr>> addrspec>> port>> "port" get fulfill
-                accept [
-                    quot call
-                ] curry with-stream
+                accept quot curry with-stream
             ] with-disposal
         ] with-test-context
-    ] "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 ;
+    ] "SSL server test" spawn drop ;
 
 : ?promise-test ( mailbox -- obj )
-    340 milliseconds ?promise-timeout ;
+    500 milliseconds ?promise-timeout ;
 
 : client-test ( -- string )
     <secure-config> [
@@ -38,40 +29,28 @@ IN: io.sockets.secure.tests
         [ stream-contents ] with-timeout*
     ] with-secure-context ;
 
-! { } [ [ class-of name>> write "done" my-mailbox mailbox-put ] server-test ] unit-test
-{ } [ [ class-of name>> write ] server-test ] unit-test
-
-{ "secure" } [ client-test ] unit-test
+! Simple test, write/read
+{ "secure" } [
+    <promise> "port" set
+    [ class-of name>> write ] server-test
+    client-test
+] unit-test
 
 ! Now, see what happens if the server closes the connection prematurely
-{ } [ <promise> "port" set ] unit-test
-
-{ } [
+[
+    <promise> "port" set
     [
         drop
-        "hello" write flush
         input-stream get stream>> handle>> f >>connected drop
     ] server-test
-] unit-test
-
-! Actually, this should not be an error since many HTTPS servers
-! (eg, google.com) do this.
-! [ client-test ] [ premature-close-error? ] must-fail-with
-
-! Started failing on Ubuntu 22 with libssl3 3.0.1
-! server-test disconnects on purpose, client-test fails with
-! error:0A000197:SSL routines::shutdown while in init
-! Seems like it should fail, but fix this if you can!
-! { "hello" } [ client-test ] unit-test
-
+    client-test
+] [ premature-close-error? ] must-fail-with
 
 ! Now, try validating the certificate. This should fail because its
 ! actually an invalid certificate
-{ } [ <promise> "port" set ] unit-test
-
-{ } [ [ drop "hi" write ] server-test ] unit-test
-
 [
+    <promise> "port" set
+    [ drop "hi" write ] server-test
     <secure-config> [
         "localhost" "port" get ?promise-test <inet> f <secure> ascii
         <client> drop dispose
@@ -79,37 +58,25 @@ IN: io.sockets.secure.tests
 ] [ certificate-verify-error? ] must-fail-with
 
 ! Client-side handshake timeout
-{ } [ <promise> "port" set ] unit-test
-
-{ } [
-    [
-        [
-            "127.0.0.1" 0 <inet4> ascii <server> &dispose
-                dup addr>> port>> "port" get fulfill
-                accept drop &dispose 1 minutes sleep
-        ] with-destructors
-    ] "Silly server" spawn drop
-] unit-test
-
 [
+    <promise> "port" set
+    [ 5 seconds sleep ] server-test
     1 seconds secure-socket-timeout [
         client-test
     ] with-variable
 ] [ io-timeout? ] must-fail-with
 
 ! Server-side handshake timeout
-{ } [ <promise> "port" set ] unit-test
+[
+    <promise> "port" set
 
-{ } [
     [
         [
             "127.0.0.1" "port" get ?promise-test
-            <inet4> ascii <client> drop &dispose 1 minutes sleep
+            <inet4> ascii <client> drop &dispose 5 seconds sleep
         ] with-destructors
     ] "Silly client" spawn drop
-] unit-test
 
-[
     1 seconds secure-socket-timeout [
         [
             [
@@ -122,62 +89,6 @@ IN: io.sockets.secure.tests
     ] with-variable
 ] [ io-timeout? ] must-fail-with
 
-! Client socket shutdown timeout
-
-! Until I sort out two-stage handshaking, I can't do much here
-[
-    [ ] [ <promise> "port" set ] unit-test
-
-    [ ] [
-        [
-            [
-                [
-                    "127.0.0.1" 0 <inet4> f <secure> ascii <server> [
-                        dup addr>> addrspec>> port>> "port" get fulfill
-                        accept drop &dispose 1 minutes sleep
-                    ] with-disposal
-                ] with-test-context
-            ] with-destructors
-        ] "Silly server" spawn drop
-    ] unit-test
-
-    [
-        1 seconds secure-socket-timeout [
-            <secure-config> [
-                "127.0.0.1" "port" get ?promise-test <inet4> f <secure>
-                ascii <client> drop dispose
-            ] with-secure-context
-        ] with-variable
-    ] [ io-timeout? ] must-fail-with
-
-    ! Server socket shutdown timeout
-    [ ] [ <promise> "port" set ] unit-test
-
-    [ ] [
-        [
-            [
-                [
-                    "127.0.0.1" "port" get ?promise-test
-                    <inet4> f <secure> ascii <client> drop &dispose 1 minutes sleep
-                ] with-test-context
-            ] with-destructors
-        ] "Silly client" spawn drop
-    ] unit-test
-
-    [
-        [
-            1 seconds secure-socket-timeout [
-                [
-                    "127.0.0.1" 0 <inet4> f <secure> ascii <server> [
-                        dup addr>> addrspec>> port>> "port" get fulfill
-                        accept drop &dispose
-                    ] with-disposal
-                ] with-test-context
-            ] with-variable
-        ] with-destructors
-    ] [ io-timeout? ] must-fail-with
-] drop
-
 { } [
     [ download-my-image ] with-temp-directory
 ] unit-test