1 # Copyright (C) 2016-2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
7 use PublicInbox::TestCommon;
8 my ($tmpdir, $for_destroy) = tmpdir();
9 my $maindir = "$tmpdir/main.git";
10 my $addr = 'test-public@example.com';
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 use PublicInbox::Import;
19 use PublicInbox::Config;
20 my $config = PublicInbox::Config->new(\<<EOF);
22 $cfgpfx.inboxdir=$maindir
24 is(0, system(qw(git init -q --bare), $maindir), "git init (main)");
25 my $git = PublicInbox::Git->new($maindir);
26 my $im = PublicInbox::Import->new($git, 'test', $addr);
28 my $mime = Email::MIME->new(<<EOF);
29 From: Me <me\@example.com>
30 To: You <you\@example.com>
32 Message-Id: <blah\@example.com>
34 Date: Thu, 01 Jan 1970 00:00:00 +0000
42 my $www = PublicInbox::WWW->new($config);
43 my $app = builder(sub {
45 mount('/a' => builder(sub { sub { $www->call(@_) } }));
46 mount('/b' => builder(sub { sub { $www->call(@_) } }));
53 $res = $cb->(GET('/a/test/new.atom'));
54 like($res->content, qr!\bhttp://[^/]+/a/test/!,
55 'URLs which exist in Atom feed are mount-aware');
56 unlike($res->content, qr!\b\Qhttp://[^/]+/test/\E!,
57 'No URLs which are not mount-aware');
59 $res = $cb->(GET('/a/test/new.html'));
60 like($res->content, qr!git clone --mirror http://[^/]+/a/test\b!,
61 'clone URL in new.html is mount-aware');
63 $res = $cb->(GET('/a/test/blah%40example.com/'));
64 is($res->code, 200, 'OK with URLMap mount');
65 like($res->content, qr!git clone --mirror http://[^/]+/a/test\b!,
66 'clone URL in /$INBOX/$MESSAGE_ID/ is mount-aware');
68 $res = $cb->(GET('/a/test/blah%40example.com/raw'));
69 is($res->code, 200, 'OK with URLMap mount');
70 like($res->content, qr!^List-Archive: <http://[^/]+/a/test/>!m,
71 'List-Archive set in /raw mboxrd');
73 qr!^Archived-At: <http://[^/]+/a/test/blah\@example\.com/>!m,
74 'Archived-At set in /raw mboxrd');
77 $res = $cb->(GET('/a/test/m/blah%40example.com.html'));
78 is($res->header('Location'),
79 'http://localhost/a/test/blah@example.com/',
80 'redirect functions properly under mount');
82 $res = $cb->(GET('/test/blah%40example.com/'));
83 is($res->code, 404, 'intentional 404 with URLMap mount');
87 require_mods(qw(DBD::SQLite Search::Xapian IO::Uncompress::Gunzip), 3);
88 my $ibx = $config->lookup_name('test');
89 require_ok 'PublicInbox::SearchIdx';
90 PublicInbox::SearchIdx->new($ibx, 1)->index_sync;
93 my $res = $cb->(GET('/a/test/blah@example.com/t.mbox.gz'));
94 my $gz = $res->content;
96 IO::Uncompress::Gunzip::gunzip(\$gz => \$raw);
97 like($raw, qr!^List-Archive: <http://[^/]+/a/test/>!m,
98 'List-Archive set in /t.mbox.gz mboxrd');
101 <http://[^/]+/a/test/blah\@example\.com/>!mx,
102 'Archived-At set in /t.mbox.gz mboxrd');