]> Sergey Matveev's repositories - public-inbox.git/blob - t/psgi_scan_all.t
No ext_urls
[public-inbox.git] / t / psgi_scan_all.t
1 #!perl -w
2 # Copyright (C) 2019-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::TestCommon;
7 use PublicInbox::Eml;
8 use PublicInbox::Config;
9 my @mods = qw(HTTP::Request::Common Plack::Test URI::Escape DBD::SQLite);
10 require_git 2.6;
11 require_mods(@mods);
12 use_ok 'PublicInbox::WWW';
13 foreach my $mod (@mods) { use_ok $mod; }
14 my $cfg = '';
15 foreach my $i (1..2) {
16         my $ibx = create_inbox "test-$i", version => 2, indexlevel => 'basic',
17         sub {
18                 my ($im, $ibx) = @_;
19                 $im->add(PublicInbox::Eml->new(<<EOF)) or BAIL_OUT;
20 From: a\@example.com
21 To: $ibx->{-primary_address}
22 Subject: s$i
23 Message-ID: <a-mid-$i\@b>
24 Date: Fri, 02 Oct 1993 00:00:00 +0000
25
26 hello world
27 EOF
28         };
29         my $cfgpfx = "publicinbox.test-$i";
30         $cfg .= "$cfgpfx.address=$ibx->{-primary_address}\n";
31         $cfg .= "$cfgpfx.inboxdir=$ibx->{inboxdir}\n";
32         $cfg .= "$cfgpfx.url=http://example.com/$i\n";
33
34 }
35 my $www = PublicInbox::WWW->new(PublicInbox::Config->new(\$cfg));
36
37 test_psgi(sub { $www->call(@_) }, sub {
38         my ($cb) = @_;
39         foreach my $i (1..2) {
40                 foreach my $end ('', '/') {
41                         my $res = $cb->(GET("/a-mid-$i\@b$end"));
42                         is($res->code, 302, 'got 302');
43                         is($res->header('Location'),
44                                 "http://example.com/$i/a-mid-$i\@b/",
45                                 "redirected OK to $i");
46                 }
47         }
48         foreach my $x (qw(inv@lid inv@lid/ i/v/a l/i/d/)) {
49                 my $res = $cb->(GET("/$x"));
50                 is($res->code, 404, "404 on $x");
51         }
52 });
53 done_testing;