- Replace hardcoded ALL_SERVICE_NAMES=[5 services] in cli.py with
_all_service_names() pulling dynamically from the plugin registry;
randomize-services now draws from all 25 registered honeypots
- Add build_base field to DistroProfile: apt-compatible image for service
Dockerfiles (ubuntu22/ubuntu20/kali get their own; others fall back to
debian:bookworm-slim since Dockerfiles use apt-get)
- Add build_base to DeckyConfig; propagate from distro in _build_deckies
and _build_deckies_from_ini
- Inject BASE_IMAGE build arg in composer.py for every build-based service
so each decky's containers reflect its assigned distro
- Update all 21 service Dockerfiles: FROM debian:bookworm-slim →
ARG BASE_IMAGE=debian:bookworm-slim / FROM ${BASE_IMAGE}
- Add tests/test_cli_service_pool.py and tests/test_composer.py (306 total)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
82 lines
2.4 KiB
Python
82 lines
2.4 KiB
Python
"""
|
|
Tests for the CLI service pool — verifies that --randomize-services draws
|
|
from all registered services, not just the original hardcoded 5.
|
|
"""
|
|
|
|
import pytest
|
|
from decnet.cli import _all_service_names, _build_deckies
|
|
from decnet.services.registry import all_services
|
|
|
|
|
|
ORIGINAL_5 = {"ssh", "smb", "rdp", "http", "ftp"}
|
|
|
|
|
|
def test_all_service_names_covers_full_registry():
|
|
"""_all_service_names() must return every service in the registry."""
|
|
pool = set(_all_service_names())
|
|
registry = set(all_services().keys())
|
|
assert pool == registry
|
|
|
|
|
|
def test_all_service_names_is_sorted():
|
|
names = _all_service_names()
|
|
assert names == sorted(names)
|
|
|
|
|
|
def test_all_service_names_includes_at_least_25():
|
|
assert len(_all_service_names()) >= 25
|
|
|
|
|
|
def test_all_service_names_includes_all_original_5():
|
|
pool = set(_all_service_names())
|
|
assert ORIGINAL_5.issubset(pool)
|
|
|
|
|
|
def test_randomize_services_pool_exceeds_original_5():
|
|
"""
|
|
After enough random draws, at least one service outside the original 5 must appear.
|
|
With 25 services and picking 1-3 at a time, 200 draws makes this ~100% certain.
|
|
"""
|
|
all_drawn: set[str] = set()
|
|
for _ in range(200):
|
|
deckies = _build_deckies(
|
|
n=1,
|
|
ips=["10.0.0.10"],
|
|
services_explicit=None,
|
|
randomize_services=True,
|
|
)
|
|
all_drawn.update(deckies[0].services)
|
|
|
|
beyond_original = all_drawn - ORIGINAL_5
|
|
assert beyond_original, (
|
|
f"After 200 draws only saw the original 5 services. "
|
|
f"All drawn: {sorted(all_drawn)}"
|
|
)
|
|
|
|
|
|
def test_build_deckies_randomize_services_valid():
|
|
"""All randomly chosen services must exist in the registry."""
|
|
registry = set(all_services().keys())
|
|
for _ in range(50):
|
|
deckies = _build_deckies(
|
|
n=3,
|
|
ips=["10.0.0.10", "10.0.0.11", "10.0.0.12"],
|
|
services_explicit=None,
|
|
randomize_services=True,
|
|
)
|
|
for decky in deckies:
|
|
unknown = set(decky.services) - registry
|
|
assert not unknown, f"Decky {decky.name} got unknown services: {unknown}"
|
|
|
|
|
|
def test_build_deckies_explicit_services_unchanged():
|
|
"""Explicit service list must pass through untouched."""
|
|
deckies = _build_deckies(
|
|
n=2,
|
|
ips=["10.0.0.10", "10.0.0.11"],
|
|
services_explicit=["ssh", "ftp"],
|
|
randomize_services=False,
|
|
)
|
|
for decky in deckies:
|
|
assert decky.services == ["ssh", "ftp"]
|