2 # Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
7 use PublicInbox::TestCommon;
8 use PublicInbox::Config;
9 my ($tmpdir, $for_destroy) = tmpdir();
10 my $v1dir = "$tmpdir/v1.git";
11 my $cfgpfx = "publicinbox.test";
12 my @mods = qw(HTTP::Request::Common Plack::Test URI::Escape
13 Plack::Builder Plack::App::URLMap);
15 use_ok $_ foreach @mods;
16 use_ok 'PublicInbox::WWW';
17 my $ibx = create_inbox 'test', tmpdir => $v1dir, sub {
19 $im->add(PublicInbox::Eml->new(<<EOF)) or BAIL_OUT;
20 From: Me <me\@example.com>
21 To: You <you\@example.com>
22 Cc: $ibx->{-primary_address}
23 Message-Id: <blah\@example.com>
25 Date: Thu, 01 Jan 1970 00:00:00 +0000
30 my $cfg = PublicInbox::Config->new(\<<EOF);
31 $cfgpfx.address=$ibx->{-primary_address}
32 $cfgpfx.inboxdir=$v1dir
34 my $www = PublicInbox::WWW->new($cfg);
35 my $app = builder(sub {
37 mount('/a' => builder(sub { sub { $www->call(@_) } }));
38 mount('/b' => builder(sub { sub { $www->call(@_) } }));
45 $res = $cb->(GET('/a/test/new.atom'));
46 like($res->content, qr!\bhttp://[^/]+/a/test/!,
47 'URLs which exist in Atom feed are mount-aware');
48 unlike($res->content, qr!\b\Qhttp://[^/]+/test/\E!,
49 'No URLs which are not mount-aware');
51 $res = $cb->(GET('/a/test/_/text/mirror/'));
52 like($res->content, qr!git clone --mirror\s+.*?http://[^/]+/a/test\b!s,
53 'clone URL in /text/mirror is mount-aware');
55 $res = $cb->(GET('/a/test/blah%40example.com/raw'));
56 is($res->code, 200, 'OK with URLMap mount');
58 qr/^Message-Id: <blah\@example\.com>\n/sm,
59 'headers appear in /raw');
62 $res = $cb->(GET('/a/test/m/blah%40example.com.html'));
63 is($res->header('Location'),
64 'http://localhost/a/test/blah@example.com/',
65 'redirect functions properly under mount');
67 $res = $cb->(GET('/test/blah%40example.com/'));
68 is($res->code, 404, 'intentional 404 with URLMap mount');
72 require_mods(qw(DBD::SQLite Search::Xapian IO::Uncompress::Gunzip), 3);
73 require_ok 'PublicInbox::SearchIdx';
74 PublicInbox::SearchIdx->new($ibx, 1)->index_sync;
77 my $res = $cb->(GET('/a/test/blah@example.com/t.mbox.gz'));
78 my $gz = $res->content;
80 IO::Uncompress::Gunzip::gunzip(\$gz => \$raw);
81 like($raw, qr!^Message-Id:\x20<blah\@example\.com>\n!sm,
82 'headers appear in /t.mbox.gz mboxrd');