]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/nntpd.t
fixup Plack-related requires
[public-inbox.git] / t / nntpd.t
index ea2c3df882b7c1ff267c9ddb78456c697ed00d0b..d8c2e7b305f4563aefea6e3ab32885a51c89c1b5 100644 (file)
--- a/t/nntpd.t
+++ b/t/nntpd.t
@@ -3,10 +3,12 @@
 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;
@@ -15,7 +17,6 @@ use Socket qw(SO_KEEPALIVE IPPROTO_TCP TCP_NODELAY);
 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";
@@ -130,7 +131,7 @@ EOF
                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');
@@ -151,7 +152,49 @@ EOF
                        '<nntp@example.com>',
                        '',
                        '202',
-                       '1' ] }, "XOVER works");
+                       '1' ] }, "XOVER range works");
+
+       is_deeply($n->xover('1'), {
+               '1' => ['hihi',
+                       'Me <me@example.com>',
+                       'Thu, 01 Jan 1970 06:06:06 +0000',
+                       '<nntp@example.com>',
+                       '',
+                       '202',
+                       '1' ] }, "XOVER by article works");
+
+       {
+               syswrite($s, "OVER $mid\r\n");
+               $buf = '';
+               do {
+                       sysread($s, $buf, 4096, length($buf));
+               } 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" .
+                       "Thu, 01 Jan 1970 06:06:06 +0000\t" .
+                       "$mid\t\t202\t1", 'OVER by Message-ID works');
+               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;