Put search_page behind the CAPTCHA wall

This commit is contained in:
swagg boi 2023-10-27 23:16:47 -04:00
parent fd10bb4f4a
commit dd8fdea5e3
3 changed files with 27 additions and 5 deletions

View file

@ -147,7 +147,7 @@ sub startup($self) {
$r->get('/feeds')->to('page#feeds')->name('feeds_page');
# Not-so-static but I mean they're all 'pages' c'mon
$r->get('/search')->to('page#search')->name('search_page');
$human->get('/search')->to('page#search')->name('search_page');
$r->any([qw{GET POST}], '/captcha/*return_url')
->to('page#captcha')

View file

@ -4,14 +4,27 @@ use Test::Mojo;
my $t = Test::Mojo->new('PostText');
my $invalid_query = 'aaaaaaaa' x 300;
my %good_human = (answer => 1, number => '');
my $search_url =
'/captcha/H4sIABJ8PGUAA8soKSmw0tfPyU9OzMnILy6xMjYwMNDPKM1NzNMvTk0sSs4AAPrUR3kiAAAA%0A';
subtest Search => sub {
$t->get_ok('/search')->status_is(200)->text_like(h2 => qr/Search/);
subtest 'Search before CAPTCHA', sub {
$t->get_ok('/human/search')->status_is(302)
->header_like(Location => qr/captcha/);
};
$t->get_ok('/search?q=test')->status_is(200)
subtest 'Search after CAPTCHA', sub {
$t->post_ok($search_url, form => \%good_human)
->status_is(302)
->header_like(Location => qr{human/search});
$t->get_ok('/human/search')->status_is(200)
->text_like(h2 => qr/Search Posts/);
$t->get_ok('/human/search?q=test')->status_is(200)
->text_like(h3 => qr/Results/);
$t->get_ok("/search?q=$invalid_query")->status_is(400)
$t->get_ok("/human/search?q=$invalid_query")->status_is(400)
->text_like(p => qr/Must be between/);
};

View file

@ -1,5 +1,14 @@
% layout 'default';
% title 'Search Posts';
<% content_for open_graph => begin %>
<meta property="og:type" content="website">
<meta property="og:title" content="<%= title %>">
<meta property="og:description" content="Search for posts.">
<% end %>
<% content_for twitter_card => begin %>
<meta name="twitter:title" content="<%= title %>">
<meta name="twitter:description" content="Search for posts.">
<% end %>
<h2 class="page-title"><%= title %></h2>
<form method="get" class="form-body">
<div class="form-field">