From 860169adcd29341142b7c4a369c09b4ac492bd1e Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 7 Feb 2021 23:05:13 -1000 Subject: tests: favor IPv6 IPv4 gets plenty of real-world coverage, and apparently there's Debian buildd hosts which lack IPv4(*). So ensure everything can work on IPv6 and not cause problems for odd setups. (*) https://bugs.debian.org/979432 --- t/extsearch.t | 2 +- t/httpd-corner.psgi | 2 +- t/httpd-corner.t | 12 +++++------- t/httpd-https.t | 2 +- t/httpd-unix.t | 7 +++---- t/httpd.t | 8 +++----- t/imapd-tls.t | 4 ++-- t/imapd.t | 8 ++------ t/lei-mirror.t | 2 +- t/nntpd-tls.t | 4 ++-- t/nntpd.t | 11 ++++------- t/psgi_attach.t | 2 +- t/psgi_v2.t | 2 +- t/solver_git.t | 2 +- t/v2mirror.t | 3 +-- t/v2writable.t | 3 +-- t/www_altid.t | 2 +- t/www_listing.t | 3 +-- 18 files changed, 32 insertions(+), 47 deletions(-) (limited to 't') diff --git a/t/extsearch.t b/t/extsearch.t index 26c3d4ae..d199fc7b 100644 --- a/t/extsearch.t +++ b/t/extsearch.t @@ -14,7 +14,7 @@ use_ok 'PublicInbox::ExtSearch'; use_ok 'PublicInbox::ExtSearchIdx'; use_ok 'PublicInbox::OverIdx'; my $sock = tcp_server(); -my $host_port = $sock->sockhost . ':' . $sock->sockport; +my $host_port = tcp_host_port($sock); my ($home, $for_destroy) = tmpdir(); local $ENV{HOME} = $home; mkdir "$home/.public-inbox" or BAIL_OUT $!; diff --git a/t/httpd-corner.psgi b/t/httpd-corner.psgi index 5436a74d..5fab2ba4 100644 --- a/t/httpd-corner.psgi +++ b/t/httpd-corner.psgi @@ -48,7 +48,7 @@ my $app = sub { } } elsif ($path eq '/host-port') { $code = 200; - push @$body, "$env->{REMOTE_ADDR}:$env->{REMOTE_PORT}"; + push @$body, "$env->{REMOTE_ADDR} $env->{REMOTE_PORT}"; } elsif ($path eq '/callback') { return sub { my ($res) = @_; diff --git a/t/httpd-corner.t b/t/httpd-corner.t index c3f80530..794d8aeb 100644 --- a/t/httpd-corner.t +++ b/t/httpd-corner.t @@ -11,7 +11,6 @@ use PublicInbox::TestCommon; require_mods(qw(Plack::Util Plack::Builder HTTP::Date HTTP::Status)); use Digest::SHA qw(sha1_hex); use IO::Handle (); -use IO::Socket; use IO::Socket::UNIX; use Fcntl qw(:seek); use Socket qw(IPPROTO_TCP TCP_NODELAY SOL_SOCKET); @@ -50,14 +49,13 @@ sub unix_server ($) { Listen => 1024, Type => Socket::SOCK_STREAM(), Local => $_[0], - ); + ) or BAIL_OUT "bind + listen $_[0]: $!"; $s->blocking(0); $s; } my $upath = "$tmpdir/s"; my $unix = unix_server($upath); -ok($unix, 'UNIX socket created'); my $td; my $spawn_httpd = sub { my (@args) = @_; @@ -219,7 +217,7 @@ sub check_400 { ok($u, 'unix socket connected'); $u->write("GET /host-port HTTP/1.0\r\n\r\n"); $u->read(my $buf, 4096); - like($buf, qr!\r\n\r\n127\.0\.0\.1:0\z!, + like($buf, qr!\r\n\r\n127\.0\.0\.1 0\z!, 'set REMOTE_ADDR and REMOTE_PORT for Unix socket'); } @@ -236,8 +234,8 @@ sub conn_for { $conn->write("GET /host-port HTTP/1.0\r\n\r\n"); $conn->read(my $buf, 4096); my ($head, $body) = split(/\r\n\r\n/, $buf); - my ($addr, $port) = split(/:/, $body); - is($addr, $conn->sockhost, 'host matches addr'); + my ($addr, $port) = split(/ /, $body); + is($addr, (tcp_host_port($conn))[0], 'host matches addr'); is($port, $conn->sockport, 'port matches'); } @@ -306,7 +304,7 @@ my $check_self = sub { SKIP: { my $curl = which('curl') or skip('curl(1) missing', 4); - my $base = 'http://' . $sock->sockhost . ':' . $sock->sockport; + my $base = 'http://'.tcp_host_port($sock); my $url = "$base/sha1"; my ($r, $w); pipe($r, $w) or die "pipe: $!"; diff --git a/t/httpd-https.t b/t/httpd-https.t index a2166ce6..b37492eb 100644 --- a/t/httpd-https.t +++ b/t/httpd-https.t @@ -21,7 +21,7 @@ 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" ], diff --git a/t/httpd-unix.t b/t/httpd-unix.t index 2d3cecc1..fe4a2161 100644 --- a/t/httpd-unix.t +++ b/t/httpd-unix.t @@ -42,13 +42,12 @@ for (1..1000) { ok(-S $unix, 'UNIX socket was bound by -httpd'); sub check_sock ($) { my ($unix) = @_; - my $sock = IO::Socket::UNIX->new(Peer => $unix, Type => SOCK_STREAM); - warn "E: $! connecting to $unix\n" unless defined $sock; - ok($sock, 'client UNIX socket connected'); + my $sock = IO::Socket::UNIX->new(Peer => $unix, Type => SOCK_STREAM) + // BAIL_OUT "E: $! connecting to $unix"; ok($sock->write("GET /host-port HTTP/1.0\r\n\r\n"), 'wrote req to server'); ok($sock->read(my $buf, 4096), 'read response'); - like($buf, qr!\r\n\r\n127\.0\.0\.1:0\z!, + like($buf, qr!\r\n\r\n127\.0\.0\.1 0\z!, 'set REMOTE_ADDR and REMOTE_PORT for Unix socket'); } diff --git a/t/httpd.t b/t/httpd.t index 2fc28355..af9fbfeb 100644 --- a/t/httpd.t +++ b/t/httpd.t @@ -44,11 +44,9 @@ EOF $im->add($mime); $im->done($mime); } - ok($sock, 'sock created'); $cmd = [ '-httpd', '-W0', "--stdout=$out", "--stderr=$err" ]; $td = start_script($cmd, undef, { 3 => $sock }); - my $host = $sock->sockhost; - my $port = $sock->sockport; + my $http_pfx = 'http://'.tcp_host_port($sock); { my $bad = tcp_connect($sock); print $bad "GETT / HTTP/1.0\r\n\r\n" or die; @@ -65,7 +63,7 @@ EOF } is(xsys(qw(git clone -q --mirror), - "http://$host:$port/$group", "$tmpdir/clone.git"), + "$http_pfx/$group", "$tmpdir/clone.git"), 0, 'smart clone successful'); # ensure dumb cloning works, too: @@ -73,7 +71,7 @@ EOF qw(config http.uploadpack false)), 0, 'disable http.uploadpack'); is(xsys(qw(git clone -q --mirror), - "http://$host:$port/$group", "$tmpdir/dumb.git"), + "$http_pfx/$group", "$tmpdir/dumb.git"), 0, 'clone successful'); ok($td->kill, 'killed httpd'); diff --git a/t/imapd-tls.t b/t/imapd-tls.t index e40ae1e8..ab90ddec 100644 --- a/t/imapd-tls.t +++ b/t/imapd-tls.t @@ -70,8 +70,8 @@ EOF } } -my $imaps_addr = $imaps->sockhost . ':' . $imaps->sockport; -my $starttls_addr = $starttls->sockhost . ':' . $starttls->sockport; +my $imaps_addr = tcp_host_port($imaps); +my $starttls_addr = tcp_host_port($starttls); my $env = { PI_CONFIG => $pi_config }; my $td; diff --git a/t/imapd.t b/t/imapd.t index 1df9d26e..0583dfdd 100644 --- a/t/imapd.t +++ b/t/imapd.t @@ -60,11 +60,8 @@ my $err = "$tmpdir/stderr.log"; my $out = "$tmpdir/stdout.log"; my $cmd = [ '-imapd', '-W0', "--stdout=$out", "--stderr=$err" ]; my $td = start_script($cmd, undef, { 3 => $sock }) or BAIL_OUT("-imapd: $?"); -my %mic_opt = ( - Server => $sock->sockhost, - Port => $sock->sockport, - Uid => 1, -); +my ($ihost, $iport) = tcp_host_port($sock); +my %mic_opt = ( Server => $ihost, Port => $iport, Uid => 1 ); my $mic = $imap_client->new(%mic_opt); my $pre_login_capa = $mic->capability; is(grep(/\AAUTH=ANONYMOUS\z/, @$pre_login_capa), 1, @@ -456,7 +453,6 @@ SKIP: { my $url = "http://example.com/i1"; my $inboxdir = "$tmpdir/watchimap"; my $cmd = ['-init', '-V2', '-Lbasic', $name, $inboxdir, $url, $addr]; - my ($ihost, $iport) = ($sock->sockhost, $sock->sockport); my $imapurl = "imap://$ihost:$iport/inbox.i1.0"; run_script($cmd) or BAIL_OUT("init $name"); xsys(qw(git config), "--file=$home/.public-inbox/config", diff --git a/t/lei-mirror.t b/t/lei-mirror.t index 667284fd..e3707979 100644 --- a/t/lei-mirror.t +++ b/t/lei-mirror.t @@ -6,7 +6,7 @@ require_git 2.6; require_mods(qw(DBD::SQLite Search::Xapian)); my $sock = tcp_server(); my ($tmpdir, $for_destroy) = tmpdir(); -my $http = 'http://'.$sock->sockhost.':'.$sock->sockport.'/'; +my $http = 'http://'.tcp_host_port($sock); my ($ro_home, $cfg_path) = setup_public_inboxes; my $cmd = [ qw(-httpd -W0), "--stdout=$tmpdir/out", "--stderr=$tmpdir/err" ]; my $td = start_script($cmd, { PI_CONFIG => $cfg_path }, { 3 => $sock }); diff --git a/t/nntpd-tls.t b/t/nntpd-tls.t index 1194be6f..8dab4ca8 100644 --- a/t/nntpd-tls.t +++ b/t/nntpd-tls.t @@ -70,8 +70,8 @@ EOF } } -my $nntps_addr = $nntps->sockhost . ':' . $nntps->sockport; -my $starttls_addr = $starttls->sockhost . ':' . $starttls->sockport; +my $nntps_addr = tcp_host_port($nntps); +my $starttls_addr = tcp_host_port($starttls); my $env = { PI_CONFIG => $pi_config }; my $td; diff --git a/t/nntpd.t b/t/nntpd.t index 63287d43..6c100138 100644 --- a/t/nntpd.t +++ b/t/nntpd.t @@ -8,7 +8,6 @@ use PublicInbox::Spawn qw(which); require_mods(qw(DBD::SQLite)); require PublicInbox::InboxWritable; use PublicInbox::Eml; -use IO::Socket; use Socket qw(IPPROTO_TCP TCP_NODELAY); use Net::NNTP; use Sys::Hostname; @@ -34,6 +33,7 @@ my $addr = $group . '@example.com'; my %opts; my $sock = tcp_server(); +my $host_port = tcp_host_port($sock); my $td; my $len; @@ -96,10 +96,8 @@ EOF } } - ok($sock, 'sock created'); my $cmd = [ '-nntpd', '-W0', "--stdout=$out", "--stderr=$err" ]; $td = start_script($cmd, undef, { 3 => $sock }); - my $host_port = $sock->sockhost . ':' . $sock->sockport; my $n = Net::NNTP->new($host_port); my $list = $n->list; ok(delete $list->{'x.y.z'}, 'deleted x.y.z group'); @@ -376,7 +374,7 @@ Date: Fri, 02 Oct 1993 00:00:00 +0000 my @of = xqx([$lsof, '-p', $td->{pid}], undef, $noerr); is(scalar(grep(/\(deleted\)/, @of)), 0, 'no deleted files'); }; - SKIP: { test_watch($tmpdir, $sock, $group) }; + SKIP: { test_watch($tmpdir, $host_port, $group) }; { setsockopt($s, IPPROTO_TCP, TCP_NODELAY, 1); syswrite($s, 'HDR List-id 1-'); @@ -417,7 +415,7 @@ sub read_til_dot { } sub test_watch { - my ($tmpdir, $sock, $group) = @_; + my ($tmpdir, $host_port, $group) = @_; use_ok 'PublicInbox::Watch'; use_ok 'PublicInbox::InboxIdle'; use_ok 'PublicInbox::Config'; @@ -432,8 +430,7 @@ sub test_watch { my $url = "http://example.com/i1"; my $inboxdir = "$tmpdir/watchnntp"; my $cmd = ['-init', '-V1', '-Lbasic', $name, $inboxdir, $url, $addr]; - my ($ihost, $iport) = ($sock->sockhost, $sock->sockport); - my $nntpurl = "nntp://$ihost:$iport/$group"; + my $nntpurl = "nntp://$host_port/$group"; run_script($cmd) or BAIL_OUT("init $name"); xsys(qw(git config), "--file=$home/.public-inbox/config", "publicinbox.$name.watch", diff --git a/t/psgi_attach.t b/t/psgi_attach.t index 65d704bf..f53b7510 100644 --- a/t/psgi_attach.t +++ b/t/psgi_attach.t @@ -116,7 +116,7 @@ SKIP: { my ($out, $err) = map { "$inboxdir/std$_.log" } qw(out err); my $cmd = [ qw(-httpd -W0), "--stdout=$out", "--stderr=$err" ]; my $td = start_script($cmd, $env, { 3 => $sock }); - my ($h, $p) = ($sock->sockhost, $sock->sockport); + my ($h, $p) = tcp_host_port($sock); local $ENV{PLACK_TEST_EXTERNALSERVER_URI} = "http://$h:$p"; Plack::Test::ExternalServer::test_psgi(client => $client); } diff --git a/t/psgi_v2.t b/t/psgi_v2.t index 7ab60adc..81355f04 100644 --- a/t/psgi_v2.t +++ b/t/psgi_v2.t @@ -35,7 +35,7 @@ my $run_httpd = sub { my ($out, $err) = map { "$inboxdir/std$_.log" } qw(out err); my $cmd = [ qw(-httpd -W0), "--stdout=$out", "--stderr=$err" ]; my $td = start_script($cmd, $env, { 3 => $sock }); - my ($h, $p) = ($sock->sockhost, $sock->sockport); + my ($h, $p) = tcp_host_port($sock); local $ENV{PLACK_TEST_EXTERNALSERVER_URI} = "http://$h:$p"; Plack::Test::ExternalServer::test_psgi(client => $client); $td->join('TERM'); diff --git a/t/solver_git.t b/t/solver_git.t index d03a6f38..3ae7259a 100644 --- a/t/solver_git.t +++ b/t/solver_git.t @@ -196,7 +196,7 @@ EOF my ($out, $err) = map { "$inboxdir/std$_.log" } qw(out err); my $cmd = [ qw(-httpd -W0), "--stdout=$out", "--stderr=$err" ]; my $td = start_script($cmd, $env, { 3 => $sock }); - my ($h, $p) = ($sock->sockhost, $sock->sockport); + my ($h, $p) = tcp_host_port($sock); local $ENV{PLACK_TEST_EXTERNALSERVER_URI} = "http://$h:$p"; Plack::Test::ExternalServer::test_psgi(client => $client); } diff --git a/t/v2mirror.t b/t/v2mirror.t index ebad2566..12e3fcd0 100644 --- a/t/v2mirror.t +++ b/t/v2mirror.t @@ -64,10 +64,9 @@ $v2w->done; $ibx->cleanup; my $sock = tcp_server(); -ok($sock, 'sock created'); my $cmd = [ '-httpd', '-W0', "--stdout=$tmpdir/out", "--stderr=$tmpdir/err" ]; my $td = start_script($cmd, undef, { 3 => $sock }); -my ($host, $port) = ($sock->sockhost, $sock->sockport); +my ($host, $port) = tcp_host_port($sock); $sock = undef; my @cmd; diff --git a/t/v2writable.t b/t/v2writable.t index f5c8313a..f0fa8a79 100644 --- a/t/v2writable.t +++ b/t/v2writable.t @@ -164,12 +164,11 @@ EOF ; close $fh or die "close: $!\n"; my $sock = tcp_server(); - ok($sock, 'sock created'); my $len; my $cmd = [ '-nntpd', '-W0', "--stdout=$out", "--stderr=$err" ]; my $env = { PI_CONFIG => $pi_config }; my $td = start_script($cmd, $env, { 3 => $sock }); - my $host_port = $sock->sockhost . ':' . $sock->sockport; + my $host_port = tcp_host_port($sock); my $n = Net::NNTP->new($host_port); $n->group($group); my $x = $n->xover('1-'); diff --git a/t/www_altid.t b/t/www_altid.t index 14eda030..784acc8b 100644 --- a/t/www_altid.t +++ b/t/www_altid.t @@ -76,7 +76,7 @@ SKIP: { my ($out, $err) = map { "$inboxdir/std$_.log" } qw(out err); my $cmd = [ qw(-httpd -W0), "--stdout=$out", "--stderr=$err" ]; my $td = start_script($cmd, $env, { 3 => $sock }); - my ($h, $p) = ($sock->sockhost, $sock->sockport); + my ($h, $p) = tcp_host_port($sock); local $ENV{PLACK_TEST_EXTERNALSERVER_URI} = "http://$h:$p"; Plack::Test::ExternalServer::test_psgi(client => $client); } diff --git a/t/www_listing.t b/t/www_listing.t index 1bcbaefb..63ef2eac 100644 --- a/t/www_listing.t +++ b/t/www_listing.t @@ -79,8 +79,7 @@ SKIP: { my $cfgfile = "$tmpdir/config"; my $v2 = "$tmpdir/v2"; my $sock = tcp_server(); - ok($sock, 'sock created'); - my ($host, $port) = ($sock->sockhost, $sock->sockport); + my ($host, $port) = tcp_host_port($sock); my @clone = qw(git clone -q -s --bare); is(xsys(@clone, $bare->{git_dir}, $alt), 0, 'clone shared repo'); -- cgit v1.2.3-24-ge0c7