Verified Commit 7a0e602a authored by Luc Didry's avatar Luc Didry

Add ability to respond to /robots.txt either by sending the file if it exists or by answering 404

parent 17eb13d9
Pipeline #52227 passed with stages
in 9 minutes 9 seconds
......@@ -10,6 +10,8 @@ lstu.conf
script/hypnotoad.pid
.zanata-cache/*
themes/*
themes/default/public/robots.txt
themes/milligram/public/robots.txt
!themes/default
!themes/default/*
!themes/milligram
......
Revision history for Perl application Lstu
0.17-2 2018-05-15
- Add ability to respond to /robots.txt either by sending the file if it exists or by answering 404
0.17-1 2018-04-28
- Fix bug in making LDAP and Htpasswd dependencies optional
......
......@@ -153,6 +153,15 @@ sub get {
my $c = shift;
my $short = $c->param('short');
if (defined($c->stash('format')) && $short eq 'robots' && $c->stash('format') eq 'txt') {
if ($c->app->static->file('robots.txt')) {
$c->res->headers->content_type('text/plain');
return $c->reply->static('robots.txt');
} else {
return $c->reply->not_found;
}
}
my $url;
if (scalar(@{$c->config('memcached_servers')})) {
$url = $c->chi('lstu_urls_cache')->compute($short, undef, sub {
......
......@@ -57,6 +57,13 @@ $t->get_ok('/')
->header_is('Content-Security-Policy' => "base-uri 'self'; default-src 'none'; font-src 'self'; form-action 'self'; frame-ancestors 'none'; img-src 'self' data:; script-src 'self'; style-src 'self'")
->content_like(qr/Lstu/i);
# Test robots.txt
$t->get_ok('/robots.txt')
->status_is(404);
$t->get_ok('/robots')
->status_is(404);
# Create short URL
$t->post_ok('/a' => form => { lsturl => 'https://lstu.fr', format => 'json' })
->status_is(200)
......@@ -68,8 +75,23 @@ $t->post_ok('/a' => form => { lsturl => 'https://lstu.fr', format => 'json' })
$t->post_ok('/a' => form => { lsturl => 'http://lstupiioqgxmq66f.onion', 'lsturl-custom' => 'onion', format => 'json' })
->status_is(200)
->json_has('url', 'short', 'success', 'qrcode')
->json_is('/success' => true, '/url' => 'https://lstu.fr', '/short' => 'http://127.0.0.1/onion');
->json_is('/success' => true, '/url' => 'https://lstupiioqgxmq66f.onion', '/short' => 'http://127.0.0.1/onion');
Lstu::DB::Ban->new(app => $m)->delete_all; # prevents ban
# Create short URL with robots custom short
$t->post_ok('/a' => form => { lsturl => 'http://robots-txt.com/', 'lsturl-custom' => 'robots', format => 'json' })
->status_is(200)
->json_has('url', 'short', 'success', 'qrcode')
->json_is('/success' => true, '/url' => 'https://lstu.fr', '/short' => 'http://127.0.0.1/robots');
# Test robots.txt even after creating a robots short URL
$t->get_ok('/robots.txt')
->status_is(404);
$t->get_ok('/robots')
->status_is(301);
# Create short URL, with invalid argument
# Create short URL, with invalid argument
$t->post_ok('/a' => form => { lsturl => 'truc', format => 'json' })
->status_is(200)
......@@ -117,7 +139,7 @@ $t->get_ok('/stats'.$short.'i')
$t->get_ok('/fullstats')
->status_is(200)
->json_has('urls', 'empty', 'timestamp')
->json_is('/urls' => 2)
->json_is('/urls' => 3)
->json_like('/empty' => qr#\d+#, '/timestamp' => qr#[0-9]{10}#);
# Needed if we use Minion for increasing counters
......
......@@ -226,7 +226,7 @@ msgid "The URL you want to shorten comes from a domain (%1) that is blacklisted
msgstr ""
#. ($c->url_for('/')
#: lib/Lstu/Controller/Admin.pm:134 lib/Lstu/Controller/Stats.pm:184 lib/Lstu/Controller/URL.pm:195
#: lib/Lstu/Controller/Admin.pm:134 lib/Lstu/Controller/Stats.pm:184 lib/Lstu/Controller/URL.pm:204
msgid "The shortened URL %1 doesn't exist."
msgstr ""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment