From 2c842608454bd54c6ac0618349e529e5da2c2b5d Mon Sep 17 00:00:00 2001 From: Valentijn Scholten Date: Tue, 10 Mar 2026 20:47:17 +0100 Subject: [PATCH 1/3] feat: allow running single integration tests from dev mode Add integration-tests service with a Docker Compose profile to the dev override, so a single integration test can be run against the running dev stack without switching environments via setEnv.sh. Also ignore the harmless Cross-Origin-Opener-Policy Chrome warning in integration tests (occurs over HTTP) and remove the now-unnecessary DD_SECURE_CROSS_ORIGIN_OPENER_POLICY overrides. Configure logging in the integration test base class so test output is visible. --- docker-compose.override.dev.yml | 18 ++++++++++++++++++ docker-compose.override.integration_tests.yml | 2 -- readme-docs/DOCKER.md | 14 ++++++++++++++ run-integration-test-dev.sh | 16 ++++++++++++++++ tests/base_test_class.py | 12 ++++++++---- 5 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 run-integration-test-dev.sh diff --git a/docker-compose.override.dev.yml b/docker-compose.override.dev.yml index db1da0d9d7a..623d458b2e2 100644 --- a/docker-compose.override.dev.yml +++ b/docker-compose.override.dev.yml @@ -73,3 +73,21 @@ services: mode: host "webhook.endpoint": image: mccutchen/go-httpbin:2.20.0@sha256:b1620821b6ff191d911629f87a720b88df5397c2554045f1cfb1ffde17c9b898 + integration-tests: + profiles: + - integration + build: + context: ./ + dockerfile: ${INTEGRATION_TESTS_DOCKERFILE:-Dockerfile.integration-tests-debian} + image: "defectdojo/defectdojo-integration-tests:${INTEGRATION_TESTS_VERSION:-latest}" + depends_on: + - nginx + - uwsgi + entrypoint: ['/wait-for-it.sh', '${DD_DATABASE_HOST:-postgres}:${DD_DATABASE_PORT:-5432}', '-t', '30', '--', '/app/docker/entrypoint-integration-tests.sh'] + volumes: + - '.:/app:z' + environment: + DD_BASE_URL: 'http://nginx:8080/' + DD_ADMIN_USER: "${DD_ADMIN_USER:-admin}" + DD_ADMIN_PASSWORD: "${DD_ADMIN_PASSWORD:-admin}" + DD_INTEGRATION_TEST_FILENAME: "${DD_INTEGRATION_TEST_FILENAME:-}" diff --git a/docker-compose.override.integration_tests.yml b/docker-compose.override.integration_tests.yml index 24d522f73a0..d45940b24e9 100644 --- a/docker-compose.override.integration_tests.yml +++ b/docker-compose.override.integration_tests.yml @@ -15,7 +15,6 @@ services: environment: PYTHONWARNINGS: error # We are strict about Warnings during testing DD_BASE_URL: 'http://nginx:8080/' - DD_SECURE_CROSS_ORIGIN_OPENER_POLICY: 'None' DD_ADMIN_USER: "${DD_ADMIN_USER:-admin}" DD_ADMIN_PASSWORD: "${DD_ADMIN_PASSWORD:-AdminsLoveIntegrationtests!}" DD_INTEGRATION_TEST_FILENAME: "${DD_INTEGRATION_TEST_FILENAME}" @@ -33,7 +32,6 @@ services: PYTHONWARNINGS: error # We are strict about Warnings during testing DD_DEBUG: 'True' DD_DATABASE_URL: ${DD_TEST_DATABASE_URL:-postgresql://defectdojo:defectdojo@postgres:5432/test_defectdojo} - DD_SECURE_CROSS_ORIGIN_OPENER_POLICY: 'None' DD_SECRET_KEY: "${DD_SECRET_KEY:-.}" DD_EMAIL_URL: "smtp://mailhog:1025" DD_V3_FEATURE_LOCATIONS: ${DD_V3_FEATURE_LOCATIONS:-False} diff --git a/readme-docs/DOCKER.md b/readme-docs/DOCKER.md index 0f9c5bcedf2..c2e63fb425a 100644 --- a/readme-docs/DOCKER.md +++ b/readme-docs/DOCKER.md @@ -353,6 +353,20 @@ Check the logs with: docker compose logs -f integration-tests ``` +### Running a single integration test from dev mode + +If your dev stack is already running (`docker/setEnv.sh dev && docker compose up`), you can run a single integration test without switching environments. +The dev override includes an `integration-tests` service behind a Docker Compose profile, so it won't start during normal `docker compose up`. + +Make sure the dev containers are up and healthy before running the test: + +``` +./run-integration-test-dev.sh tests/finding_test.py +``` + +This spins up the integration test runner container against your running dev stack and tears it down when done. +Note that test data is created in your dev database — the integration tests attempt to clean up after themselves. + # Checking Docker versions Run the following to determine the versions for docker and docker compose: diff --git a/run-integration-test-dev.sh b/run-integration-test-dev.sh new file mode 100644 index 00000000000..cd9927f48eb --- /dev/null +++ b/run-integration-test-dev.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# Run a single integration test against the running dev stack. +# Requires dev mode to be active (./docker/setEnv.sh dev && docker compose up). +# +# Usage: +# ./run-integration-test-dev.sh tests/finding_test.py +# ./run-integration-test-dev.sh tests/risk_acceptance_test.py + +set -e + +TEST_FILE="${1:?Usage: $0 }" + +docker compose --profile integration run --rm --no-deps \ + -e "DD_INTEGRATION_TEST_FILENAME=${TEST_FILE}" \ + -e "LOG_LEVEL=${LOG_LEVEL:-INFO}" \ + integration-tests diff --git a/tests/base_test_class.py b/tests/base_test_class.py index 7850ec3770c..ce4f483ea77 100644 --- a/tests/base_test_class.py +++ b/tests/base_test_class.py @@ -13,6 +13,10 @@ from selenium.webdriver.support.ui import WebDriverWait # import time +logging.basicConfig( + level=os.environ.get("LOG_LEVEL", "WARNING"), + format="%(levelname)s %(name)s: %(message)s", +) logger = logging.getLogger(__name__) @@ -403,7 +407,7 @@ def assertNoConsoleErrors(self): The addition of the trigger exception is due to the Report Builder tests. The addition of the innerHTML exception is due to the test for quick reports in finding_test.py """ - accepted_javascript_messages = r"(zoom\-in\.cur.*)404\ \(Not\ Found\)|Uncaught TypeError: Cannot read properties of null \(reading \'trigger\'\)|Uncaught TypeError: Cannot read properties of null \(reading \'innerHTML\'\)" + accepted_javascript_messages = r"(zoom\-in\.cur.*)404\ \(Not\ Found\)|Uncaught TypeError: Cannot read properties of null \(reading \'trigger\'\)|Uncaught TypeError: Cannot read properties of null \(reading \'innerHTML\'\)|Cross-Origin-Opener-Policy header has been ignored" if entry["level"] == "SEVERE": # TODO: actually this seems to be the previous url @@ -420,12 +424,12 @@ def assertNoConsoleErrors(self): + self.driver.current_url, ) if self.accept_javascript_errors: - logger.warning( + logger.debug( "skipping SEVERE javascript error because accept_javascript_errors is True!", ) elif re.search(accepted_javascript_messages, entry["message"]): - logger.warning( - "skipping javascript errors related to known issues images, see https://github.com/DefectDojo/django-DefectDojo/blob/master/tests/base_test_class.py#L324", + logger.debug( + "skipping javascript errors related to known issues, see https://github.com/DefectDojo/django-DefectDojo/blob/master/tests/base_test_class.py#L324", ) else: self.assertNotEqual(entry["level"], "SEVERE") From 8110ba25fe75f5c5819564b0fcb6daa4b6db98fe Mon Sep 17 00:00:00 2001 From: Valentijn Scholten Date: Tue, 10 Mar 2026 21:29:08 +0100 Subject: [PATCH 2/3] fix: keep DD_SECURE_CROSS_ORIGIN_OPENER_POLICY in integration tests override The base_test_class.py change to ignore the COOP warning is not yet on the bugfix branch, so the full integration test suite still needs this setting to avoid Chrome SEVERE console errors over HTTP. --- docker-compose.override.integration_tests.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-compose.override.integration_tests.yml b/docker-compose.override.integration_tests.yml index d45940b24e9..24d522f73a0 100644 --- a/docker-compose.override.integration_tests.yml +++ b/docker-compose.override.integration_tests.yml @@ -15,6 +15,7 @@ services: environment: PYTHONWARNINGS: error # We are strict about Warnings during testing DD_BASE_URL: 'http://nginx:8080/' + DD_SECURE_CROSS_ORIGIN_OPENER_POLICY: 'None' DD_ADMIN_USER: "${DD_ADMIN_USER:-admin}" DD_ADMIN_PASSWORD: "${DD_ADMIN_PASSWORD:-AdminsLoveIntegrationtests!}" DD_INTEGRATION_TEST_FILENAME: "${DD_INTEGRATION_TEST_FILENAME}" @@ -32,6 +33,7 @@ services: PYTHONWARNINGS: error # We are strict about Warnings during testing DD_DEBUG: 'True' DD_DATABASE_URL: ${DD_TEST_DATABASE_URL:-postgresql://defectdojo:defectdojo@postgres:5432/test_defectdojo} + DD_SECURE_CROSS_ORIGIN_OPENER_POLICY: 'None' DD_SECRET_KEY: "${DD_SECRET_KEY:-.}" DD_EMAIL_URL: "smtp://mailhog:1025" DD_V3_FEATURE_LOCATIONS: ${DD_V3_FEATURE_LOCATIONS:-False} From 21d6275482aca2d0cb40d5ba5bcd1b9928226317 Mon Sep 17 00:00:00 2001 From: Valentijn Scholten Date: Wed, 11 Mar 2026 20:34:14 +0100 Subject: [PATCH 3/3] fix: add executable bit and platform: linux/amd64 for integration-tests - Set executable bit on run-integration-test-dev.sh - Add platform: "linux/amd64" to integration-tests service in both dev and integration_tests overrides (Chromium doesn't work on aarch64) --- docker-compose.override.dev.yml | 1 + docker-compose.override.integration_tests.yml | 1 + run-integration-test-dev.sh | 0 3 files changed, 2 insertions(+) mode change 100644 => 100755 run-integration-test-dev.sh diff --git a/docker-compose.override.dev.yml b/docker-compose.override.dev.yml index 623d458b2e2..0e694ade4d2 100644 --- a/docker-compose.override.dev.yml +++ b/docker-compose.override.dev.yml @@ -74,6 +74,7 @@ services: "webhook.endpoint": image: mccutchen/go-httpbin:2.20.0@sha256:b1620821b6ff191d911629f87a720b88df5397c2554045f1cfb1ffde17c9b898 integration-tests: + platform: "linux/amd64" profiles: - integration build: diff --git a/docker-compose.override.integration_tests.yml b/docker-compose.override.integration_tests.yml index 24d522f73a0..611becefbec 100644 --- a/docker-compose.override.integration_tests.yml +++ b/docker-compose.override.integration_tests.yml @@ -1,6 +1,7 @@ --- services: integration-tests: + platform: "linux/amd64" build: context: ./ dockerfile: ${INTEGRATION_TESTS_DOCKERFILE:-Dockerfile.integration-tests-debian} diff --git a/run-integration-test-dev.sh b/run-integration-test-dev.sh old mode 100644 new mode 100755