]> Sergey Matveev's repositories - public-inbox.git/blob - t/psgi_mount.t
www: move mirror instructions to /text/
[public-inbox.git] / t / psgi_mount.t
1 #!perl -w
2 # Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict;
5 use v5.10.1;
6 use PublicInbox::Eml;
7 use PublicInbox::TestCommon;
8 use PublicInbox::Config;
9 my ($tmpdir, $for_destroy) = tmpdir();
10 my $v1dir = "$tmpdir/v1.git";
11 my $cfgpfx = "publicinbox.test";
12 my @mods = qw(HTTP::Request::Common Plack::Test URI::Escape
13         Plack::Builder Plack::App::URLMap);
14 require_mods(@mods);
15 use_ok $_ foreach @mods;
16 use_ok 'PublicInbox::WWW';
17 my $ibx = create_inbox 'test', tmpdir => $v1dir, sub {
18         my ($im, $ibx) = @_;
19         $im->add(PublicInbox::Eml->new(<<EOF)) or BAIL_OUT;
20 From: Me <me\@example.com>
21 To: You <you\@example.com>
22 Cc: $ibx->{-primary_address}
23 Message-Id: <blah\@example.com>
24 Subject: hihi
25 Date: Thu, 01 Jan 1970 00:00:00 +0000
26
27 zzzzzz
28 EOF
29 };
30 my $cfg = PublicInbox::Config->new(\<<EOF);
31 $cfgpfx.address=$ibx->{-primary_address}
32 $cfgpfx.inboxdir=$v1dir
33 EOF
34 my $www = PublicInbox::WWW->new($cfg);
35 my $app = builder(sub {
36         enable('Head');
37         mount('/a' => builder(sub { sub { $www->call(@_) } }));
38         mount('/b' => builder(sub { sub { $www->call(@_) } }));
39 });
40
41 test_psgi($app, sub {
42         my ($cb) = @_;
43         my $res;
44         # Atom feed:
45         $res = $cb->(GET('/a/test/new.atom'));
46         like($res->content, qr!\bhttp://[^/]+/a/test/!,
47                 'URLs which exist in Atom feed are mount-aware');
48         unlike($res->content, qr!\b\Qhttp://[^/]+/test/\E!,
49                 'No URLs which are not mount-aware');
50
51         $res = $cb->(GET('/a/test/_/text/mirror/'));
52         like($res->content, qr!git clone --mirror\s+.*?http://[^/]+/a/test\b!s,
53                 'clone URL in /text/mirror is mount-aware');
54
55         $res = $cb->(GET('/a/test/blah%40example.com/raw'));
56         is($res->code, 200, 'OK with URLMap mount');
57         like($res->content,
58                 qr/^Message-Id: <blah\@example\.com>\n/sm,
59                 'headers appear in /raw');
60
61         # redirects
62         $res = $cb->(GET('/a/test/m/blah%40example.com.html'));
63         is($res->header('Location'),
64                 'http://localhost/a/test/blah@example.com/',
65                 'redirect functions properly under mount');
66
67         $res = $cb->(GET('/test/blah%40example.com/'));
68         is($res->code, 404, 'intentional 404 with URLMap mount');
69 });
70
71 SKIP: {
72         require_mods(qw(DBD::SQLite Search::Xapian IO::Uncompress::Gunzip), 3);
73         require_ok 'PublicInbox::SearchIdx';
74         PublicInbox::SearchIdx->new($ibx, 1)->index_sync;
75         test_psgi($app, sub {
76                 my ($cb) = @_;
77                 my $res = $cb->(GET('/a/test/blah@example.com/t.mbox.gz'));
78                 my $gz = $res->content;
79                 my $raw;
80                 IO::Uncompress::Gunzip::gunzip(\$gz => \$raw);
81                 like($raw, qr!^Message-Id:\x20<blah\@example\.com>\n!sm,
82                         'headers appear in /t.mbox.gz mboxrd');
83         });
84 }
85
86 done_testing();