1 # Copyright (C) 2016-2018 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');
64 $res = $cb->(GET('/a/test/blah%40example.com/'));
65 is($res->code, 200, 'OK with URLMap mount');
66 $res = $cb->(GET('/a/test/blah%40example.com/raw'));
67 is($res->code, 200, 'OK with URLMap mount');
68 $res = $cb->(GET('/a/test/m/blah%40example.com.html'));
69 is($res->header('Location'),
70 'http://localhost/a/test/blah@example.com/',
71 'redirect functions properly under mount');
73 $res = $cb->(GET('/test/blah%40example.com/'));
74 is($res->code, 404, 'intentional 404 with URLMap mount');