use strict;
use warnings;
use Test::More;
-eval { require PublicInbox::SearchIdx };
-plan skip_all => "Xapian missing for nntpd" if $@;
-eval { require PublicInbox::Msgmap };
-plan skip_all => "DBD::SQLite missing for nntpd" if $@;
+foreach my $mod (qw(DBD::SQLite Search::Xapian Danga::Socket)) {
+ eval "require $mod";
+ plan skip_all => "$mod missing for nntpd.t" if $@;
+}
+require PublicInbox::SearchIdx;
+require PublicInbox::Msgmap;
use Cwd;
use Email::Simple;
use IO::Socket;
use File::Temp qw/tempdir/;
use Net::NNTP;
use IPC::Run qw(run);
-use Data::Dumper;
my $tmpdir = tempdir(CLEANUP => 1);
my $home = "$tmpdir/pi-home";
syswrite($s, "HDR $k $mid\r\n");
do {
sysread($s, $buf, 4096, length($buf));
- } until ($buf =~ /^[^2]../ || $buf =~ /\r\n\.\r\n\z/);
+ } until ($buf =~ /\r\n\.\r\n\z/);
my @r = split("\r\n", $buf);
like($r[0], qr/\A224 /, '224 response for HDR');
is($r[1], "0 $v", 'got expected response for HDR');
$buf = '';
do {
sysread($s, $buf, 4096, length($buf));
- } until ($buf =~ /^[^2]../ || $buf =~ /\r\n\.\r\n\z/);
+ } until ($buf =~ /\r\n\.\r\n\z/);
my @r = split("\r\n", $buf);
like($r[0], qr/^224 /, 'got 224 response for OVER');
is($r[1], "0\thihi\tMe <me\@example.com>\t" .
is($r[2], '.', 'correctly terminated response');
}
+ is_deeply($n->xhdr(qw(Cc 1-)), { 1 => 'test-nntpd@example.com' },
+ 'XHDR Cc 1- works');
+ is_deeply($n->xhdr(qw(References 1-)), { 1 => '' },
+ 'XHDR References 1- works (empty string)');
+ is_deeply($n->xhdr(qw(list-id 1-)), {},
+ 'XHDR on invalid header returns empty');
+
+ {
+ syswrite($s, "HDR List-id 1-\r\n");
+ $buf = '';
+ do {
+ sysread($s, $buf, 4096, length($buf));
+ } until ($buf =~ /\r\n\z/);
+ my @r = split("\r\n", $buf);
+ like($r[0], qr/^5\d\d /,
+ 'got 5xx response for unoptimized HDR');
+ is(scalar @r, 1, 'only one response line');
+ }
+
ok(kill('TERM', $pid), 'killed nntpd');
$pid = undef;
waitpid(-1, 0);