From 3332a53d6d26d39783f79a4e39c4487ffa712a80 Mon Sep 17 00:00:00 2001 From: OpenClaw Bot Date: Sat, 30 May 2026 12:08:00 +0000 Subject: [PATCH 1/5] docs(openspec): specify issue 46 CI split --- .../released-mock-ci-coverage/proposal.md | 40 ++++++++++++ .../released-mock-ci-coverage/tasks.md | 30 +++++++++ .../specs/released-mock-ci-coverage/spec.md | 65 +++++++++++++++++++ 3 files changed, 135 insertions(+) create mode 100644 openspec/changes/released-mock-ci-coverage/proposal.md create mode 100644 openspec/changes/released-mock-ci-coverage/tasks.md create mode 100644 openspec/specs/released-mock-ci-coverage/spec.md diff --git a/openspec/changes/released-mock-ci-coverage/proposal.md b/openspec/changes/released-mock-ci-coverage/proposal.md new file mode 100644 index 0000000..4ae74d0 --- /dev/null +++ b/openspec/changes/released-mock-ci-coverage/proposal.md @@ -0,0 +1,40 @@ +## Why + +Issue #46 calls out two problems in the current CI split. + +First, the mock-backed check is not deterministic enough because it pulls a +floating `ghcr.io/clawosiris/openvas-mock-scanner:latest` image. That means a +`scan-examples` pull request can fail because the mock server changed out from +under it, not because the repository itself regressed. + +Second, the current mock coverage is too shallow. The existing smoke test only +exercises the `success-basic` path and does not validate the more realistic +result shapes that matter to this repository, especially the feed-derived +metadata and result payload structure the real scan path already relies on. + +At the same time, the real scan remains the highest-value compatibility signal, +but it is too expensive to run as the default short-path gate for every quick +iteration. + +## What Changes + +- Replace the floating mock image dependency with a released + `openvas-mock-scanner` artifact identified by a stable version tag or digest. +- Expand mock-backed validation beyond a basic liveness check by adding + compatibility tests that use realistic data derived from the Greenbone feed + inputs already used by the real scan flow. +- Keep mock-backed validation as the default fast gate for short-lived and + general pull requests. +- Run the real scan path in addition to the mock-backed checks for pull requests + targeting `main` and for release-oriented validation flows. +- Document the CI split so contributors understand which paths are expected to + run for quick validation versus higher-cost release confidence. + +## Impact + +- CI becomes more reproducible because the mock dependency stops drifting with a + floating tag. +- Mock validation becomes a meaningful compatibility test instead of only a + container smoke check. +- Heavyweight real-scan coverage is preserved where it matters most without + forcing every short-lived PR to pay that cost. diff --git a/openspec/changes/released-mock-ci-coverage/tasks.md b/openspec/changes/released-mock-ci-coverage/tasks.md new file mode 100644 index 0000000..1094f63 --- /dev/null +++ b/openspec/changes/released-mock-ci-coverage/tasks.md @@ -0,0 +1,30 @@ +## 1. Mock artifact policy + +- [ ] 1.1 Replace the floating mock image reference with a released + `openvas-mock-scanner` version tag or digest. +- [ ] 1.2 Document how the chosen mock release is selected and updated. + +## 2. Higher-value mock compatibility coverage + +- [ ] 2.1 Add mock-backed tests that use realistic feed-derived data rather than + only the `success-basic` path. +- [ ] 2.2 Cover the client/result behaviors that matter to this repository, such + as metadata lookup expectations, result payload shape, and larger or + paged result handling when applicable. +- [ ] 2.3 Keep the mock-backed path fast enough to remain the default short-path + CI gate. + +## 3. Real-scan gating policy + +- [ ] 3.1 Run real-scan validation in addition to the mock-backed path for pull + requests targeting `main`. +- [ ] 3.2 Run real-scan validation in addition to the mock-backed path for + release validation flows. +- [ ] 3.3 Ensure general PRs and short-lived iteration paths continue to use the + fast mock-backed validation by default. + +## 4. Verification + +- [ ] 4.1 Add or update tests for the new mock compatibility coverage. +- [ ] 4.2 Update CI/workflow documentation to describe the fast-path and + high-signal-path split. diff --git a/openspec/specs/released-mock-ci-coverage/spec.md b/openspec/specs/released-mock-ci-coverage/spec.md new file mode 100644 index 0000000..02129aa --- /dev/null +++ b/openspec/specs/released-mock-ci-coverage/spec.md @@ -0,0 +1,65 @@ +## ADDED Requirements + +### Requirement: Released mock-server artifact for fast validation +The repository SHALL use a released `openvas-mock-scanner` artifact for +mock-backed CI validation instead of a floating image tag. + +#### Scenario: Mock-backed CI uses a stable released artifact +- **GIVEN** the repository runs mock-backed compatibility checks in CI +- **WHEN** the workflow resolves the mock-server image to run +- **THEN** it uses a stable released artifact identified by version tag, digest, + or another reproducible release reference +- **AND** it does not use an unqualified moving `:latest` tag +- **AND** the selected artifact is documented so future updates are intentional. + +### Requirement: Feed-derived mock compatibility coverage +The repository SHALL validate its mock-backed scan workflow using realistic +data derived from the Greenbone feed inputs already used by the real scan path. + +#### Scenario: Mock tests use realistic feed-derived result data +- **GIVEN** the repository already uses Greenbone feed data as part of the real + scan flow +- **WHEN** mock-backed compatibility tests are prepared +- **THEN** the test data is generated from or derived from those existing feed + inputs instead of relying only on a trivial canned happy-path payload +- **AND** the resulting test cases reflect realistic OIDs, metadata, and result + structures that `scan_examples` is expected to consume. + +#### Scenario: Mock tests validate client-relevant result handling +- **GIVEN** the mock-backed compatibility tests run against the released mock + server artifact +- **WHEN** the repository exercises the scan lifecycle and result retrieval path +- **THEN** the tests verify the behaviors this repository depends on, including + result parsing, feed-derived metadata expectations, and larger or paged + result handling where applicable +- **AND** the mock-backed path remains fast enough to serve as the default + short-path CI gate. + +### Requirement: Real-scan coverage for high-signal branches and releases +The repository SHALL keep the heavyweight real-scan path in CI for pull +requests targeting `main` and for release-oriented validation flows, in +addition to the fast mock-backed checks. + +#### Scenario: PR to main runs both fast and heavyweight validation +- **GIVEN** a pull request targets the `main` branch +- **WHEN** the repository CI runs for that pull request +- **THEN** it runs the fast mock-backed validation path +- **AND** it also runs the real-scan validation path +- **AND** the real-scan path is not the only validation signal for that pull + request. + +#### Scenario: Release validation runs both fast and heavyweight validation +- **GIVEN** a release workflow or release-oriented pull request is validated +- **WHEN** the repository CI runs for that release validation path +- **THEN** it runs the fast mock-backed validation path +- **AND** it also runs the real-scan validation path +- **AND** the release signal reflects both deterministic mock compatibility and + the real scanner integration. + +#### Scenario: General pull requests keep the fast validation default +- **GIVEN** a general pull request or short-lived iteration path that does not + target `main` and is not a release validation flow +- **WHEN** CI runs +- **THEN** the fast mock-backed validation path is the default scanner-facing + gate +- **AND** the heavyweight real-scan path is not required for every such run. From 5c119c33664cd81ed51816109187fde85112c498 Mon Sep 17 00:00:00 2001 From: OpenClaw Bot Date: Sat, 30 May 2026 12:18:14 +0000 Subject: [PATCH 2/5] Use released mock scanner for CI --- .github/workflows/tests.yml | 11 +- README.md | 22 ++- .../released-mock-ci-coverage/tasks.md | 20 +-- src/scan_examples/client.py | 23 ++- tests/data/mock-feed/notus-advisories.json | 21 +++ tests/data/mock-feed/scap-cves.json | 18 +++ tests/data/mock-feed/target-profile.json | 67 +++++++++ tests/data/mock-feed/vt-metadata.json | 68 +++++++++ tests/test_client.py | 45 ++++++ tests/test_compose_feed_sync.py | 19 +++ tests/test_mock_server_smoke.py | 138 +++++++++++++++++- 11 files changed, 427 insertions(+), 25 deletions(-) create mode 100644 tests/data/mock-feed/notus-advisories.json create mode 100644 tests/data/mock-feed/scap-cves.json create mode 100644 tests/data/mock-feed/target-profile.json create mode 100644 tests/data/mock-feed/vt-metadata.json diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index dd5e9f2..f8c7765 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -3,6 +3,8 @@ name: tests on: push: branches: [main, devel] + tags: + - 'v*' pull_request: workflow_dispatch: inputs: @@ -53,7 +55,10 @@ jobs: needs: unit runs-on: ubuntu-latest env: - OPENVAS_MOCK_SCANNER_IMAGE: ghcr.io/clawosiris/openvas-mock-scanner:latest + # Pinned to the released mock artifact so fast scanner-facing CI does not + # drift with a moving :latest tag. Update this deliberately after reading + # the mock scanner release notes. + OPENVAS_MOCK_SCANNER_IMAGE: ghcr.io/clawosiris/openvas-mock-scanner:v0.2.1 steps: - uses: actions/checkout@v4 - uses: astral-sh/setup-uv@v5 @@ -69,6 +74,10 @@ jobs: e2e: needs: [unit, mock-smoke] + if: >- + github.event_name == 'workflow_dispatch' || + (github.event_name == 'pull_request' && github.base_ref == 'main') || + (github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))) runs-on: [self-hosted, Linux, X64, hetzner-vps-scan-examples, scan-examples-e2e] timeout-minutes: 90 steps: diff --git a/README.md b/README.md index e1d9929..946fd0a 100644 --- a/README.md +++ b/README.md @@ -68,21 +68,28 @@ Supported environment variables: The Docker image and local package expose `openvas-example` for scanner lifecycle examples and `openvas-enrich-results` for standalone result enrichment. -## Quick commit smoke test with `openvas-mock-sanner` +## Quick commit smoke test with `openvas-mock-scanner` For fast commit-time coverage, this repo can exercise its real HTTP client and CLI against the baseline mock scanner from -[`clawosiris/openvas-mock-sanner`](https://github.com/clawosiris/openvas-mock-sanner). This is much -lighter than the full Compose/OpenVAS stack and is intended as an early smoke check, not a -replacement for the self-hosted e2e workflow. +[`clawosiris/openvas-mock-sanner`](https://github.com/clawosiris/openvas-mock-sanner). CI pins the +published `ghcr.io/clawosiris/openvas-mock-scanner:v0.2.1` release instead of a floating `:latest` +tag so mock-backed validation only changes when this repository intentionally updates the selected +mock scanner release. This is much lighter than the full Compose/OpenVAS stack and is intended as +the default scanner-facing gate for short-lived pull requests. Local example against the published container image: ```bash -OPENVAS_MOCK_SCANNER_IMAGE=ghcr.io/clawosiris/openvas-mock-scanner:latest \ +OPENVAS_MOCK_SCANNER_IMAGE=ghcr.io/clawosiris/openvas-mock-scanner:v0.2.1 \ uv run pytest tests/test_mock_server_smoke.py ``` +The mock test suite includes a feed-backed compatibility scenario using fixture data under +`tests/data/mock-feed`. Those fixtures mirror the Greenbone feed shapes consumed by the real scan +enrichment flow: VT metadata, Notus-style package advisory data, SCAP/CVE metadata, target services, +and a larger paged result set. + If you do not have a container runtime available, the smoke test still supports a local source checkout fallback: @@ -438,6 +445,11 @@ intentionally keeps the named feed volumes (`vt_data_vol`, `notus_data_vol`, `da `gpg_data_vol`) between runs so Greenbone feed data is updated incrementally instead of re-fetched from scratch every time. Transient scanner state volumes are removed during teardown. +CI is split by validation cost. Unit tests and the pinned mock-backed compatibility test run for +normal pull requests. The heavyweight real scan runs in addition to the mock-backed checks for pull +requests targeting `main`, manual `workflow_dispatch` validation, pushes to `main`, and release tag +pushes such as `v1.2.3`. + ## Reference docs - `scan-docs.md` diff --git a/openspec/changes/released-mock-ci-coverage/tasks.md b/openspec/changes/released-mock-ci-coverage/tasks.md index 1094f63..c20913e 100644 --- a/openspec/changes/released-mock-ci-coverage/tasks.md +++ b/openspec/changes/released-mock-ci-coverage/tasks.md @@ -1,30 +1,30 @@ ## 1. Mock artifact policy -- [ ] 1.1 Replace the floating mock image reference with a released +- [x] 1.1 Replace the floating mock image reference with a released `openvas-mock-scanner` version tag or digest. -- [ ] 1.2 Document how the chosen mock release is selected and updated. +- [x] 1.2 Document how the chosen mock release is selected and updated. ## 2. Higher-value mock compatibility coverage -- [ ] 2.1 Add mock-backed tests that use realistic feed-derived data rather than +- [x] 2.1 Add mock-backed tests that use realistic feed-derived data rather than only the `success-basic` path. -- [ ] 2.2 Cover the client/result behaviors that matter to this repository, such +- [x] 2.2 Cover the client/result behaviors that matter to this repository, such as metadata lookup expectations, result payload shape, and larger or paged result handling when applicable. -- [ ] 2.3 Keep the mock-backed path fast enough to remain the default short-path +- [x] 2.3 Keep the mock-backed path fast enough to remain the default short-path CI gate. ## 3. Real-scan gating policy -- [ ] 3.1 Run real-scan validation in addition to the mock-backed path for pull +- [x] 3.1 Run real-scan validation in addition to the mock-backed path for pull requests targeting `main`. -- [ ] 3.2 Run real-scan validation in addition to the mock-backed path for +- [x] 3.2 Run real-scan validation in addition to the mock-backed path for release validation flows. -- [ ] 3.3 Ensure general PRs and short-lived iteration paths continue to use the +- [x] 3.3 Ensure general PRs and short-lived iteration paths continue to use the fast mock-backed validation by default. ## 4. Verification -- [ ] 4.1 Add or update tests for the new mock compatibility coverage. -- [ ] 4.2 Update CI/workflow documentation to describe the fast-path and +- [x] 4.1 Add or update tests for the new mock compatibility coverage. +- [x] 4.2 Update CI/workflow documentation to describe the fast-path and high-signal-path split. diff --git a/src/scan_examples/client.py b/src/scan_examples/client.py index a97a132..b8db54a 100644 --- a/src/scan_examples/client.py +++ b/src/scan_examples/client.py @@ -95,13 +95,32 @@ def get_results(self, scan_id: str) -> list[dict[str, Any]]: """Fetch result items for a scan. Some endpoints return the results as a top-level array while others wrap - them in ``{"results": [...]}``, so we normalize both into a list. + them in ``{"results": [...]}``, so we normalize both into a list. When + the scanner exposes openvasd-style pagination metadata, fetch all pages. """ data = self._request("GET", f"/scans/{scan_id}/results") if isinstance(data, list): return data if isinstance(data, dict) and isinstance(data.get("results"), list): - return data["results"] + results = list(data["results"]) + next_offset = data.get("next_offset") + total = data.get("total") + limit = data.get("limit") + while isinstance(next_offset, int): + page = self._request( + "GET", + f"/scans/{scan_id}/results", + params={"offset": next_offset, "limit": limit or 100}, + ) + if not ( + isinstance(page, dict) and isinstance(page.get("results"), list) + ): + raise OpenVASAPIError(f"Unexpected paged results payload: {page!r}") + results.extend(page["results"]) + next_offset = page.get("next_offset") + if isinstance(total, int) and len(results) >= total: + break + return results raise OpenVASAPIError(f"Unexpected results payload: {data!r}") def delete_scan(self, scan_id: str) -> Any: diff --git a/tests/data/mock-feed/notus-advisories.json b/tests/data/mock-feed/notus-advisories.json new file mode 100644 index 0000000..f5537c4 --- /dev/null +++ b/tests/data/mock-feed/notus-advisories.json @@ -0,0 +1,21 @@ +{ + "advisories": [ + { + "oid": "1.3.6.1.4.1.25623.1.0.900001", + "title": "Ubuntu: OpenSSL Security Advisory", + "family": "Linux Local Security Checks", + "severity": 7.4, + "cves": ["CVE-2022-0778"], + "summary": "OpenSSL package metadata derived from a Notus-style advisory fixture.", + "solution": "Upgrade openssl to 1.1.1f-1ubuntu2.12 or later.", + "packages": [ + { + "name": "openssl", + "version": "1.1.1f-1ubuntu2.10", + "fixed_version": "1.1.1f-1ubuntu2.12", + "source": "ubuntu" + } + ] + } + ] +} diff --git a/tests/data/mock-feed/scap-cves.json b/tests/data/mock-feed/scap-cves.json new file mode 100644 index 0000000..eb4932f --- /dev/null +++ b/tests/data/mock-feed/scap-cves.json @@ -0,0 +1,18 @@ +{ + "cves": [ + { + "id": "CVE-2021-41773", + "severity": 7.5, + "cvss_vector": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N", + "summary": "Apache HTTP Server path normalization allows path traversal for affected configurations.", + "references": [{"type": "url", "id": "https://httpd.apache.org/security/vulnerabilities_24.html"}] + }, + { + "id": "CVE-2022-0778", + "severity": 7.4, + "cvss_vector": "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:N", + "summary": "OpenSSL certificate parsing can trigger excessive resource use.", + "references": [{"type": "url", "id": "https://www.openssl.org/news/secadv/20220315.txt"}] + } + ] +} diff --git a/tests/data/mock-feed/target-profile.json b/tests/data/mock-feed/target-profile.json new file mode 100644 index 0000000..e9c9f39 --- /dev/null +++ b/tests/data/mock-feed/target-profile.json @@ -0,0 +1,67 @@ +{ + "hosts": [ + { + "host": "192.0.2.10", + "hostname": "metasploitable-web.example.test", + "os": { + "name": "Ubuntu Linux", + "version": "14.04", + "cpe": "cpe:/o:canonical:ubuntu_linux:14.04" + }, + "services": [ + { + "port": 22, + "protocol": "tcp", + "name": "ssh", + "product": "OpenSSH", + "version": "6.6.1p1" + }, + { + "port": 80, + "protocol": "tcp", + "name": "http", + "product": "Apache httpd", + "version": "2.4.49", + "cpe": "cpe:/a:apache:http_server:2.4.49" + }, + { + "port": 443, + "protocol": "tcp", + "name": "https", + "product": "Apache httpd", + "version": "2.4.49", + "cpe": "cpe:/a:apache:http_server:2.4.49" + } + ], + "packages": [ + { + "name": "ghostscript", + "version": "9.53.3", + "cpe": "cpe:/a:artifex:ghostscript:9.53.3" + }, + { + "name": "openssl", + "version": "1.1.1f-1ubuntu2.10", + "cpe": "cpe:/a:openssl:openssl:1.1.1f" + } + ], + "web_apps": [{"path": "/", "name": "example-app", "version": "1.0.0"}], + "auth": {"ssh": "success"} + }, + { + "host": "192.0.2.11", + "hostname": "metasploitable-db.example.test", + "services": [ + { + "port": 5432, + "protocol": "tcp", + "name": "postgresql", + "product": "PostgreSQL", + "version": "9.6" + } + ], + "packages": [{"name": "openssl", "version": "1.1.1f-1ubuntu2.10"}], + "auth": {} + } + ] +} diff --git a/tests/data/mock-feed/vt-metadata.json b/tests/data/mock-feed/vt-metadata.json new file mode 100644 index 0000000..d46a3f0 --- /dev/null +++ b/tests/data/mock-feed/vt-metadata.json @@ -0,0 +1,68 @@ +[ + { + "oid": "1.3.6.1.4.1.25623.1.0.100034", + "name": "HTTP-Version Detection", + "filename": "gb_http_version_detect.nasl", + "family": "Service detection", + "category": "gather_info", + "severity": 0.0, + "qod": 80, + "cpe": ["cpe:/a:apache:http_server"], + "references": [], + "tag": { + "summary": "Detects the HTTP server product and version exposed by the target service.", + "solution": "No remediation is required for an informational detection result." + } + }, + { + "oid": "1.3.6.1.4.1.25623.1.0.147696", + "name": "Ghostscript 9.50 < 9.55.0 Sandbox Escape Vulnerability - Linux", + "filename": "2022/artifex/gb_ghostscript_sandbox_escape_vuln_sep21_lin.nasl", + "family": "General", + "category": "gather_info", + "severity": 9.8, + "cvss_vector": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H", + "qod": 97, + "cpe": ["cpe:/a:artifex:ghostscript"], + "references": [{"class": "cve", "id": "CVE-2021-3781"}], + "tag": { + "summary": "Ghostscript is vulnerable to a sandbox escape issue.", + "solution": "Update Ghostscript to version 9.55.0 or later.", + "solution_type": "VendorFix" + } + }, + { + "oid": "1.3.6.1.4.1.25623.1.0.117812", + "name": "Apache HTTP Server 2.4.49 Path Traversal and File Disclosure Vulnerability", + "filename": "2021/apache/gb_apache_httpd_path_traversal_cve_2021_41773.nasl", + "family": "Web Servers", + "category": "attack", + "severity": 7.5, + "cvss_vector": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N", + "qod": 98, + "cpe": ["cpe:/a:apache:http_server:2.4.49"], + "references": [{"class": "cve", "id": "CVE-2021-41773"}], + "tag": { + "summary": "Apache HTTP Server 2.4.49 can expose files outside configured document roots.", + "solution": "Update Apache HTTP Server to a fixed vendor release.", + "solution_type": "VendorFix" + } + }, + { + "oid": "1.3.6.1.4.1.25623.1.0.900001", + "name": "Ubuntu: OpenSSL Security Advisory", + "filename": "notus/ubuntu_openssl_compat.notus", + "family": "Linux Local Security Checks", + "category": "package", + "severity": 7.4, + "cvss_vector": "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:N", + "qod": 97, + "cpe": ["cpe:/a:openssl:openssl"], + "references": [{"class": "cve", "id": "CVE-2022-0778"}], + "tag": { + "summary": "The installed OpenSSL package is affected by a certificate parsing denial-of-service issue.", + "solution": "Install the vendor fixed OpenSSL package.", + "solution_type": "VendorFix" + } + } +] diff --git a/tests/test_client.py b/tests/test_client.py index 11242ea..6337225 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -60,6 +60,51 @@ def test_get_results_accepts_wrapped_results(): assert client.get_results("scan-123") == [{"id": 1}] +def test_get_results_follows_openvasd_result_pages(): + client = OpenVASScannerClient("http://scanner") + client.session = DummySession( + [ + make_response( + payload={ + "results": [{"id": 1}, {"id": 2}], + "offset": 0, + "limit": 2, + "total": 5, + "next_offset": 2, + } + ), + make_response( + payload={ + "results": [{"id": 3}, {"id": 4}], + "offset": 2, + "limit": 2, + "total": 5, + "next_offset": 4, + } + ), + make_response( + payload={ + "results": [{"id": 5}], + "offset": 4, + "limit": 2, + "total": 5, + "next_offset": None, + } + ), + ] + ) + + assert client.get_results("scan-123") == [ + {"id": 1}, + {"id": 2}, + {"id": 3}, + {"id": 4}, + {"id": 5}, + ] + assert client.session.calls[1]["params"] == {"offset": 2, "limit": 2} + assert client.session.calls[2]["params"] == {"offset": 4, "limit": 2} + + def test_get_scan_status_returns_status_payload(): client = OpenVASScannerClient("http://scanner") client.session = DummySession([make_response(payload={"status": "succeeded"})]) diff --git a/tests/test_compose_feed_sync.py b/tests/test_compose_feed_sync.py index 812a26f..11ed743 100644 --- a/tests/test_compose_feed_sync.py +++ b/tests/test_compose_feed_sync.py @@ -53,8 +53,27 @@ def test_ci_runs_feed_sync_before_scanner_stack_and_keeps_feed_volumes(): assert "scan-examples_data_objects_vol" not in WORKFLOW +def test_ci_uses_released_mock_scanner_and_gates_real_scan(): + assert ( + "OPENVAS_MOCK_SCANNER_IMAGE: ghcr.io/clawosiris/openvas-mock-scanner:v0.2.1" + in WORKFLOW + ) + assert "openvas-mock-scanner:latest" not in WORKFLOW + assert "github.base_ref == 'main'" in WORKFLOW + assert "startsWith(github.ref, 'refs/tags/v')" in WORKFLOW + assert "github.event_name == 'workflow_dispatch'" in WORKFLOW + + def test_readme_documents_feed_sync_flow(): assert "docker compose up greenbone-feed-sync" in README assert "greenbone-feed-sync --type gvmd-data" in README normalized_readme = " ".join(README.split()) assert "subsequent synchronizations only fetch deltas" in normalized_readme + + +def test_readme_documents_fast_mock_and_real_scan_split(): + normalized_readme = " ".join(README.split()) + assert "ghcr.io/clawosiris/openvas-mock-scanner:v0.2.1" in README + assert "floating `:latest` tag" in normalized_readme + assert "pull requests targeting `main`" in normalized_readme + assert "release tag pushes" in normalized_readme diff --git a/tests/test_mock_server_smoke.py b/tests/test_mock_server_smoke.py index 35ef31b..f5b7ceb 100644 --- a/tests/test_mock_server_smoke.py +++ b/tests/test_mock_server_smoke.py @@ -16,6 +16,11 @@ from scan_examples.client import OpenVASScannerClient from scan_examples.e2e import run_lifecycle +from scan_examples.feed import load_vt_metadata_index + + +MOCK_FEED_FIXTURE_DIR = Path(__file__).parent / "data" / "mock-feed" +MOCK_CONTAINER_FEED_DIR = "/mock-feed" def _choose_free_port() -> int: @@ -62,16 +67,39 @@ def _container_runtime() -> str | None: return None -def _mock_server_env(port: int) -> dict[str, str]: - return { - "MOCK_SCENARIO": "success-basic", - "MOCK_RESULT_COUNT": "7", - "MOCK_HOST_COUNT": "3", +def _mock_server_env( + port: int, + *, + scenario: str = "success-basic", + result_count: int = 7, + host_count: int = 3, + page_size: int = 100, + seed: str = "scan-examples-smoke", + feed_fixture_dir: str | Path | None = None, +) -> dict[str, str]: + env = { + "MOCK_SCENARIO": scenario, + "MOCK_RESULT_COUNT": str(result_count), + "MOCK_HOST_COUNT": str(host_count), + "MOCK_PAGE_SIZE": str(page_size), "MOCK_SEED": "scan-examples-smoke", "LISTENING": f"0.0.0.0:{port}", "MOCK_HOST": "0.0.0.0", "MOCK_PORT": str(port), } + env["MOCK_SEED"] = seed + if feed_fixture_dir is not None: + root = Path(feed_fixture_dir) + env.update( + { + "MOCK_VT_METADATA_PATH": str(root / "vt-metadata.json"), + "MOCK_TARGET_PROFILE": str(root / "target-profile.json"), + "MOCK_NOTUS_ADVISORIES_PATH": str(root / "notus-advisories.json"), + "MOCK_SCAP_METADATA_PATH": str(root / "scap-cves.json"), + "MOCK_FEED_STRICT": "true", + } + ) + return env @pytest.fixture(scope="module") @@ -93,11 +121,14 @@ def mock_server_image() -> str | None: @pytest.fixture def mock_server( + request: pytest.FixtureRequest, mock_server_image: str | None, mock_server_repo: Path | None, ): + options = getattr(request, "param", {}) or {} port = _choose_free_port() base_url = f"http://127.0.0.1:{port}" + feed_backed = bool(options.get("feed_backed")) if mock_server_image: runtime = _container_runtime() @@ -106,7 +137,15 @@ def mock_server( "OPENVAS_MOCK_SCANNER_IMAGE is set but neither docker nor podman is available" ) - env = _mock_server_env(80) + env = _mock_server_env( + 80, + scenario=options.get("scenario", "success-basic"), + result_count=options.get("result_count", 7), + host_count=options.get("host_count", 3), + page_size=options.get("page_size", 100), + seed=options.get("seed", "scan-examples-smoke"), + feed_fixture_dir=MOCK_CONTAINER_FEED_DIR if feed_backed else None, + ) command = [ runtime, "run", @@ -115,6 +154,13 @@ def mock_server( "-p", f"{port}:80", ] + if feed_backed: + command.extend( + [ + "-v", + f"{MOCK_FEED_FIXTURE_DIR}:{MOCK_CONTAINER_FEED_DIR}:ro", + ] + ) for key, value in env.items(): command.extend(["-e", f"{key}={value}"]) command.append(mock_server_image) @@ -150,7 +196,17 @@ def mock_server( ) env = os.environ.copy() - env.update(_mock_server_env(port)) + env.update( + _mock_server_env( + port, + scenario=options.get("scenario", "success-basic"), + result_count=options.get("result_count", 7), + host_count=options.get("host_count", 3), + page_size=options.get("page_size", 100), + seed=options.get("seed", "scan-examples-smoke"), + feed_fixture_dir=MOCK_FEED_FIXTURE_DIR if feed_backed else None, + ) + ) process = subprocess.Popen( [sys.executable, "-m", "openvas_mock_scanner"], cwd=mock_server_repo, @@ -203,6 +259,74 @@ def test_mock_server_smoke_lifecycle(mock_server: str): } +@pytest.mark.parametrize( + "mock_server", + [ + { + "feed_backed": True, + "scenario": "success-large-report", + "result_count": 125, + "host_count": 2, + "page_size": 50, + "seed": "scan-examples-feed", + } + ], + indirect=True, +) +def test_mock_server_feed_backed_compatibility(mock_server: str): + _, vt_index = load_vt_metadata_index(MOCK_FEED_FIXTURE_DIR / "vt-metadata.json") + selected_oids = [ + "1.3.6.1.4.1.25623.1.0.100034", + "1.3.6.1.4.1.25623.1.0.147696", + "1.3.6.1.4.1.25623.1.0.117812", + "1.3.6.1.4.1.25623.1.0.900001", + ] + + with urlopen(f"{mock_server}/feed/diagnostics", timeout=1.0) as response: + diagnostics = json.load(response) + assert diagnostics["metadata_count"] == len(vt_index) + assert diagnostics["target_profile_hosts"] == 2 + assert diagnostics["notus_advisories"] == 1 + assert diagnostics["scap_cves"] == 2 + assert diagnostics["diagnostics"] == [] + + with urlopen(f"{mock_server}/vts/{selected_oids[2]}", timeout=1.0) as response: + vt_metadata = json.load(response) + assert vt_metadata["name"].startswith("Apache HTTP Server") + assert "CVE-2021-41773" in vt_metadata["cves"] + + client = OpenVASScannerClient(mock_server) + result = run_lifecycle( + client=client, + payload={ + "scan_id": "scan-examples-feed", + "target": {"hosts": ["192.0.2.10"], "ports": "T:22,80,443"}, + "vts": [{"oid": oid} for oid in selected_oids], + }, + wait_before_results=0, + create_retry_delay=0, + results_timeout=10, + results_poll_interval=0.1, + min_results=125, + vt_index=vt_index, + ) + + result_oids = {finding["oid"] for finding in result.results} + assert result.findings_summary["total"] == 125 + assert result_oids == set(selected_oids) + assert {finding["id"] for finding in result.results} == set(range(125)) + assert result.findings_summary["by_type"]["alarm"] > 0 + assert result.findings_summary["by_type"]["log"] > 0 + assert all( + enriched["feed-metadata-source"] == "vt" + for enriched in result.enriched_results + ) + assert all( + enriched["vt-metadata-status"] == "matched" + for enriched in result.enriched_results + ) + + def test_cli_commands_work_against_mock_server(mock_server: str, tmp_path: Path): scan_path = tmp_path / "scan.json" scan_path.write_text( From 7e20ea59c5066346eeecd0881596895f8d4fb135 Mon Sep 17 00:00:00 2001 From: OpenClaw Bot Date: Sat, 30 May 2026 12:20:36 +0000 Subject: [PATCH 3/5] Format mock compatibility test --- tests/test_mock_server_smoke.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_mock_server_smoke.py b/tests/test_mock_server_smoke.py index f5b7ceb..aba8d1d 100644 --- a/tests/test_mock_server_smoke.py +++ b/tests/test_mock_server_smoke.py @@ -318,8 +318,7 @@ def test_mock_server_feed_backed_compatibility(mock_server: str): assert result.findings_summary["by_type"]["alarm"] > 0 assert result.findings_summary["by_type"]["log"] > 0 assert all( - enriched["feed-metadata-source"] == "vt" - for enriched in result.enriched_results + enriched["feed-metadata-source"] == "vt" for enriched in result.enriched_results ) assert all( enriched["vt-metadata-status"] == "matched" From 1fd2d608fcb253ec1e2d94d21d0f64cde25c0fcb Mon Sep 17 00:00:00 2001 From: OpenClaw Bot Date: Sat, 30 May 2026 15:00:35 +0000 Subject: [PATCH 4/5] fix: use mock image tag without v prefix --- .github/workflows/tests.yml | 2 +- README.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f8c7765..d523bc8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -58,7 +58,7 @@ jobs: # Pinned to the released mock artifact so fast scanner-facing CI does not # drift with a moving :latest tag. Update this deliberately after reading # the mock scanner release notes. - OPENVAS_MOCK_SCANNER_IMAGE: ghcr.io/clawosiris/openvas-mock-scanner:v0.2.1 + OPENVAS_MOCK_SCANNER_IMAGE: ghcr.io/clawosiris/openvas-mock-scanner:0.2.1 steps: - uses: actions/checkout@v4 - uses: astral-sh/setup-uv@v5 diff --git a/README.md b/README.md index 946fd0a..1c1054d 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ The Docker image and local package expose `openvas-example` for scanner lifecycl For fast commit-time coverage, this repo can exercise its real HTTP client and CLI against the baseline mock scanner from [`clawosiris/openvas-mock-sanner`](https://github.com/clawosiris/openvas-mock-sanner). CI pins the -published `ghcr.io/clawosiris/openvas-mock-scanner:v0.2.1` release instead of a floating `:latest` +published `ghcr.io/clawosiris/openvas-mock-scanner:0.2.1` release instead of a floating `:latest` tag so mock-backed validation only changes when this repository intentionally updates the selected mock scanner release. This is much lighter than the full Compose/OpenVAS stack and is intended as the default scanner-facing gate for short-lived pull requests. @@ -81,7 +81,7 @@ the default scanner-facing gate for short-lived pull requests. Local example against the published container image: ```bash -OPENVAS_MOCK_SCANNER_IMAGE=ghcr.io/clawosiris/openvas-mock-scanner:v0.2.1 \ +OPENVAS_MOCK_SCANNER_IMAGE=ghcr.io/clawosiris/openvas-mock-scanner:0.2.1 \ uv run pytest tests/test_mock_server_smoke.py ``` From a3e3e9e79904b45ac93b9ec1b5bf99cba59fe2e7 Mon Sep 17 00:00:00 2001 From: OpenClaw Bot Date: Sat, 30 May 2026 15:02:37 +0000 Subject: [PATCH 5/5] test: align CI assertions with released mock tag --- tests/test_compose_feed_sync.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_compose_feed_sync.py b/tests/test_compose_feed_sync.py index 11ed743..519e8fb 100644 --- a/tests/test_compose_feed_sync.py +++ b/tests/test_compose_feed_sync.py @@ -55,7 +55,7 @@ def test_ci_runs_feed_sync_before_scanner_stack_and_keeps_feed_volumes(): def test_ci_uses_released_mock_scanner_and_gates_real_scan(): assert ( - "OPENVAS_MOCK_SCANNER_IMAGE: ghcr.io/clawosiris/openvas-mock-scanner:v0.2.1" + "OPENVAS_MOCK_SCANNER_IMAGE: ghcr.io/clawosiris/openvas-mock-scanner:0.2.1" in WORKFLOW ) assert "openvas-mock-scanner:latest" not in WORKFLOW @@ -73,7 +73,7 @@ def test_readme_documents_feed_sync_flow(): def test_readme_documents_fast_mock_and_real_scan_split(): normalized_readme = " ".join(README.split()) - assert "ghcr.io/clawosiris/openvas-mock-scanner:v0.2.1" in README + assert "ghcr.io/clawosiris/openvas-mock-scanner:0.2.1" in README assert "floating `:latest` tag" in normalized_readme assert "pull requests targeting `main`" in normalized_readme assert "release tag pushes" in normalized_readme