mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-07-11 00:08:03 -04:00
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.
This commit is contained in:
39
.github/workflows/run-all-tests.yml
vendored
39
.github/workflows/run-all-tests.yml
vendored
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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']")
|
||||
|
||||
Reference in New Issue
Block a user