1 # Copyright (C) 2017-2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
7 use PublicInbox::Config;
8 use PublicInbox::Inbox;
9 use PublicInbox::InboxWritable;
10 use bytes (); # only for bytes::length
11 use PublicInbox::TestCommon;
12 my @mods = qw(DBD::SQLite Search::Xapian HTTP::Request::Common Plack::Test
13 URI::Escape Plack::Builder);
15 use_ok($_) for (qw(HTTP::Request::Common Plack::Test));
16 use_ok 'PublicInbox::WWW';
17 my ($tmpdir, $for_destroy) = tmpdir();
19 my $ibx = PublicInbox::Inbox->new({
21 address => 'git@vger.kernel.org',
24 $ibx = PublicInbox::InboxWritable->new($ibx);
26 my $im = $ibx->importer(0);
27 my $digits = '10010260936330';
28 my $ua = 'Pine.LNX.4.10';
29 my $mid = "$ua.$digits.2460-100000\@penguin.transmeta.com";
33 From: Ævar Arnfjörð Bjarmason <avarab\@example>
34 To: git\@vger.kernel.org
38 my $mime = Email::MIME->new(\$data);
41 PublicInbox::SearchIdx->new($ibx, 1)->index_sync;
43 my $cfgpfx = "publicinbox.test";
44 my $config = PublicInbox::Config->new(\<<EOF);
45 $cfgpfx.address=git\@vger.kernel.org
46 $cfgpfx.inboxdir=$tmpdir
48 my $www = PublicInbox::WWW->new($config);
49 test_psgi(sub { $www->call(@_) }, sub {
52 $res = $cb->(GET('/test/?q=%C3%86var'));
53 my $html = $res->content;
54 like($html, qr/<title>Ævar - /, 'HTML escaped in title');
55 my @res = ($html =~ m/\?q=(.+var)\b/g);
56 ok(scalar(@res), 'saw query strings');
57 my %uniq = map { $_ => 1 } @res;
58 is(1, scalar keys %uniq, 'all query values identical in HTML');
59 is('%C3%86var', (keys %uniq)[0], 'matches original query');
60 ok(index($html, 'by Ævar Arnfjörð Bjarmason') >= 0,
61 "displayed Ævar's name properly in HTML");
64 local $SIG{__WARN__} = sub { push @$warn, @_ };
65 $res = $cb->(GET('/test/?q=s:test&l=5e'));
66 is($res->code, 200, 'successful search result');
67 is_deeply([], $warn, 'no warnings from non-numeric comparison');
69 $res = $cb->(POST('/test/?q=s:bogus&x=m'));
70 is($res->code, 404, 'failed search result gives 404');
71 is_deeply([], $warn, 'no warnings');
73 my $mid_re = qr/\Q$mid\E/o;
74 while (length($digits) > 8) {
75 $res = $cb->(GET("/test/$ua.$digits/"));
76 is($res->code, 300, 'partial match found while truncated');
77 like($res->content, qr/\b1 partial match found\b/);
78 like($res->content, $mid_re, 'found mid in response');