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 require './t/common.perl';
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 foreach my $mod (@mods) {
15 plan skip_all => "$mod missing for plack.t" if $@;
17 use_ok $_ foreach @mods;
18 use PublicInbox::Import;
20 use PublicInbox::Config;
23 use Plack::App::URLMap;
24 my $config = PublicInbox::Config->new(\<<EOF);
26 $cfgpfx.inboxdir=$maindir
28 is(0, system(qw(git init -q --bare), $maindir), "git init (main)");
29 my $git = PublicInbox::Git->new($maindir);
30 my $im = PublicInbox::Import->new($git, 'test', $addr);
32 my $mime = Email::MIME->new(<<EOF);
33 From: Me <me\@example.com>
34 To: You <you\@example.com>
36 Message-Id: <blah\@example.com>
38 Date: Thu, 01 Jan 1970 00:00:00 +0000
46 my $www = PublicInbox::WWW->new($config);
49 mount '/a' => builder { sub { $www->call(@_) } };
50 mount '/b' => builder { sub { $www->call(@_) } };
57 $res = $cb->(GET('/a/test/new.atom'));
58 like($res->content, qr!\bhttp://[^/]+/a/test/!,
59 'URLs which exist in Atom feed are mount-aware');
60 unlike($res->content, qr!\b\Qhttp://[^/]+/test/\E!,
61 'No URLs which are not mount-aware');
63 $res = $cb->(GET('/a/test/new.html'));
64 like($res->content, qr!git clone --mirror http://[^/]+/a/test\b!,
65 'clone URL in new.html is mount-aware');
67 $res = $cb->(GET('/a/test/blah%40example.com/'));
68 is($res->code, 200, 'OK with URLMap mount');
69 like($res->content, qr!git clone --mirror http://[^/]+/a/test\b!,
70 'clone URL in /$INBOX/$MESSAGE_ID/ is mount-aware');
72 $res = $cb->(GET('/a/test/blah%40example.com/raw'));
73 is($res->code, 200, 'OK with URLMap mount');
74 like($res->content, qr!^List-Archive: <http://[^/]+/a/test/>!m,
75 'List-Archive set in /raw mboxrd');
77 qr!^Archived-At: <http://[^/]+/a/test/blah\@example\.com/>!m,
78 'Archived-At set in /raw mboxrd');
81 $res = $cb->(GET('/a/test/m/blah%40example.com.html'));
82 is($res->header('Location'),
83 'http://localhost/a/test/blah@example.com/',
84 'redirect functions properly under mount');
86 $res = $cb->(GET('/test/blah%40example.com/'));
87 is($res->code, 404, 'intentional 404 with URLMap mount');
91 my @mods = qw(DBI DBD::SQLite Search::Xapian IO::Uncompress::Gunzip);
92 foreach my $mod (@mods) {
93 eval "require $mod" or skip "$mod not available: $@", 3;
95 my $ibx = $config->lookup_name('test');
96 require_ok 'PublicInbox::SearchIdx';
97 PublicInbox::SearchIdx->new($ibx, 1)->index_sync;
100 my $res = $cb->(GET('/a/test/blah@example.com/t.mbox.gz'));
101 my $gz = $res->content;
103 IO::Uncompress::Gunzip::gunzip(\$gz => \$raw);
104 like($raw, qr!^List-Archive: <http://[^/]+/a/test/>!m,
105 'List-Archive set in /t.mbox.gz mboxrd');
108 <http://[^/]+/a/test/blah\@example\.com/>!mx,
109 'Archived-At set in /t.mbox.gz mboxrd');