From 09876532ae2ad6ab9ba794c0e0ef91debb4721b5 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 29 Aug 2018 15:41:53 +0100 Subject: [PATCH] Serve robots.txt from the admin app MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We’re getting rid of the PaaS proxy, which is where this file is currently served from. Values copied from https://github.com/alphagov/notifications-aws/blob/3632313fdfa7583cbb3a1c644aebcee080841f97/ansible/roles/nginx/files/robots.txt --- app/main/views/index.py | 11 +++++++++++ app/navigation.py | 4 ++++ tests/app/main/views/test_index.py | 14 ++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/app/main/views/index.py b/app/main/views/index.py index ed07c2a15..183dfee32 100644 --- a/app/main/views/index.py +++ b/app/main/views/index.py @@ -26,6 +26,17 @@ def index(): return render_template('views/signedout.html') +@main.route('/robots.txt') +def robots(): + return ( + 'User-agent: *\n' + 'Disallow: /sign-in\n' + 'Disallow: /support\n' + 'Disallow: /support/\n' + 'Disallow: /register\n' + ), 200, {'Content-Type': 'text/plain'} + + @main.route('/error/') def error(status_code): if status_code >= 500: diff --git a/app/navigation.py b/app/navigation.py index ee9b574c8..022a8d204 100644 --- a/app/navigation.py +++ b/app/navigation.py @@ -194,6 +194,7 @@ class HeaderNavigation(Navigation): 'resend_email_verification', 'resume_service', 'revoke_api_key', + 'robots', 'send_messages', 'send_notification', 'send_one_off', @@ -451,6 +452,7 @@ class MainNavigation(Navigation): 'resend_email_verification', 'resume_service', 'roadmap', + 'robots', 'security', 'send_notification', 'service_dashboard_updates', @@ -638,6 +640,7 @@ class CaseworkNavigation(Navigation): 'resume_service', 'revoke_api_key', 'roadmap', + 'robots', 'security', 'send_messages', 'send_notification', @@ -859,6 +862,7 @@ class OrgNavigation(Navigation): 'resume_service', 'revoke_api_key', 'roadmap', + 'robots', 'security', 'send_messages', 'send_notification', diff --git a/tests/app/main/views/test_index.py b/tests/app/main/views/test_index.py index 17f5ad7c7..1795dece3 100644 --- a/tests/app/main/views/test_index.py +++ b/tests/app/main/views/test_index.py @@ -40,6 +40,20 @@ def test_logged_in_user_redirects_to_choose_account( assert response.location == url_for('main.choose_account', _external=True) +def test_robots(client): + assert url_for('main.robots') == '/robots.txt' + response = client.get(url_for('main.robots')) + assert response.headers['Content-Type'] == 'text/plain' + assert response.status_code == 200 + assert response.get_data(as_text=True) == ( + 'User-agent: *\n' + 'Disallow: /sign-in\n' + 'Disallow: /support\n' + 'Disallow: /support/\n' + 'Disallow: /register\n' + ) + + @pytest.mark.parametrize('view', [ 'cookies', 'privacy', 'using_notify', 'pricing', 'terms', 'integration_testing', 'roadmap', 'features', 'callbacks', 'documentation', 'security'