Codebase list libpoe-component-sslify-perl / ffbe1df
use Test::FailWarnings and migrate to done_testing Apocalypse 9 years ago
11 changed file(s) with 227 addition(s) and 353 deletion(s). Raw diff Collapse all Expand all
33 # Thanks to ASCENT for this test!
44 # This tests the basic functionality of sslify on client/server side
55
6 my $numtests;
7 BEGIN {
8 $numtests = 16;
9
10 eval "use Test::NoWarnings";
11 if ( ! $@ ) {
12 # increment by one
13 $numtests++;
14 }
15 }
16
17 use Test::More tests => $numtests;
6 use Test::FailWarnings;
7 use Test::More 1.001002; # new enough for sanity in done_testing()
188
199 use POE 1.267;
2010 use POE::Component::Client::TCP;
154144
155145 $poe_kernel->run();
156146
157 pass( 'shut down sanely' );
158
159 exit 0;
147 done_testing;
33 # Thanks to ASCENT for this test!
44 # This test adds renegotiation to the connection from client-side
55
6 # In an older version of this test, there was ok() littered everywhere
7 # but dngor replied in http://rt.cpan.org/Public/Bug/Display.html?id=66741
8 # that it's not going to work... how do I predict which ok() will fail and "simulate" them?
9 # the solution was to... only run a few tests and print the diag
10 # because the rest of the tests just redo what we already have in 1_simple.t and stuff...
11
12 my $numtests;
13 BEGIN {
14 $numtests = 16;
15
16 eval "use Test::NoWarnings";
17 if ( ! $@ ) {
18 # increment by one
19 $numtests++;
20 }
21 }
22
23 use Test::More tests => $numtests;
6 use Test::FailWarnings;
7 use Test::More 1.001002; # new enough for sanity in done_testing()
248
259 use POE 1.267;
2610 use POE::Component::Client::TCP;
173157 diag( "Please talk with the author to figure out if this issue can be worked around, thank you!" );
174158 }
175159
176 pass( 'shut down sanely' );
177
178 exit 0;
160 done_testing;
22
33 # This tests in-situ sslification ( upgrade a non-ssl socket to ssl )
44
5 my $numtests;
6 BEGIN {
7 $numtests = 18;
8
9 eval "use Test::NoWarnings";
10 if ( ! $@ ) {
11 # increment by one
12 $numtests++;
13 }
14 }
15
16 use Test::More tests => $numtests;
5 use Test::FailWarnings;
6 use Test::More 1.001002; # new enough for sanity in done_testing()
177
188 use POE 1.267;
199 use POE::Component::Client::TCP;
178168
179169 $poe_kernel->run();
180170
181 pass( 'shut down sanely' );
182
183 exit 0;
171 done_testing;
22
33 # This tests the connection OK hook on both server/client
44
5 my $numtests;
6 BEGIN {
7 $numtests = 19;
8
9 eval "use Test::NoWarnings";
10 if ( ! $@ ) {
11 # increment by one
12 $numtests++;
13 }
14 }
15
16 use Test::More tests => $numtests;
5 use Test::FailWarnings;
6 use Test::More 1.001002; # new enough for sanity in done_testing()
177
188 use POE 1.267;
199 use POE::Component::Client::TCP;
153143
154144 $poe_kernel->run();
155145
156 pass( 'shut down sanely' );
157
158 exit 0;
146 done_testing;
22
33 # this tests the connection fail hook on the client-side
44
5 my $numtests;
6 BEGIN {
7 $numtests = 8;
8
9 eval "use Test::NoWarnings";
10 if ( ! $@ ) {
11 # increment by one
12 $numtests++;
13 }
14 }
15
16 use Test::More tests => $numtests;
5 use Test::FailWarnings;
6 use Test::More 1.001002; # new enough for sanity in done_testing()
177
188 use POE 1.267;
199 use POE::Component::Client::TCP;
10797
10898 $poe_kernel->run();
10999
110 pass( 'shut down sanely' );
111
112 exit 0;
100 done_testing;
22
33 # this tests the connection fail hook on the server-side
44
5 my $numtests;
6 BEGIN {
7 $numtests = 9;
8
9 eval "use Test::NoWarnings";
10 if ( ! $@ ) {
11 # increment by one
12 $numtests++;
13 }
14 }
15
16 use Test::More tests => $numtests;
5 use Test::FailWarnings;
6 use Test::More 1.001002; # new enough for sanity in done_testing()
177
188 use POE 1.267;
199 use POE::Component::Client::TCP;
110100
111101 $poe_kernel->run();
112102
113 pass( 'shut down sanely' );
114
115 exit 0;
103 done_testing;
22
33 # This tests the connection OK hook on both server/client
44
5 my $numtests;
6 BEGIN {
7 $numtests = 17;
8
9 eval "use Test::NoWarnings";
10 if ( ! $@ ) {
11 # increment by one
12 $numtests++;
13 }
14 }
15
16 use Test::More tests => $numtests;
5 use Test::FailWarnings;
6 use Test::More 1.001002; # new enough for sanity in done_testing()
177
188 use POE 1.267;
199 use POE::Component::Client::TCP;
144134
145135 $poe_kernel->run();
146136
147 pass( 'shut down sanely' );
148
149 exit 0;
137 done_testing;
33 # Thanks to ASCENT for this test!
44 # This test adds renegotiation to the connection from server-side
55
6 # In an older version of this test, there was ok() littered everywhere
7 # but dngor replied in http://rt.cpan.org/Public/Bug/Display.html?id=66741
8 # that it's not going to work... how do I predict which ok() will fail and "simulate" them?
9 # the solution was to... only run a few tests and print the diag
10 # because the rest of the tests just redo what we already have in 1_simple.t and stuff...
11
12 my $numtests;
13 BEGIN {
14 $numtests = 16;
15
16 eval "use Test::NoWarnings";
17 if ( ! $@ ) {
18 # increment by one
19 $numtests++;
20 }
21 }
22
23 use Test::More tests => $numtests;
6 use Test::FailWarnings;
7 use Test::More 1.001002; # new enough for sanity in done_testing()
248
259 use POE 1.267;
2610 use POE::Component::Client::TCP;
170154 diag( "Please talk with the author to figure out if this issue can be worked around, thank you!" );
171155 }
172156
173 pass( 'shut down sanely' );
174
175 exit 0;
157 done_testing;
+0
-215
t/98_renegotiate.t less more
0 #!/usr/bin/perl
1 use strict; use warnings;
2
3 # Thanks to ASCENT for this test!
4 # This test adds renegotiation to the connection from client-side
5 # Since this is not supported on all platforms, it's marked TODO and adds custom logic
6 # to make sure it doesn't FAIL if it's not supported.
7
8 # this version of the test doesn't work as reported in http://rt.cpan.org/Public/Bug/Display.html?id=66741
9 # renamed it to this version for posterity and in case I need it for future analysis...
10
11 #my $numtests;
12 #BEGIN {
13 # $numtests = 23;
14 #
15 # eval "use Test::NoWarnings";
16 # if ( ! $@ ) {
17 # # increment by one
18 # $numtests++;
19 # }
20 #}
21
22 #use Test::More tests => $numtests;
23 use Test::More;
24 BEGIN {
25 plan skip_all => "AUTHOR TEST";
26 }
27
28 use POE 1.267;
29 use POE::Component::Client::TCP;
30 use POE::Component::Server::TCP;
31 use POE::Component::SSLify qw/Client_SSLify Server_SSLify SSLify_Options SSLify_GetCipher SSLify_ContextCreate SSLify_GetSocket SSLify_GetSSL/;
32 use Net::SSLeay qw/ERROR_WANT_READ ERROR_WANT_WRITE/;
33
34 # TODO rewrite this to use Test::POE::Server::TCP and stuff :)
35
36 my $port;
37 my $server_ping2;
38 my $client_ping2;
39
40 POE::Component::Server::TCP->new
41 (
42 Alias => 'myserver',
43 Address => '127.0.0.1',
44 Port => 0,
45
46 Started => sub
47 {
48 use Socket qw/sockaddr_in/;
49 $port = (sockaddr_in($_[HEAP]->{listener}->getsockname))[0];
50 },
51 ClientConnected => sub
52 {
53 ok(1, 'SERVER: accepted');
54 },
55 ClientDisconnected => sub
56 {
57 ok(1, 'SERVER: client disconnected');
58 $_[KERNEL]->post(myserver => 'shutdown');
59 },
60 ClientPreConnect => sub
61 {
62 eval { SSLify_Options('mylib/example.key', 'mylib/example.crt', 'sslv3') };
63 eval { SSLify_Options('../mylib/example.key', '../mylib/example.crt', 'sslv3') } if ($@);
64 ok(!$@, "SERVER: SSLify_Options $@");
65
66 my $socket = eval { Server_SSLify($_[ARG0]) };
67 ok(!$@, "SERVER: Server_SSLify $@");
68 ok(1, 'SERVER: SSLify_GetCipher: '. SSLify_GetCipher($socket));
69
70 # We pray that IO::Handle is sane...
71 ok( SSLify_GetSocket( $socket )->blocking == 0, 'SERVER: SSLified socket is non-blocking?');
72
73 return ($socket);
74 },
75 ClientInput => sub
76 {
77 my ($kernel, $heap, $request) = @_[KERNEL, HEAP, ARG0];
78
79 ## At this point, connection MUST be encrypted.
80 my $cipher = SSLify_GetCipher($heap->{client}->get_output_handle);
81 ok($cipher ne '(NONE)', "SERVER: SSLify_GetCipher: $cipher");
82
83 if ($request eq 'ping')
84 {
85 ok(1, "SERVER: recv: $request");
86 $heap->{client}->put("pong");
87 }
88 elsif ($request eq 'ping2')
89 {
90 ok(1, "SERVER: recv: $request");
91 $server_ping2++;
92 $heap->{client}->put("pong2");
93 }
94 },
95 ClientError => sub
96 {
97 # Thanks to H. Merijn Brand for spotting this FAIL in 5.12.0!
98 # The default PoCo::Server::TCP handler will throw a warning, which causes Test::NoWarnings to FAIL :(
99 my ($syscall, $errno, $error) = @_[ ARG0..ARG2 ];
100
101 # TODO are there other "errors" that is harmless?
102 $error = "Normal disconnection" unless $error;
103 my $msg = "Got SERVER $syscall error $errno: $error";
104 unless ( $syscall eq 'read' and $errno == 0 ) {
105 fail( $msg );
106 } else {
107 diag( $msg ) if $ENV{TEST_VERBOSE};
108 }
109 },
110 );
111
112 POE::Component::Client::TCP->new
113 (
114 Alias => 'myclient',
115 RemoteAddress => '127.0.0.1',
116 RemotePort => $port,
117
118 Connected => sub
119 {
120 ok(1, 'CLIENT: connected');
121
122 $_[HEAP]->{server}->put("ping");
123 },
124 PreConnect => sub
125 {
126 my $ctx = eval { SSLify_ContextCreate(undef, undef, 'sslv3') };
127 ok(!$@, "CLIENT: SSLify_ContextCreate $@");
128 my $socket = eval { Client_SSLify($_[ARG0], undef, undef, $ctx) };
129 ok(!$@, "CLIENT: Client_SSLify $@");
130 ok(1, 'CLIENT: SSLify_GetCipher: '. SSLify_GetCipher($socket));
131
132 # We pray that IO::Handle is sane...
133 ok( SSLify_GetSocket( $socket )->blocking == 0, 'CLIENT: SSLified socket is non-blocking?');
134
135 return ($socket);
136 },
137 ServerInput => sub
138 {
139 my ($kernel, $heap, $line) = @_[KERNEL, HEAP, ARG0];
140
141 ## At this point, connection MUST be encrypted.
142 my $cipher = SSLify_GetCipher($heap->{server}->get_output_handle);
143 ok($cipher ne '(NONE)', "CLIENT: SSLify_GetCipher: $cipher");
144
145 if ($line eq 'pong')
146 {
147 ok(1, "CLIENT: recv: $line");
148
149 # Skip 2 Net::SSLeay::renegotiate() tests on FreeBSD because of
150 # http://security.freebsd.org/advisories/FreeBSD-SA-09:15.ssl.asc
151 TODO: {
152 local $TODO = "Net::SSLeay::renegotiate() does not work on all platforms";
153
154 ## Force SSL renegotiation
155 my $ssl = SSLify_GetSSL( $heap->{server}->get_output_handle );
156 my $reneg_num = Net::SSLeay::num_renegotiations($ssl);
157
158 ok(1 == Net::SSLeay::renegotiate($ssl), 'CLIENT: SSL renegotiation');
159 my $handshake = Net::SSLeay::do_handshake($ssl);
160 my $err = Net::SSLeay::get_error($ssl, $handshake);
161
162 ## 1 == Successful handshake, ERROR_WANT_(READ|WRITE) == non-blocking.
163 ok($handshake == 1 || $err == ERROR_WANT_READ || $err == ERROR_WANT_WRITE, 'CLIENT: SSL handshake');
164 ok($reneg_num < Net::SSLeay::num_renegotiations($ssl), 'CLIENT: Increased number of negotiations');
165 }
166
167 $heap->{server}->put('ping2');
168 }
169
170 elsif ($line eq 'pong2')
171 {
172 ok(1, "CLIENT: recv: $line");
173 $client_ping2++;
174 $kernel->yield('shutdown');
175 }
176 },
177 ServerError => sub
178 {
179 # Thanks to H. Merijn Brand for spotting this FAIL in 5.12.0!
180 # The default PoCo::Client::TCP handler will throw a warning, which causes Test::NoWarnings to FAIL :(
181 my ($syscall, $errno, $error) = @_[ ARG0..ARG2 ];
182
183 # TODO are there other "errors" that is harmless?
184 $error = "Normal disconnection" unless $error;
185 my $msg = "Got CLIENT $syscall error $errno: $error";
186 unless ( $syscall eq 'read' and $errno == 0 ) {
187 fail( $msg );
188 } else {
189 diag( $msg ) if $ENV{TEST_VERBOSE};
190 }
191 },
192 );
193
194 $poe_kernel->run();
195
196 # Add extra pass() to make the test harness happy if renegotiate did not work
197 if ( ! $server_ping2 ) {
198 local $TODO = "Net::SSLeay::renegotiate() does not work on all platforms";
199 fail( "SERVER: Failed SSL renegotiation" );
200 }
201 if ( ! $client_ping2 ) {
202 local $TODO = "Net::SSLeay::renegotiate() does not work on all platforms";
203 fail( "CLIENT: Failed SSL renegotiation" );
204 }
205 if ( ! $server_ping2 or ! $client_ping2 ) {
206 diag( "WARNING: Your platform/SSL library does not support renegotiation of the SSL socket." );
207 diag( "This test harness detected that trying to renegotiate resulted in a disconnected socket." );
208 diag( "POE::Component::SSLify will work on your system, but please do not attempt a SSL renegotiate." );
209 diag( "Please talk with the author to figure out if this issue can be worked around, thank you!" );
210 }
211
212 pass( 'shut down sanely' );
213
214 exit 0;
1010 # sub POE::Kernel::CATCH_EXCEPTIONS () { 0 } # make sure we die right away so it's easier to debug
1111 }
1212
13 use Test::More;
14 BEGIN {
15 plan skip_all => "AUTHOR TEST";
16 }
17
1318 use strict;
1419 use warnings;
1520 use POE;
16
17 use Test::More;
18 BEGIN {
19 plan skip_all => "AUTHOR TEST";
20 }
21 use Test::FailWarnings;
2122
2223 our $DEBUG=0;
2324
257258 },)->ID;
258259
259260 POE::Kernel->run();
260 exit;
261 done_testing;
0 #!/usr/bin/perl
1 use strict; use warnings;
2
3 # Thanks to ASCENT for this test!
4 # This test adds renegotiation to the connection from client-side
5 # Since this is not supported on all platforms, it's marked TODO and adds custom logic
6 # to make sure it doesn't FAIL if it's not supported.
7
8 use Test::FailWarnings;
9 use Test::More 1.001002; # new enough for sanity in done_testing()
10
11 use POE 1.267;
12 use POE::Component::Client::TCP;
13 use POE::Component::Server::TCP;
14 use POE::Component::SSLify qw/Client_SSLify Server_SSLify SSLify_Options SSLify_GetCipher SSLify_ContextCreate SSLify_GetSocket SSLify_GetSSL/;
15 use Net::SSLeay qw/ERROR_WANT_READ ERROR_WANT_WRITE/;
16
17 # TODO rewrite this to use Test::POE::Server::TCP and stuff :)
18
19 my $port;
20 my $server_ping2;
21 my $client_ping2;
22
23 POE::Component::Server::TCP->new
24 (
25 Alias => 'myserver',
26 Address => '127.0.0.1',
27 Port => 0,
28
29 Started => sub
30 {
31 use Socket qw/sockaddr_in/;
32 $port = (sockaddr_in($_[HEAP]->{listener}->getsockname))[0];
33 },
34 ClientConnected => sub
35 {
36 ok(1, 'SERVER: accepted');
37 },
38 ClientDisconnected => sub
39 {
40 ok(1, 'SERVER: client disconnected');
41 $_[KERNEL]->post(myserver => 'shutdown');
42 },
43 ClientPreConnect => sub
44 {
45 eval { SSLify_Options('mylib/example.key', 'mylib/example.crt', 'sslv3') };
46 eval { SSLify_Options('../mylib/example.key', '../mylib/example.crt', 'sslv3') } if ($@);
47 ok(!$@, "SERVER: SSLify_Options $@");
48
49 my $socket = eval { Server_SSLify($_[ARG0]) };
50 ok(!$@, "SERVER: Server_SSLify $@");
51 ok(1, 'SERVER: SSLify_GetCipher: '. SSLify_GetCipher($socket));
52
53 # We pray that IO::Handle is sane...
54 ok( SSLify_GetSocket( $socket )->blocking == 0, 'SERVER: SSLified socket is non-blocking?');
55
56 return ($socket);
57 },
58 ClientInput => sub
59 {
60 my ($kernel, $heap, $request) = @_[KERNEL, HEAP, ARG0];
61
62 ## At this point, connection MUST be encrypted.
63 my $cipher = SSLify_GetCipher($heap->{client}->get_output_handle);
64 ok($cipher ne '(NONE)', "SERVER: SSLify_GetCipher: $cipher");
65
66 if ($request eq 'ping')
67 {
68 ok(1, "SERVER: recv: $request");
69 $heap->{client}->put("pong");
70 }
71 elsif ($request eq 'ping2')
72 {
73 ok(1, "SERVER: recv: $request");
74 $server_ping2++;
75 $heap->{client}->put("pong2");
76 }
77 },
78 ClientError => sub
79 {
80 # Thanks to H. Merijn Brand for spotting this FAIL in 5.12.0!
81 # The default PoCo::Server::TCP handler will throw a warning, which causes Test::NoWarnings to FAIL :(
82 my ($syscall, $errno, $error) = @_[ ARG0..ARG2 ];
83
84 # TODO are there other "errors" that is harmless?
85 $error = "Normal disconnection" unless $error;
86 my $msg = "Got SERVER $syscall error $errno: $error";
87 unless ( $syscall eq 'read' and $errno == 0 ) {
88 fail( $msg );
89 } else {
90 diag( $msg ) if $ENV{TEST_VERBOSE};
91 }
92 },
93 );
94
95 POE::Component::Client::TCP->new
96 (
97 Alias => 'myclient',
98 RemoteAddress => '127.0.0.1',
99 RemotePort => $port,
100
101 Connected => sub
102 {
103 ok(1, 'CLIENT: connected');
104
105 $_[HEAP]->{server}->put("ping");
106 },
107 PreConnect => sub
108 {
109 my $ctx = eval { SSLify_ContextCreate(undef, undef, 'sslv3') };
110 ok(!$@, "CLIENT: SSLify_ContextCreate $@");
111 my $socket = eval { Client_SSLify($_[ARG0], undef, undef, $ctx) };
112 ok(!$@, "CLIENT: Client_SSLify $@");
113 ok(1, 'CLIENT: SSLify_GetCipher: '. SSLify_GetCipher($socket));
114
115 # We pray that IO::Handle is sane...
116 ok( SSLify_GetSocket( $socket )->blocking == 0, 'CLIENT: SSLified socket is non-blocking?');
117
118 return ($socket);
119 },
120 ServerInput => sub
121 {
122 my ($kernel, $heap, $line) = @_[KERNEL, HEAP, ARG0];
123
124 ## At this point, connection MUST be encrypted.
125 my $cipher = SSLify_GetCipher($heap->{server}->get_output_handle);
126 ok($cipher ne '(NONE)', "CLIENT: SSLify_GetCipher: $cipher");
127
128 if ($line eq 'pong')
129 {
130 ok(1, "CLIENT: recv: $line");
131
132 # Skip 2 Net::SSLeay::renegotiate() tests on FreeBSD because of
133 # http://security.freebsd.org/advisories/FreeBSD-SA-09:15.ssl.asc
134 TODO: {
135 local $TODO = "Net::SSLeay::renegotiate() does not work on all platforms";
136
137 ## Force SSL renegotiation
138 my $ssl = SSLify_GetSSL( $heap->{server}->get_output_handle );
139 my $reneg_num = Net::SSLeay::num_renegotiations($ssl);
140
141 ok(1 == Net::SSLeay::renegotiate($ssl), 'CLIENT: SSL renegotiation');
142 my $handshake = Net::SSLeay::do_handshake($ssl);
143 my $err = Net::SSLeay::get_error($ssl, $handshake);
144
145 ## 1 == Successful handshake, ERROR_WANT_(READ|WRITE) == non-blocking.
146 ok($handshake == 1 || $err == ERROR_WANT_READ || $err == ERROR_WANT_WRITE, 'CLIENT: SSL handshake');
147 ok($reneg_num < Net::SSLeay::num_renegotiations($ssl), 'CLIENT: Increased number of negotiations');
148 }
149
150 $heap->{server}->put('ping2');
151 }
152
153 elsif ($line eq 'pong2')
154 {
155 ok(1, "CLIENT: recv: $line");
156 $client_ping2++;
157 $kernel->yield('shutdown');
158 }
159 },
160 ServerError => sub
161 {
162 # Thanks to H. Merijn Brand for spotting this FAIL in 5.12.0!
163 # The default PoCo::Client::TCP handler will throw a warning, which causes Test::NoWarnings to FAIL :(
164 my ($syscall, $errno, $error) = @_[ ARG0..ARG2 ];
165
166 # TODO are there other "errors" that is harmless?
167 $error = "Normal disconnection" unless $error;
168 my $msg = "Got CLIENT $syscall error $errno: $error";
169 unless ( $syscall eq 'read' and $errno == 0 ) {
170 fail( $msg );
171 } else {
172 diag( $msg ) if $ENV{TEST_VERBOSE};
173 }
174 },
175 );
176
177 $poe_kernel->run();
178
179 # Add extra pass() to make the test harness happy if renegotiate did not work
180 if ( ! $server_ping2 ) {
181 local $TODO = "Net::SSLeay::renegotiate() does not work on all platforms";
182 fail( "SERVER: Failed SSL renegotiation" );
183 }
184 if ( ! $client_ping2 ) {
185 local $TODO = "Net::SSLeay::renegotiate() does not work on all platforms";
186 fail( "CLIENT: Failed SSL renegotiation" );
187 }
188 if ( ! $server_ping2 or ! $client_ping2 ) {
189 diag( "WARNING: Your platform/SSL library does not support renegotiation of the SSL socket." );
190 diag( "This test harness detected that trying to renegotiate resulted in a disconnected socket." );
191 diag( "POE::Component::SSLify will work on your system, but please do not attempt a SSL renegotiate." );
192 diag( "Please talk with the author to figure out if this issue can be worked around, thank you!" );
193 }
194
195 done_testing;