- Refactor tests to achieve 100% Zero-Mocks compliance (remove unittest.mock, add tests.helpers.env_override and stdlib redirects) - Extract testable parsing methods in package managers and inspector - Add tests/test_security.py with 5 negative AppSec test cases (Zip Slip, Root Gate, Tampering SHA-256, Secret Sanitization, and AST check for zero shell=True) - Expand is_sanitized_target to redact all private SSH/TLS keys (*.key, *.pem, id_*) - Split Gitea CI/CD pipelines into test-and-lint.yaml and build-and-release.yaml - Add .gitleaks.toml configuration - Formally close v1.0.0 genesis plan in docs/plans/linux-backuper/00-status.md as immutable ADR - Bump version to v2.0.0 across __init__.py, man page, tests, and documentation
82 lines
2.9 KiB
YAML
82 lines
2.9 KiB
YAML
name: Test, Lint and Security Gate
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- 'feat/*'
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
security-and-quality:
|
|
name: Security Scan and Quality Audits
|
|
runs-on: fedora
|
|
steps:
|
|
- name: Checkout Source Code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
# 🔒 Bramka 1: Deterministyczny skan sekretów (Gitleaks via Podman)
|
|
- name: Gitleaks Secret Scan
|
|
run: |
|
|
echo "=== Running Gitleaks Secret Scan ==="
|
|
if command -v podman &>/dev/null; then
|
|
podman run --rm -v "$(pwd):/repo:ro,Z" -w /repo zricethezav/gitleaks:latest dir /repo --verbose --no-banner
|
|
elif command -v gitleaks &>/dev/null; then
|
|
gitleaks dir . --verbose --no-banner
|
|
else
|
|
echo "::warning::Neither Podman nor gitleaks found on runner. Attempting containerized execution..."
|
|
podman run --rm -v "$(pwd):/repo:ro,Z" -w /repo zricethezav/gitleaks:latest dir /repo --verbose --no-banner
|
|
fi
|
|
|
|
# 🔒 Bramka 2: Statyczna analiza bezpieczeństwa SAST (Bandit)
|
|
- name: Bandit Security SAST Audit
|
|
run: |
|
|
echo "=== Running Bandit SAST Audit ==="
|
|
if ! command -v bandit &>/dev/null; then
|
|
sudo dnf install -y bandit 2>/dev/null || pip3 install --upgrade bandit 2>/dev/null || true
|
|
fi
|
|
if command -v bandit &>/dev/null; then
|
|
bandit -r linux_backuper/ -ll
|
|
else
|
|
echo "::warning::Bandit could not be installed; skipping SAST step."
|
|
fi
|
|
|
|
# 🔍 Bramka 3: Audyt Zero-Stubs (brak TODO/FIXME)
|
|
- name: Zero-Stub Quality Audit
|
|
run: |
|
|
echo "=== Zero-Stub Quality Audit ==="
|
|
! grep -rnE "TODO|FIXME" linux_backuper/ tests/
|
|
|
|
# 🔍 Bramka 4: Audyt Anti-Mock (brak mockowania struktur wewnętrznych)
|
|
- name: Anti-Mock Quality Audit
|
|
run: |
|
|
echo "=== Anti-Mock Quality Audit ==="
|
|
! grep -rnE "unittest\.mock|MagicMock|monkeypatch" tests/
|
|
|
|
test-and-coverage:
|
|
name: Unit & Security Tests (Coverage >= 80%)
|
|
needs: security-and-quality
|
|
runs-on: fedora
|
|
steps:
|
|
- name: Checkout Source Code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Coverage Tool
|
|
run: |
|
|
echo "=== Verifying / Installing Python Coverage ==="
|
|
if ! python3 -m coverage --version &>/dev/null; then
|
|
sudo dnf install -y python3-coverage 2>/dev/null || pip3 install --upgrade coverage 2>/dev/null || true
|
|
fi
|
|
|
|
- name: Run Test Suite with Coverage Proof (>= 80%)
|
|
run: |
|
|
echo "=== Executing Test Suite under Coverage ==="
|
|
python3 -m coverage run --source=linux_backuper -m unittest discover tests
|
|
echo "=== Terminal Coverage Report Table ==="
|
|
python3 -m coverage report -m --fail-under=80
|