From 10b35d81f33d08fcde37b5838f5d912ee0bfe641 Mon Sep 17 00:00:00 2001 From: Dom Sekotill Date: Fri, 21 Oct 2022 01:55:34 +0100 Subject: [PATCH 1/2] Add regression test for #20 --- .pre-commit-config.yaml | 2 +- tests/regression-20.feature | 15 ++++++++++++++ tests/requirements.txt | 2 +- tests/steps/request_steps.py | 6 +++++- tests/steps/static.py | 39 ++++++++++++++++++++++++++++++++++++ 5 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 tests/regression-20.feature create mode 100644 tests/steps/static.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2c08341..f526eaa 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/tests/regression-20.feature b/tests/regression-20.feature new file mode 100644 index 0000000..56a020c --- /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 9291874..bb41f9e 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 6238f6e..211c4d4 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 0000000..b64dbe8 --- /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) -- GitLab From f9252dae2e1d68dbcfbc5a293c62d11b4b8225fa Mon Sep 17 00:00:00 2001 From: Dom Sekotill Date: Fri, 21 Oct 2022 02:11:02 +0100 Subject: [PATCH 2/2] Remove favicon intercept from Nginx config --- data/nginx/server.conf | 5 ----- 1 file changed, 5 deletions(-) diff --git a/data/nginx/server.conf b/data/nginx/server.conf index 9fc14f6..48a685a 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/ -- GitLab