1 # Copyright (C) 2016-2019 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);
14 use_ok $_ foreach @mods;
15 use PublicInbox::Import;
17 use PublicInbox::Config;
20 use Plack::App::URLMap;
21 my $config = PublicInbox::Config->new(\<<EOF);
23 $cfgpfx.inboxdir=$maindir
25 is(0, system(qw(git init -q --bare), $maindir), "git init (main)");
26 my $git = PublicInbox::Git->new($maindir);
27 my $im = PublicInbox::Import->new($git, 'test', $addr);
29 my $mime = Email::MIME->new(<<EOF);
30 From: Me <me\@example.com>
31 To: You <you\@example.com>
33 Message-Id: <blah\@example.com>
35 Date: Thu, 01 Jan 1970 00:00:00 +0000
43 my $www = PublicInbox::WWW->new($config);
46 mount '/a' => builder { sub { $www->call(@_) } };
47 mount '/b' => builder { sub { $www->call(@_) } };
54 $res = $cb->(GET('/a/test/new.atom'));
55 like($res->content, qr!\bhttp://[^/]+/a/test/!,
56 'URLs which exist in Atom feed are mount-aware');
57 unlike($res->content, qr!\b\Qhttp://[^/]+/test/\E!,
58 'No URLs which are not mount-aware');
60 $res = $cb->(GET('/a/test/new.html'));
61 like($res->content, qr!git clone --mirror http://[^/]+/a/test\b!,
62 'clone URL in new.html is mount-aware');
64 $res = $cb->(GET('/a/test/blah%40example.com/'));
65 is($res->code, 200, 'OK with URLMap mount');
66 like($res->content, qr!git clone --mirror http://[^/]+/a/test\b!,
67 'clone URL in /$INBOX/$MESSAGE_ID/ is mount-aware');
69 $res = $cb->(GET('/a/test/blah%40example.com/raw'));
70 is($res->code, 200, 'OK with URLMap mount');
71 like($res->content, qr!^List-Archive: <http://[^/]+/a/test/>!m,
72 'List-Archive set in /raw mboxrd');
74 qr!^Archived-At: <http://[^/]+/a/test/blah\@example\.com/>!m,
75 'Archived-At set in /raw mboxrd');
78 $res = $cb->(GET('/a/test/m/blah%40example.com.html'));
79 is($res->header('Location'),
80 'http://localhost/a/test/blah@example.com/',
81 'redirect functions properly under mount');
83 $res = $cb->(GET('/test/blah%40example.com/'));
84 is($res->code, 404, 'intentional 404 with URLMap mount');
88 require_mods(qw(DBD::SQLite Search::Xapian IO::Uncompress::Gunzip), 3);
89 my $ibx = $config->lookup_name('test');
90 require_ok 'PublicInbox::SearchIdx';
91 PublicInbox::SearchIdx->new($ibx, 1)->index_sync;
94 my $res = $cb->(GET('/a/test/blah@example.com/t.mbox.gz'));
95 my $gz = $res->content;
97 IO::Uncompress::Gunzip::gunzip(\$gz => \$raw);
98 like($raw, qr!^List-Archive: <http://[^/]+/a/test/>!m,
99 'List-Archive set in /t.mbox.gz mboxrd');
102 <http://[^/]+/a/test/blah\@example\.com/>!mx,
103 'Archived-At set in /t.mbox.gz mboxrd');