about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/admin.t20
-rw-r--r--t/cgi.t30
-rw-r--r--t/v2mirror.t31
3 files changed, 68 insertions, 13 deletions
diff --git a/t/admin.t b/t/admin.t
index a9d67d25..c25667b2 100644
--- a/t/admin.t
+++ b/t/admin.t
@@ -78,4 +78,24 @@ SKIP: {
 }
 
 chdir '/';
+
+my @pairs = (
+        '1g' => 1024 ** 3,
+        666 => 666,
+        '1500K' => 1500 * 1024,
+        '15m' => 15 * (1024 ** 2),
+);
+
+while (@pairs) {
+        my ($in, $out) = splice(@pairs, 0, 2);
+        my $orig = $in;
+        ok(PublicInbox::Admin::parse_unsigned(\$in), "parse_unsigned $orig");
+        is($in, $out, "got $orig => ($in == $out)");
+}
+
+for my $v ('', 'bogus', '1p', '1gig') {
+        ok(!PublicInbox::Admin::parse_unsigned(\$v),
+                "parse_unsigned rejects $v");
+}
+
 done_testing();
diff --git a/t/cgi.t b/t/cgi.t
index 52f80e88..bceb83e5 100644
--- a/t/cgi.t
+++ b/t/cgi.t
@@ -55,10 +55,14 @@ Date: Thu, 01 Jan 1970 00:00:00 +0000
 
 zzzzzz
 EOF
-        $im->add($mime);
+        ok($im->add($mime), 'added initial message');
+
+        $mime->header_set('Message-ID', '<toobig@example.com>');
+        $mime->body_str_set("z\n" x 1024);
+        ok($im->add($mime), 'added big message');
 
         # deliver a reply, too
-        my $reply = Email::MIME->new(<<EOF);
+        $mime = Email::MIME->new(<<EOF);
 From: You <you\@example.com>
 To: Me <me\@example.com>
 Cc: $addr
@@ -72,7 +76,7 @@ Me wrote:
 
 what?
 EOF
-        $im->add($reply);
+        ok($im->add($mime), 'added reply');
 
         my $slashy_mid = 'slashy/asdf@example.com';
         my $slashy = Email::MIME->new(<<EOF);
@@ -85,7 +89,7 @@ Date: Thu, 01 Jan 1970 00:00:01 +0000
 
 slashy
 EOF
-        $im->add($slashy);
+        ok($im->add($slashy), 'added slash');
         $im->done;
 
         my $res = cgi_run("/test/slashy/asdf\@example.com/raw");
@@ -99,14 +103,9 @@ EOF
         my $path = "/test/blahblah\@example.com/t.mbox.gz";
         my $res = cgi_run($path);
         like($res->{head}, qr/^Status: 501 /, "search not-yet-enabled");
-        my $indexed;
-        eval {
-                require DBD::SQLite;
-                require PublicInbox::SearchIdx;
-                my $s = PublicInbox::SearchIdx->new($ibx, 1);
-                $s->index_sync;
-                $indexed = 1;
-        };
+        my $cmd = ['-index', $ibx->{inboxdir}, '--max-size=2k'];
+        my $opt = { 2 => \(my $err) };
+        my $indexed = run_script($cmd, undef, $opt);
         if ($indexed) {
                 $res = cgi_run($path);
                 like($res->{head}, qr/^Status: 200 /, "search returned mbox");
@@ -117,9 +116,14 @@ EOF
                         IO::Uncompress::Gunzip::gunzip(\$in => \$out);
                         like($out, qr/^From /m, "From lines in mbox");
                 };
+                $res = cgi_run('/test/toobig@example.com/');
+                like($res->{head}, qr/^Status: 300 /,
+                        'did not index or return >max-size message');
+                like($err, qr/skipping [a-f0-9]{40,}/,
+                        'warned about skipping large OID');
         } else {
                 like($res->{head}, qr/^Status: 501 /, "search not available");
-                SKIP: { skip 'DBD::SQLite not available', 2 };
+                SKIP: { skip 'DBD::SQLite not available', 4 };
         }
 
         my $have_xml_treepp = eval { require XML::TreePP; 1 } if $indexed;
diff --git a/t/v2mirror.t b/t/v2mirror.t
index 406bbd4f..ecf96891 100644
--- a/t/v2mirror.t
+++ b/t/v2mirror.t
@@ -187,6 +187,37 @@ is($mibx->git->check($to_purge), undef, 'unindex+prune successful in mirror');
         is(scalar($mset->items), 0, '1@example.com no longer visible in mirror');
 }
 
+if ('max size') {
+        $mime->header_set('Message-ID', '<2big@a>');
+        my $max = '2k';
+        $mime->body_str_set("z\n" x 1024);
+        ok($v2w->add($mime), "add big message");
+        $v2w->done;
+        $ibx->cleanup;
+        $fetch_each_epoch->();
+        PublicInbox::InboxWritable::cleanup($mibx);
+        my $cmd = ['-index', "$tmpdir/m", "--max-size=$max" ];
+        my $opt = { 2 => \(my $err) };
+        ok(run_script($cmd, undef, $opt), 'indexed with --max-size');
+        like($err, qr/skipping [a-f0-9]{40,}/, 'warned about skipping message');
+        $mset = $mibx->search->reopen->query('m:2big@a', {mset =>1});
+        is(scalar($mset->items), 0, 'large message not indexed');
+
+        {
+                open my $fh, '>>', $pi_config or die;
+                print $fh <<EOF or die;
+[publicinbox]
+        indexMaxSize = 2k
+EOF
+                close $fh or die;
+        }
+        $cmd = ['-index', "$tmpdir/m", "--reindex" ];
+        ok(run_script($cmd, undef, $opt), 'reindexed w/ indexMaxSize in file');
+        like($err, qr/skipping [a-f0-9]{40,}/, 'warned about skipping message');
+        $mset = $mibx->search->reopen->query('m:2big@a', {mset =>1});
+        is(scalar($mset->items), 0, 'large message not re-indexed');
+}
+
 ok($td->kill, 'killed httpd');
 $td->join;