Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: tests
on:
push:
branches: [main, devel]
tags:
- 'v*'
pull_request:
workflow_dispatch:
inputs:
Expand Down Expand Up @@ -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:0.2.1
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v5
Expand All @@ -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:
Expand Down
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: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.

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:0.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:

Expand Down Expand Up @@ -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`
Expand Down
40 changes: 40 additions & 0 deletions openspec/changes/released-mock-ci-coverage/proposal.md
Original file line number Diff line number Diff line change
@@ -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.
30 changes: 30 additions & 0 deletions openspec/changes/released-mock-ci-coverage/tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## 1. Mock artifact policy

- [x] 1.1 Replace the floating mock image reference with a released
`openvas-mock-scanner` version tag or digest.
- [x] 1.2 Document how the chosen mock release is selected and updated.

## 2. Higher-value mock compatibility coverage

- [x] 2.1 Add mock-backed tests that use realistic feed-derived data rather than
only the `success-basic` path.
- [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.
- [x] 2.3 Keep the mock-backed path fast enough to remain the default short-path
CI gate.

## 3. Real-scan gating policy

- [x] 3.1 Run real-scan validation in addition to the mock-backed path for pull
requests targeting `main`.
- [x] 3.2 Run real-scan validation in addition to the mock-backed path for
release validation flows.
- [x] 3.3 Ensure general PRs and short-lived iteration paths continue to use the
fast mock-backed validation by default.

## 4. Verification

- [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.
65 changes: 65 additions & 0 deletions openspec/specs/released-mock-ci-coverage/spec.md
Original file line number Diff line number Diff line change
@@ -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.
23 changes: 21 additions & 2 deletions src/scan_examples/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 21 additions & 0 deletions tests/data/mock-feed/notus-advisories.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
]
}
18 changes: 18 additions & 0 deletions tests/data/mock-feed/scap-cves.json
Original file line number Diff line number Diff line change
@@ -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"}]
}
]
}
67 changes: 67 additions & 0 deletions tests/data/mock-feed/target-profile.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
]
}
Loading
Loading