96
92
my ($ok, $ctx_store, $cert, $error) = @_;
97
unless ($ok && $ctx_store && $cert && !$error)
98
{ print("not ok #client failure\n") && exit; }
99
($cert =~ /IO::Socket::SSL Demo CA/) || print "not";
100
&ok("Client Verify-sub Check");
93
$ok && $ctx_store && $cert && !$error or do {
94
fail("client failure in verify_sub");
97
like( $cert, qr/IO::Socket::SSL Demo CA/, "Client Verify-sub Check");
105
102
$client || (print("not ok #client failure\n") && exit);
106
&ok("Client Initialization");
103
ok( $client, "Client Initialization");
108
105
$client->fileno() || print "not ";
109
&ok("Client Fileno Check");
106
ok( $client->fileno(), "Client Fileno Check");
111
108
# $client->untaint() if ($HAVE_SCALAR_UTIL); # In the future...
113
$client->dump_peer_certificate() || print "not ";
114
&ok("Client Peer Certificate Check");
116
$client->peer_certificate("issuer") || print "not ";
117
&ok("Client Peer Certificate Issuer Check");
119
$client->get_cipher() || print "not ";
120
&ok("Client Cipher Check");
110
ok( $client->dump_peer_certificate(), "Client Peer Certificate Check");
112
ok( $client->peer_certificate("issuer"), "Client Peer Certificate Issuer Check");
114
ok( $client->get_cipher(), "Client Cipher Check");
122
116
$client->syswrite('00waaaanf00', 7, 2);
126
120
$client->read($buffer,2);
127
print "not " if ($buffer ne 'ok');
128
&ok("Client Peek Check");
121
is( $buffer, "ok", "Client Peek Check");
131
124
$client->print("Test\n");
132
$client->printf("\$%.2f\n%d\n%c\n%s", 1.0444442342, 4.0, ord("y"), "Test\nBeaver\nBeaver\n");
125
$client->printf("\$%.2f\n%d\n%c\n%s",
129
"Test\nBeaver\nBeaver\n");
133
130
shutdown($client, 1);
135
132
my $buffer="\0\0aaaaaaaaaaaaaaaaaaaa";
136
133
$client->sysread($buffer, 7, 2);
137
print "not " if ($buffer ne "\0\0waaaanf");
138
&ok("Client Sysread Check");
134
is( $buffer, "\0\0waaaanf", "Client Sysread Check");
147
143
my @array = $client->getline();
148
print "not " if (@array != 1 or $array[0] ne "Test\n");
149
&ok("Client Getline Check");
144
is( $array[0], "Test\n", "Client Getline Check");
151
print "not " if ($client->getc ne "\$");
152
&ok("Client Getc Check");
146
is( $client->getc, "\$", "Client Getc Check");
154
148
@array = $client->getlines;
155
print "not " if (@array != 6);
156
&ok("Client Getlines Check 1");
158
print "not " if ($array[0] != "1.04\n");
159
&ok("Client Getlines Check 2");
161
print "not " if ($array[1] ne "4\n");
162
&ok("Client Getlines Check 3");
164
print "not " if ($array[2] ne "y\n");
165
&ok("Client Getlines Check 4");
167
print "not " if (join("", @array[3..5]) ne "Test\nBeaver\nBeaver\n");
168
&ok("Client Getlines Check 5");
170
print "not " if (defined(<$client>));
171
&ok("Client Finished Reading Check");
149
is( scalar @array, 6, "Client Getlines Check 1");
151
is( $array[0], "1.04\n", "Client Getlines Check 2");
153
is( $array[1], "4\n", "Client Getlines Check 3");
155
is( $array[2], "y\n", "Client Getlines Check 4");
157
is( join("", @array[3..5]),
158
"Test\nBeaver\nBeaver\n",
159
"Client Getlines Check 5");
161
ok( !<$client>, "Client Finished Reading Check");
173
163
$client->close(SSL_no_shutdown => 1);
175
165
my $client_2 = IO::Socket::INET->new($saddr);
176
print "not " if (!$client_2);
177
&ok("Second Client Initialization");
166
ok( $client_2, "Second Client Initialization");
179
168
$client_2 = IO::Socket::SSL->new_from_fd($client_2->fileno, '+<>',
180
169
SSL_reuse_ctx => $client);
181
print "not " if (!$client_2);
182
&ok("Client Init from Fileno Check");
170
ok( $client_2, "Client Init from Fileno Check");
183
171
$buffer = <$client_2>;
185
print "not " unless ($buffer eq "Boojums\n");
186
&ok("Client (fileno) Readline Check");
173
is( $buffer, "Boojums\n", "Client (fileno) Readline Check");
187
174
$client_2->close(SSL_ctx_free => 1);
189
176
if ($CAN_NONBLOCK) {
198
185
SSL_key_file => "certs/server-key.enc",
199
186
SSL_passwd_cb => sub { return "bluebell" },
203
print "not " if (!$client_3);
204
&ok("Client Nonblocking Check 1");
190
ok( $client_3, "Client Nonblocking Check 1");
207
193
my $client_4 = IO::Socket::SSL->new(
208
194
PeerAddr => $saddr,
209
195
SSL_reuse_ctx => $client_3,
212
print "not " if (!$client_4);
213
&ok("Client Nonblocking Check 2");
198
ok( $client_4, "Client Nonblocking Check 2");
214
199
$client_3->close(SSL_ctx_free => 1);
220
205
my $client = $server->accept;
222
$error_trapped or print "not ";
223
&ok("Server non-SSL Client Check");
207
ok( $error_trapped, "Server non-SSL Client Check");
225
209
if ($client && $client->opened) {
226
print "not ok # client stayed alive!\n";
210
fail("client stayed alive");
229
&ok("Server Kill-client Check");
213
ok( !$client, "Server Kill-client Check");
231
215
($client, my $peer) = $server->accept;
233
print "not ok # no client\n";
236
&ok("Server Client Accept Check");
238
print "not " unless defined $peer;
239
&ok("Accept returning peer address check.");
242
fileno($client) || print "not ";
243
&ok("Server Client Fileno Check");
216
ok( $client, "Server Client Accept Check");
219
ok( $peer, "Accept returning peer address check.");
221
ok( fileno($client), "Server Client Fileno Check");
248
226
$client->peek($buffer, 7, 2);
249
print "not " if ($buffer ne "\0\0waaaanf");
250
&ok("Server Peek Check");
227
is( $buffer, "\0\0waaaanf","Server Peek Check");
252
print "not " if ($client->pending() != 7);
253
&ok("Server Pending Check");
229
is( $client->pending(), 7, "Server Pending Check");
255
231
print $client "ok";
262
234
sysread($client, $buffer, 7, 2);
263
print "not " if ($buffer ne "\0\0waaaanf");
264
&ok("Server Sysread Check");
235
is( $buffer, "\0\0waaaanf", "Server Sysread Check");
267
237
my @array = scalar <$client>;
268
print "not " if ($array[0] ne "Test\n");
269
&ok("Server Getline Check");
272
print "not " if (getc($client) ne "\$");
273
&ok("Server Getc Check");
238
is( $array[0], "Test\n", "Server Getline Check");
240
is( getc($client), "\$", "Server Getc Check");
276
242
@array = <$client>;
277
print "not " if (@array != 6);
278
&ok("Server Getlines Check 1");
280
print "not " if ($array[0] != "1.04\n");
281
&ok("Server Getlines Check 2");
283
print "not " if ($array[1] ne "4\n");
284
&ok("Server Getlines Check 3");
286
print "not " if ($array[2] ne "y\n");
287
&ok("Server Getlines Check 4");
289
print "not " if (join("", @array[3..5]) ne "Test\nBeaver\nBeaver\n");
290
&ok("Server Getlines Check 5");
243
is( scalar @array, 6, "Server Getlines Check 1");
245
is( $array[0], "1.04\n", "Server Getlines Check 2");
247
is( $array[1], "4\n", "Server Getlines Check 3");
249
is( $array[2], "y\n", "Server Getlines Check 4");
251
is( join("", @array[3..5]), "Test\nBeaver\nBeaver\n", "Server Getlines Check 5");
293
253
syswrite($client, '00waaaanf00', 7, 2);
294
254
print($client "Test\n");
299
($client, $peer) = $server->accept;
300
&bail unless $client;
301
print "not " unless (inet_ntoa((unpack_sockaddr_in($peer))[1]) eq $expected_peer);
302
&ok("Peer address check");
259
($client, $peer) = $server->accept or do {
260
fail("client creation failed");
263
is( inet_ntoa((unpack_sockaddr_in($peer))[1]), $expected_peer, "Peer address check");
304
265
if ($CAN_NONBLOCK) {
305
266
$client->blocking(0);
306
267
$client->read($buffer, 20, 0);
307
print "not " if $SSL_ERROR != SSL_WANT_READ;
308
&ok("Server Nonblocking Check 1");
268
is( $SSL_ERROR, SSL_WANT_READ, "Server Nonblocking Check 1");
311
print "not " unless ($client->opened);
312
&ok("Server Client Opened Check 1");
271
ok( $client->opened, "Server Client Opened Check 1");
314
273
print $client "Boojums\n";
318
277
${*$client}{'_SSL_opened'} = 1;
319
print "not " if ($client->opened);
320
&ok("Server Client Opened Check 2");
278
ok( !$client->opened, "Server Client Opened Check 2");
321
279
${*$client}{'_SSL_opened'} = 0;
324
281
if ($CAN_NONBLOCK) {
325
282
$client = $server->accept;
326
print "not " if (!$client->opened);
327
&ok("Server Nonblocking Check 2");
283
ok( $client->opened, "Server Nonblocking Check 2");
330
286
$server->blocking(0);