Codebase list libpoe-component-sslify-perl / f5b8e4a
more fixes and add hook testcase Apocalypse 11 years ago
2 changed file(s) with 146 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
162162 }
163163
164164 # mangle custom_ctx depending on connref
165 if ( ref $custom_ctx and ref( $custom_ctx ) eq 'CODE' ) {
165 if ( defined $custom_ctx and ref $custom_ctx and ref( $custom_ctx ) eq 'CODE' ) {
166166 $connref = $custom_ctx;
167 $custom_ctx = $ctx;
167 $custom_ctx = undef;
168168 }
169169
170170 # From IO::Handle POD
175175
176176 # Now, we create the new socket and bind it to our subclass of Net::SSLeay::Handle
177177 my $newsock = gensym();
178 tie( *$newsock, 'POE::Component::SSLify::ServerHandle', $socket, $custom_ctx, $connref ) or die "Unable to tie to our subclass: $!";
178 tie( *$newsock, 'POE::Component::SSLify::ServerHandle', $socket, ( $custom_ctx || $ctx ), $connref ) or die "Unable to tie to our subclass: $!";
179179
180180 # All done!
181181 return $newsock;
0 #!/usr/bin/perl
1
2 # Thanks to ASCENT for this test!
3
4 use strict; use warnings;
5
6 my $numtests;
7 BEGIN {
8 $numtests = 14;
9
10 # disabled for testing now...
11 # eval "use Test::NoWarnings";
12 # if ( ! $@ ) {
13 # # increment by one
14 # $numtests++;
15 #
16 # }
17 }
18
19 use Test::More tests => $numtests;
20
21 use POE 1.267;
22 use POE::Component::Client::TCP;
23 use POE::Component::Server::TCP;
24 use POE::Component::SSLify qw/Client_SSLify Server_SSLify SSLify_Options SSLify_GetCipher SSLify_ContextCreate SSLify_GetSocket SSLify_GetSSL/;
25
26 # TODO rewrite this to use Test::POE::Server::TCP and stuff :)
27
28 my $port;
29
30 POE::Component::Server::TCP->new
31 (
32 Alias => 'myserver',
33 Address => '127.0.0.1',
34 Port => 0,
35
36 Started => sub
37 {
38 use Socket qw/sockaddr_in/;
39 $port = (sockaddr_in($_[HEAP]->{listener}->getsockname))[0];
40 },
41 ClientConnected => sub
42 {
43 ok(1, 'SERVER: accepted');
44 },
45 ClientDisconnected => sub
46 {
47 ok(1, 'SERVER: client disconnected');
48 $_[KERNEL]->post( 'myserver' => 'shutdown');
49 },
50 ClientPreConnect => sub
51 {
52 eval { SSLify_Options('mylib/example.key', 'mylib/example.crt', 'sslv3') };
53 eval { SSLify_Options('../mylib/example.key', '../mylib/example.crt', 'sslv3') } if ($@);
54 ok(!$@, "SERVER: SSLify_Options $@");
55
56 my $socket = eval { Server_SSLify( $_[ARG0], sub {
57 pass( "Got connect hook for server" );
58 } ) };
59 ok(!$@, "SERVER: Server_SSLify $@");
60 ok(1, 'SERVER: SSLify_GetCipher: '. SSLify_GetCipher($socket));
61
62 # We pray that IO::Handle is sane...
63 ok( SSLify_GetSocket( $socket )->blocking == 0, 'SERVER: SSLified socket is non-blocking?');
64
65 return ($socket);
66 },
67 ClientInput => sub
68 {
69 my ($kernel, $heap, $line) = @_[KERNEL, HEAP, ARG0];
70
71 die "Unknown line from CLIENT: $line";
72 },
73 ClientError => sub
74 {
75 # Thanks to H. Merijn Brand for spotting this FAIL in 5.12.0!
76 # The default PoCo::Server::TCP handler will throw a warning, which causes Test::NoWarnings to FAIL :(
77 my ($syscall, $errno, $error) = @_[ ARG0..ARG2 ];
78
79 # TODO are there other "errors" that is harmless?
80 $error = "Normal disconnection" unless $error;
81 my $msg = "Got SERVER $syscall error $errno: $error";
82 unless ( $syscall eq 'read' and $errno == 0 ) {
83 fail( $msg );
84 } else {
85 diag( $msg ) if $ENV{TEST_VERBOSE};
86 }
87 },
88 );
89
90 POE::Component::Client::TCP->new
91 (
92 Alias => 'myclient',
93 RemoteAddress => '127.0.0.1',
94 RemotePort => $port,
95 Connected => sub
96 {
97 ok(1, 'CLIENT: connected');
98 },
99 PreConnect => sub
100 {
101 my $ctx = eval { SSLify_ContextCreate(undef, undef, 'sslv3') };
102 ok(!$@, "CLIENT: SSLify_ContextCreate $@");
103 my $socket = eval { Client_SSLify($_[ARG0], undef, undef, $ctx, sub {
104 pass( "Got connect hook for client" );
105 $poe_kernel->post( 'myclient' => 'shutdown' );
106 }) };
107 ok(!$@, "CLIENT: Client_SSLify $@");
108 ok(1, 'CLIENT: SSLify_GetCipher: '. SSLify_GetCipher($socket));
109
110 # We pray that IO::Handle is sane...
111 ok( SSLify_GetSocket( $socket )->blocking == 0, 'CLIENT: SSLified socket is non-blocking?');
112
113 return ($socket);
114 },
115 ServerInput => sub
116 {
117 my ($kernel, $heap, $line) = @_[KERNEL, HEAP, ARG0];
118
119 $kernel->yield('shutdown');
120 },
121 ServerError => sub
122 {
123 # Thanks to H. Merijn Brand for spotting this FAIL in 5.12.0!
124 # The default PoCo::Client::TCP handler will throw a warning, which causes Test::NoWarnings to FAIL :(
125 my ($syscall, $errno, $error) = @_[ ARG0..ARG2 ];
126
127 # TODO are there other "errors" that is harmless?
128 $error = "Normal disconnection" unless $error;
129 my $msg = "Got CLIENT $syscall error $errno: $error";
130 unless ( $syscall eq 'read' and $errno == 0 ) {
131 fail( $msg );
132 } else {
133 diag( $msg ) if $ENV{TEST_VERBOSE};
134 }
135 },
136 );
137
138 $poe_kernel->run();
139
140 pass( 'shut down sanely' );
141
142 exit 0;