]> gitweb.factorcode.org Git - factor.git/blob - basis/openssl/libssl/libssl-tests.factor
70650799a448e3c637b44a5f91d69c5fedf0c7fa
[factor.git] / basis / openssl / libssl / libssl-tests.factor
1 USING:
2     arrays
3     kernel
4     math
5     openssl.libssl
6     sequences
7     tools.test ;
8 IN: openssl.libssl.tests
9
10 : all-opts ( -- opts )
11     {
12         SSL_OP_NO_SSLv2
13         SSL_OP_NO_SSLv3
14         SSL_OP_NO_TLSv1
15         SSL_OP_NO_TLSv1_1
16         SSL_OP_NO_TLSv1_2
17     } [ execute( -- x ) ] map ;
18
19 : set-opt ( ctx op -- )
20     SSL_CTRL_OPTIONS swap f SSL_CTX_ctrl drop ;
21
22 : has-opt ( ctx op -- ? )
23     swap SSL_CTRL_OPTIONS 0 f SSL_CTX_ctrl bitand 0 > ;
24
25 : new-ctx ( -- ctx )
26     SSLv23_client_method SSL_CTX_new ;
27
28 : new-ssl ( -- ssl )
29     new-ctx SSL_new ;
30
31 ! Test default options
32 [ { f f f f f } ] [ new-ctx all-opts [ has-opt ] with map ] unit-test
33
34 ! Test setting options
35 [ 5 ] [
36     new-ctx all-opts [ [ set-opt ] [ has-opt ] 2bi ] with map [ t = ] count
37 ] unit-test
38
39 ! Initial state
40 [ { "before/connect initialization" "read header" 1 f } ] [
41     new-ssl {
42         SSL_state_string_long
43         SSL_rstate_string_long
44         SSL_want
45         SSL_get_peer_certificate
46     } [ execute( x -- x ) ] with map
47 ] unit-test