diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2c0834163c06dc1086491bbc4ad9e375d98be05c..f526eaa9df978dac0b4e63c253f77c2115d6af9e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -96,4 +96,4 @@ repos: args: ["--config-file=.lint.cfg"] additional_dependencies: - types-requests - - git+https://code.kodo.org.uk/dom/behave-utils.git@v0.2#behave-utils + - behave-utils ~=0.3.2 diff --git a/data/nginx/server.conf b/data/nginx/server.conf index 9fc14f66a8f41dfeb6b483e44c534c8f0d67acc5..48a685a05ab88c436c46d1863d26086e9aebefba 100644 --- a/data/nginx/server.conf +++ b/data/nginx/server.conf @@ -49,11 +49,6 @@ server { access_log off; } - # Don't return 200 for a missing favicon - location = /favicon.ico { - try_files favicon.ico =404; - } - # Don't delegate to index.php for /.well-known/ # If a plugin wants to handle /.well-known/ URIs please submit an issue to # https://code.kodo.org.uk/singing-chimes.co.uk/wordpress/ diff --git a/tests/regression-20.feature b/tests/regression-20.feature new file mode 100644 index 0000000000000000000000000000000000000000..56a020c61b55fcd69d2b7ebf1c7524cb4fa0f660 --- /dev/null +++ b/tests/regression-20.feature @@ -0,0 +1,15 @@ +Feature: Return favicons when requests + Regression check for "#20": Fix/remove favicon.ico intercept in Nginx + + An icon should always be served when requesting "/favicon.ico", either one + added by the owner, or a default icon. + + Scenario: Default icon + When /favicon.ico is requested + Then 302 is returned + And the "Location" header's value is "http://test.example.com/wp-includes/images/w-logo-blue-white-bg.png" + + Scenario: Owner supplied icon + Given /app/static/favicon.ico exists in the frontend + When /favicon.ico is requested + Then 200 is returned diff --git a/tests/requirements.txt b/tests/requirements.txt index 92918748e901ed983ad642e4407727c2d6058545..bb41f9e7b4c6a446ef3f5b5105e5181b28bea9ac 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,5 +1,5 @@ Python ~=3.9; python_version < '3.9' behave -git+https://code.kodo.org.uk/dom/behave-utils.git@v0.2#behave-utils +behave-utils ~=0.3.2 requests ~=2.26 diff --git a/tests/steps/request_steps.py b/tests/steps/request_steps.py index 6238f6ef9a3b8d253644e5e388f78fb269e5d611..211c4d4f20c4a7bfd79d4ac85f176c9d437d8f0e 100644 --- a/tests/steps/request_steps.py +++ b/tests/steps/request_steps.py @@ -1,4 +1,4 @@ -# Copyright 2021 Dominik Sekotill +# Copyright 2021-2022 Dominik Sekotill # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this @@ -19,6 +19,8 @@ from behave.runner import Context from behave_utils import URL from behave_utils import PatternEnum +SAMPLE_SITE_NAME = "http://test.example.com" + class Method(PatternEnum): """ @@ -120,6 +122,8 @@ def assert_header(context: Context, header_name: str, header_value: str) -> None """ Assert that an expected header was received during a previous step """ + if SAMPLE_SITE_NAME in header_value: + header_value = header_value.replace(SAMPLE_SITE_NAME, context.site.url) headers = context.response.headers assert header_name in headers, \ f"Expected header not found in response: {header_name!r}" diff --git a/tests/steps/static.py b/tests/steps/static.py new file mode 100644 index 0000000000000000000000000000000000000000..b64dbe85e8af0bc54f8bb3a2ddac347c9601a57e --- /dev/null +++ b/tests/steps/static.py @@ -0,0 +1,39 @@ +# Copyright 2022 Dominik Sekotill +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +""" +Step implementations involving creating files in containers +""" + +from __future__ import annotations + +from typing import Iterator + +from behave import fixture +from behave import given +from behave import use_fixture +from behave.runner import Context +from behave_utils.docker import Cli + + +@given("{path} exists in the {container}") +def step_impl(context: Context, path: str, container: str) -> None: + """ + Create a file in the named container + """ + use_fixture(container_file, context, path, container) + + +@fixture +def container_file(context: Context, path: str, container_name: str) -> Iterator[None]: + """ + Create a file in a named container as a fixture + """ + container = getattr(context.site, container_name) + run = Cli(container) + run("tee", path, input=getattr(context, "text", "This is a data file!")) + yield + run("rm", path)