about summary refs log tree commit homepage
path: root/lib/PublicInbox
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2022-08-26 10:15:45 +0000
committerEric Wong <e@80x24.org>2022-08-26 18:10:30 +0000
commit81ea7f0100f016ad8c66605b49230e876a1eb82d (patch)
treea65529a4aaa1fa9abc0b7d09ef6f151ccd7ebe4c /lib/PublicInbox
parentf2ee1e5f1c36afee3bf80e42e9c5f3196dded34f (diff)
downloadpublic-inbox-81ea7f0100f016ad8c66605b49230e876a1eb82d.tar.gz
Unindexed v1 inboxes were leaving $smsg objects unpopulated when
using public-inbox-httpd (but not generic PSGI servers) and
causing missing HTML content and uninitialized value warnings.

Our existing tests for unindexed v1 inboxes only assumed generic
PSGI servers and synchronous blob retrieval.  Due to changes
several years ago to make git blob retrieval async for slow
storage using public-inbox-httpd, our tests were insufficient to
detect this regression.

So ensure $smsg->populate runs in a few places and rewrite
t/plack.t to test against both generic PSGI and -httpd
implementations.

Fortunately, unindexed v1 inboxes are uncommon, and this
bug was only (finally) discovered while developing other
features.

For ensuring we can test (and not blindly follow) redirects with
-httpd, we now provide our own LWP::UserAgent (used internally
by Plack::Test::ExternalServer) with redirect following
disabled to P:T:ES::test_psgi.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/Feed.pm5
-rw-r--r--lib/PublicInbox/TestCommon.pm8
-rw-r--r--lib/PublicInbox/WwwAtomStream.pm1
3 files changed, 11 insertions, 3 deletions
diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm
index ee579f6d..e0810420 100644
--- a/lib/PublicInbox/Feed.pm
+++ b/lib/PublicInbox/Feed.pm
@@ -51,7 +51,10 @@ sub new_html_i {
         my ($ctx, $eml) = @_;
         $ctx->zmore($ctx->html_top) if exists $ctx->{-html_tip};
 
-        $eml and return PublicInbox::View::eml_entry($ctx, $eml);
+        if ($eml) {
+                $ctx->{smsg}->populate($eml) if !$ctx->{ibx}->{over};
+                return PublicInbox::View::eml_entry($ctx, $eml);
+        }
         my $smsg = shift @{$ctx->{msgs}} or
                 $ctx->zmore(PublicInbox::View::pagination_footer(
                                                 $ctx, './new.html'));
diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index 04adede0..55d82fc0 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -740,14 +740,18 @@ sub test_httpd ($$;$) {
                 $env->{$_} or BAIL_OUT "$_ unset";
         }
         SKIP: {
-                require_mods(qw(Plack::Test::ExternalServer), $skip // 1);
+                require_mods(qw(Plack::Test::ExternalServer LWP::UserAgent),
+                                $skip // 1);
                 my $sock = tcp_server() or die;
                 my ($out, $err) = map { "$env->{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);
+                my $ua = LWP::UserAgent->new;
+                $ua->max_redirect(0);
+                Plack::Test::ExternalServer::test_psgi(client => $client,
+                                                        ua => $ua);
                 $td->join('TERM');
                 open my $fh, '<', $err or BAIL_OUT $!;
                 my $e = do { local $/; <$fh> };
diff --git a/lib/PublicInbox/WwwAtomStream.pm b/lib/PublicInbox/WwwAtomStream.pm
index 82895db6..7b7047ac 100644
--- a/lib/PublicInbox/WwwAtomStream.pm
+++ b/lib/PublicInbox/WwwAtomStream.pm
@@ -38,6 +38,7 @@ sub async_next ($) {
 sub async_eml { # for async_blob_cb
         my ($ctx, $eml) = @_;
         my $smsg = delete $ctx->{smsg};
+        $smsg->{mid} // $smsg->populate($eml);
         $ctx->write(feed_entry($ctx, $smsg, $eml));
 }