From 495698c6c2d5e02f4a1056e86e846775e219d7bf Mon Sep 17 00:00:00 2001 From: "Jokob @NetAlertX" <96159884+jokob-sk@users.noreply.github.com> Date: Wed, 1 Jul 2026 05:54:05 +0000 Subject: [PATCH] Update test suite configuration and enhance test assertions - Changed the test suite name for clarity. - Updated default behavior for running all tests in the workflow. - Improved logging in the Docker test script for better debugging. - Modified assertions in Nginx proxy security tests to ensure access is not blocked. - Added exception handling in UI tests to skip tests when elements are not found. --- .github/workflows/run-all-tests.yml | 39 ++++++++++++++----- scripts/run_tests_in_docker_environment.sh | 1 + .../test_nginx_proxy_security.py | 11 +++--- test/ui/test_ui_maintenance.py | 2 + test/ui/test_ui_waits.py | 3 +- 5 files changed, 40 insertions(+), 16 deletions(-) diff --git a/.github/workflows/run-all-tests.yml b/.github/workflows/run-all-tests.yml index 83feea36..a68bbde7 100644 --- a/.github/workflows/run-all-tests.yml +++ b/.github/workflows/run-all-tests.yml @@ -1,12 +1,15 @@ -name: ๐Ÿงช Manual Test Suite Selector +name: ๐Ÿงช Test Suite on: + pull_request: + branches: + - main workflow_dispatch: inputs: run_all: description: 'โœ… Run ALL tests (overrides individual selectors)' type: boolean - default: false + default: true run_scan: description: '๐Ÿ“‚ scan/ (Scan, Logic, Locks, IPs)' type: boolean @@ -48,25 +51,41 @@ jobs: - name: Build Test Path Command id: builder + env: + INPUT_EVENT_NAME: ${{ github.event_name }} + INPUT_RUN_ALL: ${{ github.event.inputs.run_all }} + INPUT_RUN_SCAN: ${{ github.event.inputs.run_scan }} + INPUT_RUN_API: ${{ github.event.inputs.run_api }} + INPUT_RUN_BACKEND: ${{ github.event.inputs.run_backend }} + INPUT_RUN_DOCKER_ENV: ${{ github.event.inputs.run_docker_env }} + INPUT_RUN_UI: ${{ github.event.inputs.run_ui }} + INPUT_RUN_PLUGINS: ${{ github.event.inputs.run_plugins }} + INPUT_RUN_ROOT_FILES: ${{ github.event.inputs.run_root_files }} run: | PATHS="" + # Always run all tests on pull_request events + if [ "$INPUT_EVENT_NAME" == "pull_request" ]; then + echo "final_paths=test/" >> $GITHUB_OUTPUT + exit 0 + fi + # run_all overrides everything - if [ "${{ github.event.inputs.run_all }}" == "true" ]; then + if [ "$INPUT_RUN_ALL" == "true" ]; then echo "final_paths=test/" >> $GITHUB_OUTPUT exit 0 fi # Folder Mapping with 'test/' prefix - if [ "${{ github.event.inputs.run_scan }}" == "true" ]; then PATHS="$PATHS test/scan/"; fi - if [ "${{ github.event.inputs.run_api }}" == "true" ]; then PATHS="$PATHS test/api_endpoints/ test/server/"; fi - if [ "${{ github.event.inputs.run_backend }}" == "true" ]; then PATHS="$PATHS test/backend/ test/db/"; fi - if [ "${{ github.event.inputs.run_docker_env }}" == "true" ]; then PATHS="$PATHS test/docker_tests/"; fi - if [ "${{ github.event.inputs.run_ui }}" == "true" ]; then PATHS="$PATHS test/ui/"; fi - if [ "${{ github.event.inputs.run_plugins }}" == "true" ]; then PATHS="$PATHS test/plugins/"; fi + if [ "$INPUT_RUN_SCAN" == "true" ]; then PATHS="$PATHS test/scan/"; fi + if [ "$INPUT_RUN_API" == "true" ]; then PATHS="$PATHS test/api_endpoints/ test/server/"; fi + if [ "$INPUT_RUN_BACKEND" == "true" ]; then PATHS="$PATHS test/backend/ test/db/"; fi + if [ "$INPUT_RUN_DOCKER_ENV" == "true" ]; then PATHS="$PATHS test/docker_tests/"; fi + if [ "$INPUT_RUN_UI" == "true" ]; then PATHS="$PATHS test/ui/"; fi + if [ "$INPUT_RUN_PLUGINS" == "true" ]; then PATHS="$PATHS test/plugins/"; fi # Root Files Mapping (files sitting directly in /test/) - if [ "${{ github.event.inputs.run_root_files }}" == "true" ]; then + if [ "$INPUT_RUN_ROOT_FILES" == "true" ]; then PATHS="$PATHS test/test_device_atomicity.py test/test_mcp_disablement.py test/test_plugin_helper.py test/test_wol_validation.py" fi diff --git a/scripts/run_tests_in_docker_environment.sh b/scripts/run_tests_in_docker_environment.sh index 02249bc9..22711452 100755 --- a/scripts/run_tests_in_docker_environment.sh +++ b/scripts/run_tests_in_docker_environment.sh @@ -81,6 +81,7 @@ for i in $(seq 1 $BACKEND_WAIT); do fi if [ "$i" -eq "$BACKEND_WAIT" ]; then echo "--- Warning: Flask backend did not become ready after $BACKEND_WAIT seconds, proceeding anyway ---" + docker logs netalertx-test-container fi echo " ... waiting for backend ($i/$BACKEND_WAIT)" sleep 1 diff --git a/test/api_endpoints/test_nginx_proxy_security.py b/test/api_endpoints/test_nginx_proxy_security.py index 8cd6656e..7b148935 100644 --- a/test/api_endpoints/test_nginx_proxy_security.py +++ b/test/api_endpoints/test_nginx_proxy_security.py @@ -31,8 +31,8 @@ def test_nginx_proxy_security_modern_check(): print("Response body:") print(response.text) - assert response.status_code in [200, 401, 404, 500, 502], ( - f"Expected access allowed, got {response.status_code}" + assert response.status_code != 403, ( + f"Expected access not blocked by Nginx, got {response.status_code}" ) except requests.exceptions.ConnectionError: @@ -50,7 +50,7 @@ def test_nginx_proxy_security_legacy_check(): } try: response = http_get(BASE_URL, headers=headers) - assert response.status_code in [200, 401, 404, 500, 502], f"Expected access allowed, got {response.status_code}" + assert response.status_code != 403, f"Expected access not blocked by Nginx, got {response.status_code}" except requests.exceptions.ConnectionError: pytest.fail("Could not connect to Nginx. Is it running?") @@ -122,7 +122,7 @@ def test_nginx_proxy_security_legacy_protocol_agnostic(): """ headers = {"Referer": f"https://localhost:{PORT}/path"} response = http_get(BASE_URL, headers=headers) - assert response.status_code in [200, 401, 404, 500, 502] + assert response.status_code != 403, f"Expected access not blocked by Nginx, got {response.status_code}" def test_nginx_proxy_security_block_server_docs(): @@ -140,7 +140,8 @@ def test_nginx_proxy_security_block_server_docs(): def test_nginx_proxy_security_allow_port(): """ - Test that access to `:20212/docs` is allowed by Nginx (should return 200). + Test that the backend port (20212) is directly reachable without Nginx security filtering. + 200 indicates a healthy backend; 500 indicates the backend is reachable but returned an error. """ headers = {"Referer": f"https://localhost:{BACKEND_PORT}/path"} url = f"http://localhost:{BACKEND_PORT}/docs" diff --git a/test/ui/test_ui_maintenance.py b/test/ui/test_ui_maintenance.py index e5da50cb..0259b45a 100644 --- a/test/ui/test_ui_maintenance.py +++ b/test/ui/test_ui_maintenance.py @@ -91,6 +91,8 @@ def test_export_csv_button_works(driver): # Best-effort page source check; skip if alert already consumed the state try: assert "error" not in driver.page_source.lower(), "Button click should not cause errors" + except AssertionError: + raise except Exception: pass # Can't reliably check page source after alert dismissal except Exception as e: diff --git a/test/ui/test_ui_waits.py b/test/ui/test_ui_waits.py index 3dafcb21..95e19253 100644 --- a/test/ui/test_ui_waits.py +++ b/test/ui/test_ui_waits.py @@ -5,6 +5,7 @@ Basic verification tests for wait helpers used by UI tests. import sys import os +import pytest from selenium.webdriver.common.by import By # Add test directory to path @@ -52,7 +53,7 @@ def test_wait_for_input_value_on_devices(driver): wait_for_element_by_css(driver, "#NEWDEV_devMac", timeout=10) except Exception: # Element still not found after direct navigation โ€” skip the rest of the test - return + pytest.skip("NEWDEV_devMac element not found after direct navigation") # Attempt to click the generate control if present gen_buttons = driver.find_elements(By.CSS_SELECTOR, "span[onclick*='generate_NEWDEV_devMac']")