]> gitweb.factorcode.org Git - factor.git/commitdiff
openssl.libssl: new destructors, to make sure the tests doesnt leak
authorBjörn Lindqvist <bjourne@gmail.com>
Sat, 19 Nov 2016 17:03:12 +0000 (18:03 +0100)
committerBjörn Lindqvist <bjourne@gmail.com>
Sat, 19 Nov 2016 17:03:12 +0000 (18:03 +0100)
basis/openssl/libssl/libssl-tests.factor
basis/openssl/libssl/libssl.factor

index 507c01eb448f86443f37a7640f2f2be249a984bd..dcbe9b98a8d7a6a93b8448b1039bff81c4664489 100644 (file)
@@ -1,4 +1,5 @@
-USING: arrays kernel math openssl.libssl sequences tools.test ;
+USING: arrays destructors kernel math openssl openssl.libssl sequences
+tools.test ;
 USING: openssl ;
 
 IN: openssl.libssl.tests
@@ -20,29 +21,50 @@ maybe-init-ssl
 : has-opt ( ctx op -- ? )
     swap SSL_CTRL_OPTIONS 0 f SSL_CTX_ctrl bitand 0 > ;
 
-: new-ctx ( -- ctx )
-    TLSv1_client_method SSL_CTX_new ;
+: new-ctx ( method -- ctx )
+    SSL_CTX_new &SSL_CTX_free ;
 
-: new-ssl ( -- ssl )
-    new-ctx SSL_new ;
+: new-tls1-ctx ( -- ctx )
+    TLSv1_client_method new-ctx ;
+
+: new-ssl ( ctx -- ssl )
+    SSL_new &SSL_free ;
 
 {
     { f f f }
 } [
-    new-ctx tls-opts [ has-opt ] with map
+    [
+        new-tls1-ctx tls-opts [ has-opt ] with map
+    ] with-destructors
 ] unit-test
 
 ! Test setting options
 { 3 } [
-    new-ctx tls-opts [ [ set-opt ] [ has-opt ] 2bi ] with map [ t = ] count
+    [
+        new-tls1-ctx tls-opts [ [ set-opt ] [ has-opt ] 2bi ] with map
+        [ t = ] count
+    ] with-destructors
 ] unit-test
 
 ! Initial state
 { { "before/connect initialization" "read header" 1 f } } [
-    new-ssl {
-        SSL_state_string_long
-        SSL_rstate_string_long
-        SSL_want
-        SSL_get_peer_certificate
-    } [ execute( x -- x ) ] with map
+    [
+        new-tls1-ctx new-ssl {
+            SSL_state_string_long
+            SSL_rstate_string_long
+            SSL_want
+            SSL_get_peer_certificate
+        } [ execute( x -- x ) ] with map
+    ] with-destructors
+] unit-test
+
+: method>version-string ( method -- str )
+    new-ctx new-ssl SSL_get_version ;
+
+! SSL_get_version
+{ { "TLSv1" "TLSv1.1" "TLSv1.2" } } [
+    [
+        TLSv1_method TLSv1_1_method TLSv1_2_method 3array
+        [ method>version-string ] map
+    ] with-destructors
 ] unit-test
index 58d2bffb55a2d8b2f2841c9cf396b0cbedf256f3..c7a79998490a995e61cc2996d39a8be582ca31d1 100644 (file)
@@ -422,8 +422,9 @@ FUNCTION: int SSL_get_error ( SSL* ssl, int ret )
 FUNCTION: void SSL_set_connect_state ( SSL* ssl )
 
 FUNCTION: void SSL_set_accept_state ( SSL* ssl )
-
 FUNCTION: void SSL_free ( SSL* ssl )
+DESTRUCTOR: SSL_free
+
 FUNCTION: int SSL_accept ( SSL* ssl )
 FUNCTION: int SSL_connect ( SSL* ssl )
 FUNCTION: int SSL_read ( SSL* ssl, void* buf, int num )
@@ -448,6 +449,7 @@ FUNCTION: SSL* SSL_load_client_CA_file ( c-string file )
 ! ------------------------------------------------------------------------------
 FUNCTION: SSL_CTX* SSL_CTX_new ( ssl-method method )
 FUNCTION: void SSL_CTX_free ( SSL_CTX* ctx )
+DESTRUCTOR: SSL_CTX_free
 
 ! Load the certificates and private keys into the SSL_CTX
 FUNCTION: int SSL_CTX_use_certificate_chain_file ( SSL_CTX* ctx,