1#!perl 2 3use strict; 4use warnings; 5use Test::More; 6use File::Temp qw/tempfile/; 7use WWW::Curl::Easy; 8 9# list of tests 10# site-url, verifypeer(0,1), verifyhost(0,2), result(0=ok, 1=fail), result-openssl0.9.5 11my $url_list=[ 12 13 [ 'https://www.microsoft.com/', 0, 0, 0 , 0 ], 14 [ 'https://www.microsoft.com/', 0, 0, 0 , 0 ], 15 [ 'https://www.verisign.com/', 1, 2, 0 , 0 ], # verisign have had broken ssl - do this first 16 [ 'https://www.verisign.com/', 0, 0, 0 , 0 ], 17 [ 'https://www.verisign.com/', 0, 0, 0 , 0 ], 18 [ 'https://www.verisign.com/', 0, 2, 0 , 0 ], 19 [ 'https://www.thawte.com/', 0, 0, 0 , 0 ], 20 [ 'https://www.thawte.com/', 0, 2, 0 , 0 ], 21 22# libcurl < 7.9.3 crashes with more than 5 ssl hosts per handle. 23 24 [ 'https://www.rapidssl.com/', 0, 0, 0 , 0], 25 [ 'https://www.rapidssl.com/', 0, 2, 0 , 0], 26 [ 'https://www.rapidssl.com/', 1, 0, 1 , 0], 27 [ 'https://www.rapidssl.com/', 1, 2, 1 , 0], 28]; 29 30 31if (&WWW::Curl::Easy::version() !~ /ssl|nss/i) { 32 plan skip_all => 'libcurl was compiled without ssl support, skipping ssl tests'; 33} else { 34 plan tests => scalar(@{$url_list})+7; 35} 36 37# Init the curl session 38my $curl = WWW::Curl::Easy->new(); 39ok($curl, 'Curl session initialize returns something'); #1 40ok(ref($curl) eq 'WWW::Curl::Easy', 'Curl session looks like an object from the WWW::Curl::Easy module'); #2 41 42ok(! $curl->setopt(CURLOPT_NOPROGRESS, 1), "Setting CURLOPT_NOPROGRESS"); #3 43ok(! $curl->setopt(CURLOPT_FOLLOWLOCATION, 1), "Setting CURLOPT_FOLLOWLOCATION"); #4 44ok(! $curl->setopt(CURLOPT_TIMEOUT, 30), "Setting CURLOPT_TIMEOUT"); #5 45 46my $head = tempfile(); 47ok(! $curl->setopt(CURLOPT_WRITEHEADER, $head), "Setting CURLOPT_WRITEHEADER"); #6 48 49my $body = tempfile(); 50ok(! $curl->setopt(CURLOPT_FILE, $body), "Setting CURLOPT_FILE"); #7 51 52my @myheaders; 53$myheaders[0] = "User-Agent: Verifying SSL functions in WWW::Curl perl interface for libcURL"; 54$curl->setopt(CURLOPT_HTTPHEADER, \@myheaders); 55 56$curl->setopt(CURLOPT_FORBID_REUSE, 1); 57$curl->setopt(CURLOPT_FRESH_CONNECT, 1); 58#$curl->setopt(CURLOPT_SSL_CIPHER_LIST, "HIGH:MEDIUM"); 59 60$curl->setopt(CURLOPT_CAINFO,"ca-bundle.crt"); 61$curl->setopt(CURLOPT_DEBUGFUNCTION, \&silence); 62 63sub silence { return 0 } 64 65my $count = 1; 66 67my $sslversion95 = 0; 68$sslversion95++ if (&WWW::Curl::Easy::version() =~ m/SSL 0.9.5/); # 0.9.5 has buggy connect with some ssl sites 69 70my $haveca = 0; 71if (-f "ca-bundle.crt") { $haveca = 1; } 72 73for my $test_list (@$url_list) { 74 my ($url,$verifypeer,$verifyhost,$result,$result95)=@{$test_list}; 75 if ($verifypeer && !$haveca) { $result = 1 } # expect to fail if no ca-bundle file 76 if ($sslversion95) { $result=$result95 }; # change expectation 77 78 79 $curl->setopt(CURLOPT_SSL_VERIFYPEER,$verifypeer); # do verify 80 $curl->setopt(CURLOPT_SSL_VERIFYHOST,$verifyhost); # check name 81 my $retcode; 82 83 $curl->setopt(CURLOPT_URL, $url); 84 85 $retcode = $curl->perform(); 86 ok(($retcode != 0) == $result, "$url ssl test succeeds"); 87} 88 89