-# Copyright (C) 2019 all contributors <meta@public-inbox.org>
+# Copyright (C) 2019-2020 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 File::Temp qw(tempdir);
use Socket qw(SOCK_STREAM IPPROTO_TCP SOL_SOCKET);
+use PublicInbox::TestCommon;
# IO::Poll and Net::NNTP are part of the standard library, but
# distros may split them off...
-foreach my $mod (qw(DBD::SQLite IO::Socket::SSL Net::NNTP IO::Poll)) {
- eval "require $mod";
- plan skip_all => "$mod missing for $0" if $@;
-}
+require_mods(qw(DBD::SQLite IO::Socket::SSL Net::NNTP IO::Poll));
Net::NNTP->can('starttls') or
plan skip_all => 'Net::NNTP does not support TLS';
-IO::Socket::SSL->VERSION(2.007) or
- plan skip_all => 'IO::Socket::SSL <2.007 not supported by Net::NNTP';
my $cert = 'certs/server-cert.pem';
my $key = 'certs/server-key.pem';
use_ok 'PublicInbox::TLS';
use_ok 'IO::Socket::SSL';
-require './t/common.perl';
require PublicInbox::InboxWritable;
-require PublicInbox::MIME;
+require PublicInbox::Eml;
require PublicInbox::SearchIdx;
-my $need_zlib;
+our $need_zlib;
eval { require Compress::Raw::Zlib } or
$need_zlib = 'Compress::Raw::Zlib missing';
my $version = 2; # v2 needs newer git
require_git('2.6') if $version >= 2;
-my $tmpdir = tempdir('pi-nntpd-tls-XXXXXX', TMPDIR => 1, CLEANUP => 1);
+my ($tmpdir, $for_destroy) = tmpdir();
my $err = "$tmpdir/stderr.log";
my $out = "$tmpdir/stdout.log";
my $inboxdir = "$tmpdir";
my $pi_config = "$tmpdir/pi_config";
my $group = 'test-nntpd-tls';
my $addr = $group . '@example.com';
-my $nntpd = 'blib/script/public-inbox-nntpd';
my $starttls = tcp_server();
my $nntps = tcp_server();
-my ($pid, $tail_pid);
-END {
- foreach ($pid, $tail_pid) {
- kill 'TERM', $_ if defined $_;
- }
-};
-
my $ibx = PublicInbox::Inbox->new({
inboxdir => $inboxdir,
name => 'nntpd-tls',
{
my $im = $ibx->importer(0);
- my $mime = PublicInbox::MIME->new(do {
- open my $fh, '<', 't/data/0001.patch' or die;
- local $/;
- <$fh>
- });
+ my $mime = eml_load 't/data/0001.patch';
ok($im->add($mime), 'message added');
$im->done;
if ($version == 1) {
my $nntps_addr = $nntps->sockhost . ':' . $nntps->sockport;
my $starttls_addr = $starttls->sockhost . ':' . $starttls->sockport;
my $env = { PI_CONFIG => $pi_config };
+my $td;
for my $args (
[ "--cert=$cert", "--key=$key",
for ($out, $err) {
open my $fh, '>', $_ or die "truncate: $!";
}
- if (my $tail_cmd = $ENV{TAIL}) { # don't assume GNU tail
- $tail_pid = fork;
- if (defined $tail_pid && $tail_pid == 0) {
- exec(split(' ', $tail_cmd), $out, $err);
- }
- }
- my $cmd = [ $nntpd, '-W0', @$args, "--stdout=$out", "--stderr=$err" ];
- $pid = spawn_listener($env, $cmd, [ $starttls, $nntps ]);
+ my $cmd = [ '-nntpd', '-W0', @$args, "--stdout=$out", "--stderr=$err" ];
+ $td = start_script($cmd, $env, { 3 => $starttls, 4 => $nntps });
my %o = (
SSL_hostname => 'server.local',
SSL_verifycn_name => 'server.local',
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($nntps, IPPROTO_TCP, $var)) or die;
ok(unpack('i', $x) > 0, 'TCP_DEFER_ACCEPT set on NNTPS');
defined($x = getsockopt($starttls, IPPROTO_TCP, $var)) or die;
};
$c = undef;
- kill('TERM', $pid);
- is($pid, waitpid($pid, 0), 'nntpd exited successfully');
+ $td->kill;
+ $td->join;
is($?, 0, 'no error in exited process');
- $pid = undef;
my $eout = eval {
open my $fh, '<', $err or die "open $err failed: $!";
local $/;
<$fh>;
};
unlike($eout, qr/wide/i, 'no Wide character warnings');
- if (defined $tail_pid) {
- kill 'TERM', $tail_pid;
- waitpid($tail_pid, 0);
- $tail_pid = undef;
- }
}
done_testing();