#!/usr/bin/perl
my
$port
;
POE::Component::Server::TCP->new
(
Alias
=>
'myserver'
,
Address
=>
'127.0.0.1'
,
Port
=> 0,
Started
=>
sub
{
$port
= (sockaddr_in(
$_
[HEAP]->{listener}->
getsockname
))[0];
},
ClientConnected
=>
sub
{
ok(1,
'SERVER: accepted'
);
},
ClientDisconnected
=>
sub
{
ok(1,
'SERVER: client disconnected'
);
$_
[KERNEL]->post(
'myserver'
=>
'shutdown'
);
},
ClientPreConnect
=>
sub
{
my
$args
= {
SSL_cert_file
=>
'mylib/ircd.crt'
,
SSL_key_file
=>
'mylib/ircd.key'
,
};
my
$socket
=
eval
{ Server_TLSify(
$_
[ARG0],
$args
,
sub
{
my
(
$socket
,
$status
,
$errval
) =
@_
;
pass(
"SERVER: Got callback hook"
);
is(
$status
, 1,
"SERVER: Status received from callback is OK"
);
my
$cipher
= TLSify_GetCipher(
$socket
);
} ) };
ok(!$@,
"SERVER: Server_TLSify $@"
);
return
(
$socket
);
},
ClientInput
=>
sub
{
my
(
$kernel
,
$heap
,
$line
) =
@_
[KERNEL, HEAP, ARG0];
die
"Should have never got any input from the client!"
;
},
ClientError
=>
sub
{
my
(
$syscall
,
$errno
,
$error
) =
@_
[ ARG0..ARG2 ];
$error
=
"Normal disconnection"
unless
$error
;
my
$msg
=
"Got SERVER $syscall error $errno: $error"
;
unless
(
$syscall
eq
'read'
and (
$errno
== 0 or
$errno
== 54 ) ) {
fail(
$msg
);
}
else
{
diag(
$msg
)
if
$ENV
{TEST_VERBOSE};
}
},
);
POE::Component::Client::TCP->new
(
Alias
=>
'myclient'
,
RemoteAddress
=>
'127.0.0.1'
,
RemotePort
=>
$port
,
Connected
=>
sub
{
ok(1,
'CLIENT: connected'
);
},
PreConnect
=>
sub
{
my
$args
= {
SSL_verify_mode
=> IO::Socket::SSL::SSL_VERIFY_NONE() };
my
$socket
=
eval
{ Client_TLSify(
$_
[ARG0],
$args
,
sub
{
my
(
$socket
,
$status
,
$errval
) =
@_
;
pass(
"CLIENT: Got callback hook"
);
is(
$status
, 1,
"CLIENT: Status received from callback is OK"
);
my
$cipher
= TLSify_GetCipher(
$socket
);
ok(
$cipher
ne
'(NONE)'
,
"CLIENT: TLSify_GetCipher: $cipher"
);
$poe_kernel
->post(
'myclient'
=>
'shutdown'
);
}) };
ok(!$@,
"CLIENT: Client_TLSify $@"
);
return
(
$socket
);
},
ServerInput
=>
sub
{
my
(
$kernel
,
$heap
,
$line
) =
@_
[KERNEL, HEAP, ARG0];
die
"Should have never got any input from the server!"
;
},
ServerError
=>
sub
{
my
(
$syscall
,
$errno
,
$error
) =
@_
[ ARG0..ARG2 ];
$error
=
"Normal disconnection"
unless
$error
;
my
$msg
=
"Got CLIENT $syscall error $errno: $error"
;
unless
(
$syscall
eq
'read'
and (
$errno
== 0 or
$errno
== 54 ) ) {
fail(
$msg
);
}
else
{
diag(
$msg
)
if
$ENV
{TEST_VERBOSE};
}
},
);
$poe_kernel
->run();
done_testing;