2 # Copyright (C) all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use PublicInbox::TestCommon;
7 use PublicInbox::Config;
11 require_mods(qw(json DBD::SQLite Xapian
12 HTTP::Request::Common Plack::Test URI::Escape Plack::Builder));
13 use_ok($_) for (qw(HTTP::Request::Common Plack::Test));
14 use IO::Uncompress::Gunzip qw(gunzip);
15 require PublicInbox::WWW;
16 my ($ro_home, $cfg_path) = setup_public_inboxes;
17 my ($tmpdir, $for_destroy) = tmpdir;
18 my $home = "$tmpdir/home";
19 mkdir $home or BAIL_OUT $!;
20 mkdir "$home/.public-inbox" or BAIL_OUT $!;
21 my $pi_config = "$home/.public-inbox/config";
22 cp($cfg_path, $pi_config) or BAIL_OUT;
23 my $env = { HOME => $home };
24 my $m2t = create_inbox 'mid2tid', version => 2, indexlevel => 'basic', sub {
27 $im->add(PublicInbox::Eml->new(<<EOM)) or xbail 'add';
28 Date: Fri, 02 Oct 1993 00:0$n:00 +0000
32 References: <a-mid\@b>
36 $im->add(PublicInbox::Eml->new(<<EOM)) or xbail 'add';
37 Date: Fri, 02 Oct 1993 00:0$n:00 +0000
39 Subject: unrelated tid $n
41 References: <b-mid\@b>
47 open my $cfgfh, '>>', $pi_config or BAIL_OUT;
49 print $cfgfh <<EOM or BAIL_OUT;
52 url = http://bogus.example.com/all
57 inboxdir = $m2t->{inboxdir}
58 address = $m2t->{-primary_address}
60 close $cfgfh or xbail "close: $!";
63 run_script([qw(-extindex --all), "$tmpdir/eidx"], $env) or BAIL_OUT;
64 my $www = PublicInbox::WWW->new(PublicInbox::Config->new($pi_config));
67 my $res = $cb->(GET('/all/'));
68 is($res->code, 200, '/all/ good');
69 $res = $cb->(GET('/all/new.atom', Host => 'usethis.example.com'));
70 like($res->content, qr!http://usethis\.example\.com/!s,
71 'Host: header respected in Atom feed');
72 unlike($res->content, qr!http://bogus\.example\.com/!s,
73 'default URL ignored with different host header');
75 $res = $cb->(GET('/all/_/text/config/'));
76 is($res->code, 200, '/text/config HTML');
77 $res = $cb->(GET('/all/_/text/config/raw'));
78 is($res->code, 200, '/text/config raw');
79 my $f = "$tmpdir/extindex.config";
80 open my $fh, '>', $f or xbail $!;
81 print $fh $res->content or xbail $!;
82 close $fh or xbail $!;
83 my $cfg = PublicInbox::Config->git_config_dump($f);
84 is($?, 0, 'no errors from git-config parsing');
85 ok($cfg->{'extindex.all.topdir'}, 'extindex.topdir defined');
87 $res = $cb->(GET('/all/all.mbox.gz'));
88 is($res->code, 200, 'all.mbox.gz');
90 $res = $cb->(GET('/'));
91 like($res->content, qr!\Qhttp://bogus.example.com/all\E!,
93 $res = $cb->(GET('/?q='));
94 is($res->code, 200, 'no query means all inboxes');
95 $res = $cb->(GET('/?q=nonexistent'));
96 is($res->code, 404, 'no inboxes matched');
97 unlike($res->content, qr!no inboxes, yet!,
98 'we have inboxes, just no matches');
101 for my $pfx (qw(/t1 /t2), '') {
102 $res = $cb->(GET($pfx.'/manifest.js.gz'));
103 gunzip(\($res->content) => \(my $js));
104 $m->{$pfx} = json_utf8->decode($js);
106 is_deeply([sort keys %{$m->{''}}],
107 [ sort(keys %{$m->{'/t1'}}, keys %{$m->{'/t2'}}) ],
109 is_deeply([ sort keys %{$m->{'/t2'}} ], [ '/t2/git/0.git' ],
111 is_deeply([ sort keys %{$m->{'/t1'}} ], [ '/t1' ],
114 # ensure ibx->{isrch}->{es}->over is used instead of ibx->over:
115 $res = $cb->(POST("/m2t/t\@1/?q=dt:19931002000259..&x=m"));
116 is($res->code, 200, 'hit on mid2tid query');
117 $res = $cb->(POST("/m2t/t\@1/?q=dt:19931002000400..&x=m"));
118 is($res->code, 404, '404 on out-of-range mid2tid query');
119 $res = $cb->(POST("/m2t/t\@1/?q=s:unrelated&x=m"));
120 is($res->code, 404, '404 on cross-thread search');
123 for my $c (qw(new active)) {
124 $res = $cb->(GET("/m2t/topics_$c.html"));
125 is($res->code, 200, "topics_$c.html on basic v2");
126 $res = $cb->(GET("/all/topics_$c.html"));
127 is($res->code, 200, "topics_$c.html on extindex");
130 test_psgi(sub { $www->call(@_) }, $client);
131 %$env = (%$env, TMPDIR => $tmpdir, PI_CONFIG => $pi_config);
132 test_httpd($env, $client);