]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/httpd-https.t
www: drop --subject from "git send-email" instructions
[public-inbox.git] / t / httpd-https.t
index 1d2e4d5c25e0aa51da150d5985808b9277865c1c..d42d7c509949ce7137770bb9a8ed488650bac4ef 100644 (file)
@@ -1,14 +1,12 @@
-# Copyright (C) 2019 all contributors <meta@public-inbox.org>
+# Copyright (C) 2019-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use warnings;
 use Test::More;
 use Socket qw(SOCK_STREAM IPPROTO_TCP SOL_SOCKET);
+use PublicInbox::TestCommon;
 # IO::Poll is part of the standard library, but distros may split them off...
-foreach my $mod (qw(IO::Socket::SSL IO::Poll)) {
-       eval "require $mod";
-       plan skip_all => "$mod missing for $0" if $@;
-}
+require_mods(qw(IO::Socket::SSL IO::Poll Plack::Util));
 my $cert = 'certs/server-cert.pem';
 my $key = 'certs/server-key.pem';
 unless (-r $key && -r $cert) {
@@ -17,14 +15,13 @@ unless (-r $key && -r $cert) {
 }
 use_ok 'PublicInbox::TLS';
 use_ok 'IO::Socket::SSL';
-use PublicInbox::TestCommon;
 my $psgi = "./t/httpd-corner.psgi";
 my ($tmpdir, $for_destroy) = tmpdir();
 my $err = "$tmpdir/stderr.log";
 my $out = "$tmpdir/stdout.log";
 my $https = tcp_server();
 my $td;
-my $https_addr = $https->sockhost . ':' . $https->sockport;
+my $https_addr = tcp_host_port($https);
 
 for my $args (
        [ "-lhttps://$https_addr/?key=$key,cert=$cert" ],
@@ -56,11 +53,12 @@ for my $args (
        # normal HTTPS
        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');
+       $c->print("GET /url_scheme HTTP/1.1\r\n\r\nHost: example.com\r\n\r\n")
+               or xbail "failed to write HTTP request: $!";
        my $buf = '';
-       sysread($c, $buf, 2007, length($buf)) until $buf =~ /\r\n\r\n/;
+       sysread($c, $buf, 2007, length($buf)) until $buf =~ /\r\n\r\nhttps?/;
        like($buf, qr!\AHTTP/1\.1 200!, 'read HTTP response');
+       like($buf, qr!\r\nhttps\z!, "psgi.url_scheme is 'https'");
 
        # HTTPS with bad hostname
        $c = tcp_connect($https);
@@ -90,7 +88,7 @@ for my $args (
 
        SKIP: {
                skip 'TCP_DEFER_ACCEPT is Linux-only', 2 if $^O ne 'linux';
-               my $var = Socket::TCP_DEFER_ACCEPT();
+               my $var = eval { Socket::TCP_DEFER_ACCEPT() } // 9;
                defined(my $x = getsockopt($https, IPPROTO_TCP, $var)) or die;
                ok(unpack('i', $x) > 0, 'TCP_DEFER_ACCEPT set on https');
        };
@@ -100,8 +98,10 @@ for my $args (
                        skip 'accf_data not loaded? kldload accf_data', 2;
                }
                require PublicInbox::Daemon;
-               my $var = PublicInbox::Daemon::SO_ACCEPTFILTER();
-               my $x = getsockopt($https, SOL_SOCKET, $var);
+               ok(defined($PublicInbox::Daemon::SO_ACCEPTFILTER),
+                       'SO_ACCEPTFILTER defined');
+               my $x = getsockopt($https, SOL_SOCKET,
+                               $PublicInbox::Daemon::SO_ACCEPTFILTER);
                like($x, qr/\Adataready\0+\z/, 'got dataready accf for https');
        };