-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_scanner.py
More file actions
67 lines (58 loc) · 1.8 KB
/
Copy pathtest_scanner.py
File metadata and controls
67 lines (58 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from pathlib import Path
from scanner import _extract_image_tag, _load_yaml, build_inventory
def test_sensitive_env_files_are_never_parsed(tmp_path: Path) -> None:
env_path = tmp_path / ".env"
env_path.write_text("PASSWORD=supersecretvalue", encoding="utf-8")
try:
_load_yaml(env_path)
assert False, "Expected sensitive file read to be rejected"
except ValueError as exc:
assert "Refusing to read sensitive file" in str(exc)
def test_variable_references_are_never_resolved() -> None:
assert _extract_image_tag("ghcr.io/app/service:${APP_VERSION:-latest}") == "unresolved"
def test_basic_compose_scan_has_expected_keys(tmp_path: Path) -> None:
compose = tmp_path / "web" / "docker-compose.yml"
(tmp_path / "web").mkdir()
compose.write_text(
"""
services:
web:
container_name: web-app
image: nginx:1.27
environment:
- API_KEY=${API_KEY}
- SIMPLE=abc
ports:
- "8080:80"
healthcheck:
test: ["CMD", "echo", "ok"]
""".strip(),
encoding="utf-8",
)
result = build_inventory(tmp_path, scanner_version="0.1.0-test")
assert result.inventory["metadata"]["version"] == "0.1.0-test"
assert len(result.inventory["services"]) == 1
service = result.inventory["services"][0]
expected_keys = {
"name",
"compose_service_name",
"container_name",
"image",
"image_tag",
"service_type",
"urls",
"internal_ports",
"published_ports",
"networks",
"bind_mounts",
"environment_keys",
"depends_on",
"healthcheck",
"restart",
"security",
"labels",
"source_file",
"source",
"potential_hardcoded_secrets",
}
assert expected_keys.issubset(set(service.keys()))