]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/httpd-https.t
tests: recommend running create-certs.pl with $^X
[public-inbox.git] / t / httpd-https.t
index f6b9806a52c8376c52244bfeaf467718ccecd8f4..22c62bf412034efce62cacb6a6e269ebb24be5c3 100644 (file)
@@ -14,7 +14,7 @@ my $cert = 'certs/server-cert.pem';
 my $key = 'certs/server-key.pem';
 unless (-r $key && -r $cert) {
        plan skip_all =>
-               "certs/ missing for $0, run ./create-certs.perl in certs/";
+               "certs/ missing for $0, run $^X ./create-certs.perl in certs/";
 }
 use_ok 'PublicInbox::TLS';
 use_ok 'IO::Socket::SSL';
@@ -24,14 +24,7 @@ my $tmpdir = tempdir('pi-httpd-https-XXXXXX', TMPDIR => 1, CLEANUP => 1);
 my $err = "$tmpdir/stderr.log";
 my $out = "$tmpdir/stdout.log";
 my $httpd = 'blib/script/public-inbox-httpd';
-my %opts = (
-       LocalAddr => '127.0.0.1',
-       ReuseAddr => 1,
-       Proto => 'tcp',
-       Type => SOCK_STREAM,
-       Listen => 1024,
-);
-my $https = IO::Socket::INET->new(%opts);
+my $https = tcp_server();
 my ($pid, $tail_pid);
 END {
        foreach ($pid, $tail_pid) {
@@ -39,7 +32,6 @@ END {
        }
 };
 my $https_addr = $https->sockhost . ':' . $https->sockport;
-my %opt = ( Proto => 'tcp', PeerAddr => $https_addr, Type => SOCK_STREAM );
 
 for my $args (
        [ "-lhttps://$https_addr/?key=$key,cert=$cert" ],
@@ -63,7 +55,7 @@ for my $args (
                SSL_ca_file => 'certs/test-ca.pem',
        );
        # start negotiating a slow TLS connection
-       my $slow = IO::Socket::INET->new(%opt, Blocking => 0);
+       my $slow = tcp_connect($https, Blocking => 0);
        $slow = IO::Socket::SSL->start_SSL($slow, SSL_startHandshake => 0, %o);
        my @poll = (fileno($slow));
        my $slow_done = $slow->connect_SSL;
@@ -75,7 +67,7 @@ for my $args (
        }
 
        # normal HTTPS
-       my $c = IO::Socket::INET->new(%opt);
+       my $c = tcp_connect($https);
        IO::Socket::SSL->start_SSL($c, %o);
        ok($c->print("GET /empty HTTP/1.1\r\n\r\nHost: example.com\r\n\r\n"),
                'wrote HTTP request');
@@ -84,13 +76,13 @@ for my $args (
        like($buf, qr!\AHTTP/1\.1 200!, 'read HTTP response');
 
        # HTTPS with bad hostname
-       $c = IO::Socket::INET->new(%opt);
+       $c = tcp_connect($https);
        $o{SSL_hostname} = $o{SSL_verifycn_name} = 'server.fail';
        $c = IO::Socket::SSL->start_SSL($c, %o);
        is($c, undef, 'HTTPS fails with bad hostname');
 
        $o{SSL_hostname} = $o{SSL_verifycn_name} = 'server.local';
-       $c = IO::Socket::INET->new(%opt);
+       $c = tcp_connect($https);
        IO::Socket::SSL->start_SSL($c, %o);
        ok($c, 'HTTPS succeeds again with valid hostname');