| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use Test::More; |
| 6 |
|
| 7 |
my @uris = qw( |
| 8 |
www.google.com |
| 9 |
www.microsoft.com |
| 10 |
www.kernel.org |
| 11 |
); |
| 12 |
@uris = split(/:/, $ENV{SSLEAY_URIS}) if exists $ENV{SSLEAY_URIS}; |
| 13 |
if (@uris) { |
| 14 |
plan tests => scalar @uris * 2; |
| 15 |
} |
| 16 |
else { |
| 17 |
plan skip_all => 'No external hosts specified for SSL testing'; |
| 18 |
} |
| 19 |
|
| 20 |
use File::Spec; |
| 21 |
use Symbol qw(gensym); |
| 22 |
use Net::SSLeay::Handle; |
| 23 |
|
| 24 |
# On some platforms, such as Solaris, the act of resolving the host name |
| 25 |
# opens (and leaves open) a connection to the DNS client, which breaks |
| 26 |
# the fd counting algorithm below. Make sure the DNS is operating before |
| 27 |
# we count the FDs for the first time. |
| 28 |
for my $uri (@uris) { |
| 29 |
my $dummy = gethostbyname($uri); |
| 30 |
} |
| 31 |
|
| 32 |
my $fdcount_start = count_fds(); |
| 33 |
|
| 34 |
for my $uri (@uris) { |
| 35 |
{ |
| 36 |
my $ssl = gensym(); |
| 37 |
tie(*$ssl, "Net::SSLeay::Handle", $uri, 443); |
| 38 |
print $ssl "GET / HTTP/1.0\r\n\r\n"; |
| 39 |
|
| 40 |
my $response = do { local $/ = undef; <$ssl> }; |
| 41 |
like( $response, qr/^HTTP\/1/s, 'correct response' ); |
| 42 |
} |
| 43 |
|
| 44 |
my $fdcount_end = count_fds(); |
| 45 |
is ($fdcount_end, $fdcount_start, 'handle gets destroyed when it goes out of scope'); |
| 46 |
} |
| 47 |
|
| 48 |
sub count_fds { |
| 49 |
my $fdpath = File::Spec->devnull(); |
| 50 |
my $fh = gensym(); |
| 51 |
open($fh, $fdpath) or die; |
| 52 |
my $count = fileno($fh); |
| 53 |
close($fh); |
| 54 |
return $count; |
| 55 |
} |