openssl.libssl: new destructors, to make sure the tests doesnt leak

char-rename
Björn Lindqvist 2016-11-19 18:03:12 +01:00
parent 317a832a86
commit cc6f03f5b5
2 changed files with 38 additions and 14 deletions

View 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 ; USING: openssl ;
IN: openssl.libssl.tests IN: openssl.libssl.tests
@ -20,29 +21,50 @@ maybe-init-ssl
: has-opt ( ctx op -- ? ) : has-opt ( ctx op -- ? )
swap SSL_CTRL_OPTIONS 0 f SSL_CTX_ctrl bitand 0 > ; swap SSL_CTRL_OPTIONS 0 f SSL_CTX_ctrl bitand 0 > ;
: new-ctx ( -- ctx ) : new-ctx ( method -- ctx )
TLSv1_client_method SSL_CTX_new ; SSL_CTX_new &SSL_CTX_free ;
: new-ssl ( -- ssl ) : new-tls1-ctx ( -- ctx )
new-ctx SSL_new ; TLSv1_client_method new-ctx ;
: new-ssl ( ctx -- ssl )
SSL_new &SSL_free ;
{ {
{ f f f } { f f f }
} [ } [
new-ctx tls-opts [ has-opt ] with map [
new-tls1-ctx tls-opts [ has-opt ] with map
] with-destructors
] unit-test ] unit-test
! Test setting options ! Test setting options
{ 3 } [ { 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 ] unit-test
! Initial state ! Initial state
{ { "before/connect initialization" "read header" 1 f } } [ { { "before/connect initialization" "read header" 1 f } } [
new-ssl { [
new-tls1-ctx new-ssl {
SSL_state_string_long SSL_state_string_long
SSL_rstate_string_long SSL_rstate_string_long
SSL_want SSL_want
SSL_get_peer_certificate SSL_get_peer_certificate
} [ execute( x -- x ) ] with map } [ 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 ] unit-test

View 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_connect_state ( SSL* ssl )
FUNCTION: void SSL_set_accept_state ( SSL* ssl ) FUNCTION: void SSL_set_accept_state ( SSL* ssl )
FUNCTION: void SSL_free ( SSL* ssl ) FUNCTION: void SSL_free ( SSL* ssl )
DESTRUCTOR: SSL_free
FUNCTION: int SSL_accept ( SSL* ssl ) FUNCTION: int SSL_accept ( SSL* ssl )
FUNCTION: int SSL_connect ( SSL* ssl ) FUNCTION: int SSL_connect ( SSL* ssl )
FUNCTION: int SSL_read ( SSL* ssl, void* buf, int num ) 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: SSL_CTX* SSL_CTX_new ( ssl-method method )
FUNCTION: void SSL_CTX_free ( SSL_CTX* ctx ) FUNCTION: void SSL_CTX_free ( SSL_CTX* ctx )
DESTRUCTOR: SSL_CTX_free
! Load the certificates and private keys into the SSL_CTX ! Load the certificates and private keys into the SSL_CTX
FUNCTION: int SSL_CTX_use_certificate_chain_file ( SSL_CTX* ctx, FUNCTION: int SSL_CTX_use_certificate_chain_file ( SSL_CTX* ctx,