about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/config.t4
-rw-r--r--t/extindex-psgi.t48
-rw-r--r--t/psgi_v2.t30
3 files changed, 55 insertions, 27 deletions
diff --git a/t/config.t b/t/config.t
index fe684106..06a105c1 100644
--- a/t/config.t
+++ b/t/config.t
@@ -159,7 +159,7 @@ my $xre = join('|', keys %X);
 for my $s (@invalid) {
         my $d = $s;
         $d =~ s/($xre)/$X{$1}/g;
-        ok(!PublicInbox::Config::valid_inbox_name($s), "`$d' name rejected");
+        ok(!PublicInbox::Config::valid_foo_name($s), "`$d' name rejected");
 }
 
 # obviously-valid examples
@@ -175,7 +175,7 @@ my @valid = qw(a a@example a@example.com);
 # '!', '$', '=', '+'
 push @valid, qw[bang! ca$h less< more> 1% (parens) &more eql= +plus], '#hash';
 for my $s (@valid) {
-        ok(PublicInbox::Config::valid_inbox_name($s), "`$s' name accepted");
+        ok(PublicInbox::Config::valid_foo_name($s), "`$s' name accepted");
 }
 
 {
diff --git a/t/extindex-psgi.t b/t/extindex-psgi.t
new file mode 100644
index 00000000..6f62b5a0
--- /dev/null
+++ b/t/extindex-psgi.t
@@ -0,0 +1,48 @@
+#!perl -w
+# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+use strict;
+use v5.10.1;
+use PublicInbox::TestCommon;
+use PublicInbox::Config;
+use File::Copy qw(cp);
+use IO::Handle ();
+require_git(2.6);
+require_mods(qw(json DBD::SQLite Search::Xapian
+                HTTP::Request::Common Plack::Test URI::Escape Plack::Builder));
+use_ok($_) for (qw(HTTP::Request::Common Plack::Test));
+require PublicInbox::WWW;
+my ($ro_home, $cfg_path) = setup_public_inboxes;
+my ($tmpdir, $for_destroy) = tmpdir;
+my $home = "$tmpdir/home";
+mkdir $home or BAIL_OUT $!;
+mkdir "$home/.public-inbox" or BAIL_OUT $!;
+my $pi_config = "$home/.public-inbox/config";
+cp("$ro_home/.public-inbox/config", $pi_config) or BAIL_OUT;
+my $env = { HOME => $home };
+run_script([qw(-extindex --all), "$tmpdir/eidx"], $env) or BAIL_OUT;
+{
+        open my $cfgfh, '>', $pi_config or BAIL_OUT;
+        $cfgfh->autoflush(1);
+        print $cfgfh <<EOM or BAIL_OUT;
+[extindex "all"]
+        topdir = $tmpdir/eidx
+        url = http://bogus.example.com/all
+EOM
+}
+my $www = PublicInbox::WWW->new(PublicInbox::Config->new($pi_config));
+my $client = sub {
+        my ($cb) = @_;
+        my $res = $cb->(GET('/all/'));
+        is($res->code, 200, '/all/ good');
+        $res = $cb->(GET('/all/new.atom', Host => 'usethis.example.com'));
+        like($res->content, qr!http://usethis\.example\.com/!s,
+                'Host: header respected in Atom feed');
+        unlike($res->content, qr!http://bogus\.example\.com/!s,
+                'default URL ignored with different host header');
+};
+test_psgi(sub { $www->call(@_) }, $client);
+%$env = (%$env, TMPDIR => $tmpdir, PI_CONFIG => $pi_config);
+test_httpd($env, $client);
+
+done_testing;
diff --git a/t/psgi_v2.t b/t/psgi_v2.t
index 487317b6..1f190708 100644
--- a/t/psgi_v2.t
+++ b/t/psgi_v2.t
@@ -56,27 +56,6 @@ EOF
         close $fh or BAIL_OUT;
 }
 
-my $run_httpd = sub {
-        my ($client, $skip) = @_;
-        SKIP: {
-                require_mods(qw(Plack::Test::ExternalServer), $skip);
-                my $env = { PI_CONFIG => $cfgpath };
-                my $sock = tcp_server() or die;
-                my ($out, $err) = map { "$tmpdir/std$_.log" } qw(out err);
-                my $cmd = [ qw(-httpd -W0), "--stdout=$out", "--stderr=$err" ];
-                my $td = start_script($cmd, $env, { 3 => $sock });
-                my ($h, $p) = tcp_host_port($sock);
-                local $ENV{PLACK_TEST_EXTERNALSERVER_URI} = "http://$h:$p";
-                Plack::Test::ExternalServer::test_psgi(client => $client);
-                $td->join('TERM');
-                open my $fh, '<', $err or BAIL_OUT $!;
-                my $e = do { local $/; <$fh> };
-                if ($e =~ s/^Plack::Middleware::ReverseProxy missing,\n//gms) {
-                        $e =~ s/^URL generation for redirects .*\n//gms;
-                }
-                is($e, '', 'no errors');
-        }
-};
 my $msg = $ibx->msg_by_mid('a-mid@b');
 like($$msg, qr/\AFrom oldbug/s,
         '"From_" line stored to test old bug workaround');
@@ -115,7 +94,8 @@ my $client0 = sub {
                 'new.html ordering is chronological');
 };
 test_psgi(sub { $www->call(@_) }, $client0);
-$run_httpd->($client0, 9);
+my $env = { TMPDIR => $tmpdir, PI_CONFIG => $cfgpath };
+test_httpd($env, $client0, 9);
 
 $eml->header_set('Message-ID', 'a-mid@b');
 $eml->body_set("hello ghosts\n");
@@ -225,7 +205,7 @@ my $client1 = sub {
 };
 
 test_psgi(sub { $www->call(@_) }, $client1);
-$run_httpd->($client1, 38);
+test_httpd($env, $client1, 38);
 
 {
         my $exp = [ qw(<a-mid@b> <reuse@mid>) ];
@@ -267,7 +247,7 @@ my $client2 = sub {
 };
 
 test_psgi(sub { $www->call(@_) }, $client2);
-$run_httpd->($client2, 8);
+test_httpd($env, $client2, 8);
 {
         # ensure conflicted attachments can be resolved
         local $SIG{__WARN__} = sub {};
@@ -298,6 +278,6 @@ my $client3 = sub {
         is_deeply(\@warn, [], 'no warnings on YYYYMMDD only');
 };
 test_psgi(sub { $www->call(@_) }, $client3);
-$run_httpd->($client3, 4);
+test_httpd($env, $client3, 4);
 
 done_testing;