1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
|
#!perl
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl t/core.t'
use strict;
use warnings;
use Net::SSLeay;
use Socket;
use IO::Socket::SSL;
do './testlib.pl' || do './t/testlib.pl' || die "no testlib";
$|=1;
my $numtests = 35;
print "1..$numtests\n";
my @servers = map {
IO::Socket::SSL->new(
LocalAddr => '127.0.0.1',
LocalPort => 0,
Listen => 2,
Timeout => 30,
ReuseAddr => 1,
SSL_key_file => "certs/server-key.enc",
SSL_passwd_cb => sub { return "bluebell" },
SSL_verify_mode => SSL_VERIFY_NONE,
SSL_ca_file => "certs/test-ca.pem",
SSL_cert_file => "certs/server-cert.pem",
)
} (1..3);
if ( grep { !$_ } @servers > 0 ) {
print "not ok # Server init\n";
exit;
}
&ok("Server initialization");
my @saddr = map { $_->sockhost.':'.$_->sockport } @servers;
unless (fork) {
@servers = ();
my $ctx = IO::Socket::SSL::SSL_Context->new(
SSL_passwd_cb => sub { return "opossum" },
SSL_verify_mode => SSL_VERIFY_PEER,
SSL_ca_file => "certs/test-ca.pem",
SSL_ca_path => '',
SSL_version => 'TLSv1',
SSL_cipher_list => 'HIGH',
SSL_session_cache_size => 4,
);
if (! defined $ctx->{'session_cache'}) {
print "not ok \# Context init\n";
exit;
}
&ok("Context init");
# Bogus session test
unless ($ctx->session_cache("bogus", "bogus", 0)) {
print "not ";
}
&ok("Superficial Cache Addition Test");
unless ($ctx->session_cache("bogus1", "bogus1", 0)) {
print "not ";
}
&ok("Superficial Cache Addition Test 2");
my $cache = $ctx->{'session_cache'};
if (keys(%$cache) != 4) {
print "not ";
}
&ok("Cache Keys Check 1");
unless ($cache->{'bogus1:bogus1'} and $cache->{'bogus:bogus'}) {
print "not ";
}
&ok("Cache Keys Check 2");
my ($bogus, $bogus1) = ($cache->{'bogus:bogus'}, $cache->{'bogus1:bogus1'});
unless ($cache->{'_head'} eq $bogus1) {
print "not ";
}
&ok("Cache Head Check");
unless ($bogus1->{prev} eq $bogus and
$bogus1->{next} eq $bogus and
$bogus->{prev} eq $bogus1 and
$bogus->{next} eq $bogus1) {
print "not ";
}
&ok("Cache Link Check");
IO::Socket::SSL::set_default_context($ctx);
my $sock3 = IO::Socket::INET->new($saddr[2]);
my @clients = (
IO::Socket::SSL->new($saddr[0]),
IO::Socket::SSL->new($saddr[1]),
IO::Socket::SSL->start_SSL( $sock3 ),
);
if ( grep { !$_ } @clients >0 ) {
print "not ok \# Client init $SSL_ERROR\n";
exit;
}
&ok("Client init");
# Make sure that first 'bogus' entry has been removed
if (keys(%$cache) != 6) {
warn Dumper($cache); use Data::Dumper;
print "not ";
}
&ok("Cache Keys Check 3");
if ($cache->{'bogus:bogus'}) {
print "not ";
}
&ok("Cache Removal Test");
if ($cache->{'_head'}->{prev} ne $bogus1) {
print "not ";
}
&ok("Cache Tail Check");
if ($cache->{'_head'} ne $cache->{$saddr[2]}) {
print "not ";
}
&ok("Cache Insertion Test");
for (0..2) {
if (Net::SSLeay::get_session($clients[$_]->_get_ssl_object) ne
$cache->{$saddr[$_]}->{session}) {
print "not ";
}
&ok("Cache Entry Test $_");
close $clients[$_];
}
@clients = map {
IO::Socket::SSL->new($_)
} @saddr;
if (keys(%$cache) != 6) {
print "not ";
}
&ok("Cache Keys Check 4");
if (!$cache->{'bogus1:bogus1'}) {
print "not ";
}
&ok("Cache Keys Check 5");
for (0..2) {
if (Net::SSLeay::get_session($clients[$_]->_get_ssl_object) ne
$cache->{$saddr[$_]}->{session}) {
print "not ";
}
&ok("Second Cache Entry Test $_");
unless ($clients[$_]->print("Test $_\n")) {
print "not ";
}
&ok("Write Test $_");
unless ($clients[$_]->readline eq "Ok $_\n") {
print "not ";
}
&ok("Read Test $_");
close $clients[$_];
}
exit(0);
}
my @clients = map { scalar $_->accept } @servers;
if ( grep { !$_ } @clients > 0 ) {
print "not ok \# Client init\n";
exit;
}
&ok("Client init");
close($_) for @clients;
@clients = map { scalar $_->accept } @servers;
if ( grep { !$_ } @clients > 0 ) {
print $SSL_ERROR;
print "not ok \# Client init 2\n";
exit;
}
&ok("Client init 2");
for (0..2) {
unless ($clients[$_]->readline eq "Test $_\n") {
print "not ";
}
&ok("Server Read $_");
unless ($clients[$_]->print("Ok $_\n")) {
print "not ";
}
&ok("Server Write $_");
close $clients[$_];
close $servers[$_];
}
wait;
sub ok {
print "ok #$_[0]\n";
}
sub bail {
print "Bail Out! $IO::Socket::SSL::ERROR";
}
|