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 File::Temp qw/tempdir/;
8 my $tmpdir = tempdir('psgi-path-XXXXXX', TMPDIR => 1, CLEANUP => 1);
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({
25 "$cfgpfx.address" => $addr,
26 "$cfgpfx.mainrepo" => $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: $@", 2;
95 my $ibx = $config->lookup_name('test');
96 PublicInbox::SearchIdx->new($ibx, 1)->index_sync;
99 my $res = $cb->(GET('/a/test/blah@example.com/t.mbox.gz'));
100 my $gz = $res->content;
102 IO::Uncompress::Gunzip::gunzip(\$gz => \$raw);
103 like($raw, qr!^List-Archive: <http://[^/]+/a/test/>!m,
104 'List-Archive set in /t.mbox.gz mboxrd');
107 <http://[^/]+/a/test/blah\@example\.com/>!mx,
108 'Archived-At set in /t.mbox.gz mboxrd');