2 # Copyright (C) 2020-2021 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 Search::Xapian
12 HTTP::Request::Common Plack::Test URI::Escape Plack::Builder));
13 use_ok($_) for (qw(HTTP::Request::Common Plack::Test));
14 require PublicInbox::WWW;
15 my ($ro_home, $cfg_path) = setup_public_inboxes;
16 my ($tmpdir, $for_destroy) = tmpdir;
17 my $home = "$tmpdir/home";
18 mkdir $home or BAIL_OUT $!;
19 mkdir "$home/.public-inbox" or BAIL_OUT $!;
20 my $pi_config = "$home/.public-inbox/config";
21 cp("$ro_home/.public-inbox/config", $pi_config) or BAIL_OUT;
22 my $env = { HOME => $home };
23 run_script([qw(-extindex --all), "$tmpdir/eidx"], $env) or BAIL_OUT;
25 open my $cfgfh, '>', $pi_config or BAIL_OUT;
27 print $cfgfh <<EOM or BAIL_OUT;
30 url = http://bogus.example.com/all
35 my $www = PublicInbox::WWW->new(PublicInbox::Config->new($pi_config));
38 my $res = $cb->(GET('/all/'));
39 is($res->code, 200, '/all/ good');
40 $res = $cb->(GET('/all/new.atom', Host => 'usethis.example.com'));
41 like($res->content, qr!http://usethis\.example\.com/!s,
42 'Host: header respected in Atom feed');
43 unlike($res->content, qr!http://bogus\.example\.com/!s,
44 'default URL ignored with different host header');
46 $res = $cb->(GET('/all/_/text/config/'));
47 is($res->code, 200, '/text/config HTML');
48 $res = $cb->(GET('/all/_/text/config/raw'));
49 is($res->code, 200, '/text/config raw');
50 my $f = "$tmpdir/extindex.config";
51 open my $fh, '>', $f or xbail $!;
52 print $fh $res->content or xbail $!;
53 close $fh or xbail $!;
54 my $cfg = PublicInbox::Config->git_config_dump($f);
55 is($?, 0, 'no errors from git-config parsing');
56 ok($cfg->{'extindex.all.topdir'}, 'extindex.topdir defined');
58 $res = $cb->(GET('/all/all.mbox.gz'));
59 is($res->code, 200, 'all.mbox.gz');
61 $res = $cb->(GET('/'));
62 like($res->content, qr!\Qhttp://bogus.example.com/all\E!,
64 $res = $cb->(GET('/?q='));
65 is($res->code, 200, 'no query means all inboxes');
66 $res = $cb->(GET('/?q=nonexistent'));
67 is($res->code, 404, 'no inboxes matched');
68 unlike($res->content, qr!no inboxes, yet!,
69 'we have inboxes, just no matches');
71 test_psgi(sub { $www->call(@_) }, $client);
72 %$env = (%$env, TMPDIR => $tmpdir, PI_CONFIG => $pi_config);
73 test_httpd($env, $client);