Debian lenny version packages
[pkg-perl] / deb-src / libnet-ssleay-perl / libnet-ssleay-perl-1.35 / t / handle / external / 50_external.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use Test::More;
6 use Symbol qw(gensym);
7 use Net::SSLeay::Handle;
8
9 my @sites = qw(
10         www.cdw.com
11         banking.wellsfargo.com
12         perldition.org
13         alioth.debian.org
14 );
15 @sites = split(/:/, $ENV{SSLEAY_SITES}) if exists $ENV{SSLEAY_SITES};
16 if (@sites) {
17     plan tests => scalar @sites * 6;
18 }
19 else {
20     plan skip_all => 'No external hosts specified for SSL testing';
21 }
22
23
24 for my $site (@sites) {
25     SKIP: {
26         my $ssl = gensym();
27         eval {
28             tie(*$ssl, 'Net::SSLeay::Handle', $site, 443);
29         };
30
31         skip('could not connect', 2) if $@;
32         pass('connection');
33
34         print $ssl "GET / HTTP/1.0\r\n\r\n";
35         my $resp = do { local $/ = undef; <$ssl> };
36
37         like( $resp, qr/^HTTP\/1/, 'response' );
38     }
39 }
40
41 {
42     my @sock;
43     for (my $i = 0; $i < scalar @sites; $i++) {
44         SKIP: {
45             my $ssl = gensym();
46             eval {
47                 tie(*$ssl, 'Net::SSLeay::Handle', $sites[$i], 443);
48             };
49
50             skip('could not connect', 2) if $@;
51             pass('connection');
52
53             $sock[$i] = $ssl;
54             ok( $ssl, 'got handle' );
55         }
56     }
57
58     for my $sock (@sock) {
59         SKIP : {
60             skip('not connected', 2) unless defined $sock;
61             pass('connected');
62
63             print $sock "GET / HTTP/1.0\r\n\r\n";
64
65             my $resp = do { local $/ = undef; <$sock> };
66             like( $resp, qr/^HTTP\/1/, 'response' );
67         }
68     }
69
70     close($_) for @sock;
71 }