strawberry/tests/meson.build
trvon 1d19f537c0
Monitor execs and file writes on macOS with Endpoint Security
New meson option enable_endpoint_security (auto, macOS only) links
EndpointSecurity and bsm and builds three ES backends behind the
existing interfaces. Helpers are in src/platform/es_support.hpp.

- ProcessMonitor: NOTIFY_EXEC events (pid, parent, path, dev:ino,
  argv, start time) plus NOTIFY_TRACE and NOTIFY_KEXTLOAD for the
  behavior rules. Events go to a bounded queue (4096, overflow counted
  in events_dropped) drained on the monitor thread, so callbacks stay
  on one thread. Without an ES client the monitor polls libproc
  (backend "libproc"). backend_name() reports "endpoint_security".
- ExecGuard: AUTH_EXEC with the fanotify guard's rules. It fails open
  at min(timeout, ES deadline - 500 ms) and on a full queue, and on
  macOS 27+ ES_DEADLINE_MISS_MODE_FAIL_OPEN makes the kernel allow a
  missed deadline too. Platform binaries and SIP paths are never
  denied, and our own execs are muted. ES does not cache verdicts, so
  rule changes apply on the next exec. Our own cache keys on
  dev:ino:size:mtime:generation. The image is opened by path and its
  dev:ino checked against the event; a swapped file counts as
  unscanned.
- FileWatcher: NOTIFY_CREATE/RENAME/CLOSE(modified) with inverted
  target-path muting: named entries selected literally, whole
  directories by prefix. macos_watch_specs() covers launchd
  agents/daemons, periodic jobs, cron tabs, sudo drop-ins, shell rc
  files, authorized_keys, Downloads and the temp directories.
  match_watch_spec() (direct children, as with fanotify directory
  marks) is portable and tested. Home dirs come from the directory
  service (local_home_dirs).

Every ES handler is noexcept and records swallowed exceptions. Client
errors name the missing requirement (root, entitlement, Full Disk
Access), and the daemon keeps running detection-only.

macos_es_live (root, ES entitlement) checks deny/allow/cache/
platform-binary/fail-open/audit for the guard, exec telemetry and
the file watcher, using small signed payload binaries. It has not run
yet: the development Mac has SIP enabled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 20:53:16 -06:00

434 lines
13 KiB
Meson

# Tests for Strawberry Security Scanner
test_deps = common_deps + strawberry_feature_deps
# Basic hash utils test
test_hash = executable('test_hash_utils',
'test_hash_utils.cpp',
'../src/hash_utils.cpp',
include_directories: inc_dirs,
dependencies: test_deps,
)
test('hash_utils', test_hash)
# Config test
test_config = executable('test_config',
'test_config.cpp',
'../src/config.cpp',
include_directories: inc_dirs,
dependencies: test_deps,
)
test('config', test_config)
# Database test
test_database = executable('test_database',
'test_database.cpp',
database_sources,
include_directories: inc_dirs,
dependencies: strawberry_runtime_deps,
)
test('database', test_database)
test_incident_report = executable('test_incident_report',
'test_incident_report.cpp',
'../src/incident_report.cpp',
database_sources,
include_directories: inc_dirs,
dependencies: strawberry_runtime_deps,
)
test('incident_report', test_incident_report)
test_correlation_engine = executable('test_correlation_engine',
'test_correlation_engine.cpp',
'../src/correlation_engine.cpp',
database_sources,
'../src/hash_utils.cpp',
include_directories: inc_dirs,
dependencies: strawberry_runtime_deps,
)
test('correlation_engine', test_correlation_engine)
test_process_query = executable('test_process_query',
'test_process_query.cpp',
'../src/process_query.cpp',
database_sources,
include_directories: inc_dirs,
dependencies: strawberry_runtime_deps,
)
test('process_query', test_process_query)
# Process monitor test (procfs polling backend and event ingestion)
test_process_monitor = executable('test_process_monitor',
'test_process_monitor.cpp',
'../src/process_monitor.cpp',
'../src/hash_utils.cpp',
include_directories: inc_dirs,
dependencies: strawberry_monitor_deps,
)
test('process_monitor', test_process_monitor)
runtime_pipeline_deps = strawberry_runtime_deps
if yara_dep.found()
runtime_pipeline_deps += yara_dep
endif
if libbpf_dep.found()
runtime_pipeline_deps += libbpf_dep
endif
test_runtime_pipeline = executable('test_runtime_pipeline',
'test_runtime_pipeline.cpp',
'../src/detection_pipeline.cpp',
'../src/resource_governor.cpp',
'../src/policy.cpp',
'../src/exec_guard.cpp',
'../src/crash_safety.cpp',
'../src/behavior_engine.cpp',
'../src/file_watch.cpp',
'../src/opensnitch.cpp',
'../src/ioc_set.cpp',
'../src/correlation_engine.cpp',
'../src/process_monitor.cpp',
'../src/yara_scanner.cpp',
database_sources,
'../src/hash_utils.cpp',
'../src/config.cpp',
include_directories: inc_dirs,
dependencies: runtime_pipeline_deps,
)
test('runtime_pipeline', test_runtime_pipeline)
test_daemon_runtime = executable('test_daemon_runtime',
'test_daemon_runtime.cpp',
'../src/daemon_app.cpp',
'../src/thread_priority.cpp',
'../src/control_server.cpp',
'../src/opensnitch.cpp',
'../src/exec_guard.cpp',
'../src/crash_safety.cpp',
'../src/behavior_engine.cpp',
'../src/file_watch.cpp',
'../src/correlation_engine.cpp',
'../src/detection_pipeline.cpp',
'../src/resource_governor.cpp',
'../src/policy.cpp',
'../src/ioc_set.cpp',
'../src/daemon_states.cpp',
'../src/process_monitor.cpp',
'../src/yara_scanner.cpp',
database_sources,
'../src/hash_utils.cpp',
'../src/config.cpp',
include_directories: inc_dirs,
dependencies: runtime_pipeline_deps,
)
test('daemon_runtime', test_daemon_runtime)
process_monitor_live_smoke = executable('process_monitor_live_smoke',
'process_monitor_live_smoke.cpp',
'../src/process_monitor.cpp',
'../src/hash_utils.cpp',
include_directories: inc_dirs,
dependencies: strawberry_monitor_deps,
)
live_bpf_pipeline_smoke = executable('live_bpf_pipeline_smoke',
'live_bpf_pipeline_smoke.cpp',
'../src/detection_pipeline.cpp',
'../src/resource_governor.cpp',
'../src/policy.cpp',
'../src/exec_guard.cpp',
'../src/crash_safety.cpp',
'../src/behavior_engine.cpp',
'../src/file_watch.cpp',
'../src/opensnitch.cpp',
'../src/ioc_set.cpp',
'../src/correlation_engine.cpp',
'../src/process_monitor.cpp',
'../src/yara_scanner.cpp',
database_sources,
'../src/hash_utils.cpp',
'../src/config.cpp',
include_directories: inc_dirs,
dependencies: runtime_pipeline_deps,
)
live_bpf_daemon_smoke = executable('live_bpf_daemon_smoke',
'live_bpf_daemon_smoke.cpp',
'../src/daemon_app.cpp',
'../src/thread_priority.cpp',
'../src/control_server.cpp',
'../src/opensnitch.cpp',
'../src/exec_guard.cpp',
'../src/crash_safety.cpp',
'../src/behavior_engine.cpp',
'../src/file_watch.cpp',
'../src/correlation_engine.cpp',
'../src/detection_pipeline.cpp',
'../src/resource_governor.cpp',
'../src/policy.cpp',
'../src/ioc_set.cpp',
'../src/daemon_states.cpp',
'../src/process_monitor.cpp',
'../src/yara_scanner.cpp',
database_sources,
'../src/hash_utils.cpp',
'../src/config.cpp',
include_directories: inc_dirs,
dependencies: runtime_pipeline_deps,
)
# YARA scanner test (real scans when libyara is present, graceful fallback otherwise)
test_yara_scanner = executable('test_yara_scanner',
'test_yara_scanner.cpp',
'../src/yara_scanner.cpp',
include_directories: inc_dirs,
dependencies: strawberry_yara_deps,
)
test('yara_scanner', test_yara_scanner)
# Direct submodule persistence/transaction test
test_control_server = executable('test_control_server',
'test_control_server.cpp',
'../src/control_server.cpp',
include_directories: inc_dirs,
dependencies: common_deps,
)
test('control_server', test_control_server)
test_policy = executable('test_policy',
'test_policy.cpp',
include_directories: inc_dirs,
dependencies: strawberry_core_dep,
)
test('policy', test_policy)
if strawberry_updater_available and yara_dep.found()
test_rule_updater = executable('test_rule_updater',
'test_rule_updater.cpp',
'../src/rule_updater.cpp',
'../src/yara_scanner.cpp',
include_directories: inc_dirs,
dependencies: [strawberry_core_dep, updater_feature_dep, yara_dep, yara_feature_dep],
)
test('rule_updater', test_rule_updater)
# Property (invariant) tests over parsers and decision logic. Seeded;
# reproduce a failure with STRAWBERRY_PROPERTY_SEED=<seed>.
test_invariants = executable('test_invariants',
'test_invariants.cpp',
'../src/rule_updater.cpp',
'../src/yara_scanner.cpp',
include_directories: inc_dirs,
dependencies: [strawberry_core_dep, updater_feature_dep, yara_dep, yara_feature_dep],
)
test('invariants', test_invariants, timeout: 120)
endif
test_opensnitch = executable('test_opensnitch',
'test_opensnitch.cpp',
include_directories: inc_dirs,
dependencies: strawberry_core_dep,
)
test('opensnitch', test_opensnitch)
test_exec_guard = executable('test_exec_guard',
'test_exec_guard.cpp',
include_directories: inc_dirs,
dependencies: strawberry_core_dep,
)
test('exec_guard', test_exec_guard)
# Live fanotify check (root only): scripts/run_exec_guard_live_docker.sh
exec_guard_live = executable('exec_guard_live',
'exec_guard_live.cpp',
include_directories: inc_dirs,
dependencies: strawberry_core_dep,
)
test_behavior_engine = executable('test_behavior_engine',
'test_behavior_engine.cpp',
include_directories: inc_dirs,
dependencies: strawberry_core_dep,
)
test('behavior_engine', test_behavior_engine)
# Live fanotify persistence watcher check (root only)
file_watch_live = executable('file_watch_live',
'file_watch_live.cpp',
include_directories: inc_dirs,
dependencies: strawberry_core_dep,
)
# Live Endpoint Security check (macOS; root + ES entitlement): make macos-live-tests
if host_machine.system() == 'darwin' and strawberry_es_available
foreach payload : [['es_live_evil', 'EVIL-MARKER'], ['es_live_clean', 'CLEAN'], ['es_live_slow', 'SLOW-MARKER']]
executable(payload[0], 'es_live_payload.cpp', cpp_args: ['-DMARKER="' + payload[1] + '"'])
endforeach
macos_es_live = executable('macos_es_live',
'macos_es_live.cpp',
'../src/process_monitor.cpp',
'../src/hash_utils.cpp',
include_directories: inc_dirs,
dependencies: strawberry_core_dep,
)
endif
# Live eBPF behavior telemetry check (root + BPF object; Linux ptrace API)
if host_machine.system() == 'linux'
behavior_live = executable('behavior_live',
'behavior_live.cpp',
'../src/process_monitor.cpp',
'../src/hash_utils.cpp',
include_directories: inc_dirs,
dependencies: strawberry_monitor_deps,
)
endif
test_resource_governor = executable('test_resource_governor',
'test_resource_governor.cpp',
include_directories: inc_dirs,
dependencies: strawberry_core_dep,
)
test('resource_governor', test_resource_governor)
test_platform_process = executable('test_platform_process',
'test_platform_process.cpp',
include_directories: inc_dirs,
dependencies: strawberry_core_dep,
)
test('platform_process', test_platform_process)
test_crash_safety = executable('test_crash_safety',
'test_crash_safety.cpp',
include_directories: inc_dirs,
dependencies: strawberry_core_dep,
)
test('crash_safety', test_crash_safety)
# Static source invariants (lessons the dynamic tests missed; see the script).
python3_prog = find_program('python3')
test('source_invariants', python3_prog,
args: ['-I', meson.project_source_root() / 'tests' / 'source_invariants.py', meson.project_source_root()])
test('source_invariants_selftest', python3_prog,
args: ['-I', meson.project_source_root() / 'tests' / 'source_invariants.py', '--self-test', meson.project_source_root()])
# Fault-injection properties: these sources are compiled with the I/O seam's
# injector enabled (STRAWBERRY_FAULT_INJECTION=1). Production objects never are.
test_fault_injection = executable('test_fault_injection',
'test_fault_injection.cpp',
'../src/detection_pipeline.cpp',
'../src/resource_governor.cpp',
'../src/policy.cpp',
'../src/exec_guard.cpp',
'../src/crash_safety.cpp',
'../src/behavior_engine.cpp',
'../src/file_watch.cpp',
'../src/opensnitch.cpp',
'../src/ioc_set.cpp',
'../src/correlation_engine.cpp',
'../src/process_monitor.cpp',
'../src/yara_scanner.cpp',
database_sources,
'../src/hash_utils.cpp',
'../src/config.cpp',
include_directories: inc_dirs,
cpp_args: ['-DSTRAWBERRY_FAULT_INJECTION=1'],
dependencies: runtime_pipeline_deps,
)
test('fault_injection', test_fault_injection, timeout: 300)
# Event-store codec (varint, fields, records, CRC32C, zstd blocks): properties.
test_store_codec = executable('test_store_codec',
'test_store_codec.cpp',
'../src/store/codec.cpp',
include_directories: inc_dirs,
dependencies: [zstd_dep],
)
test('store_codec', test_store_codec, timeout: 120)
# Segment writer/reader/recovery under injected I/O faults (S1-S4). Compiled
# with the fault injector, so it builds its own copies of the store sources.
test_store_segment = executable('test_store_segment',
'test_store_segment.cpp',
'../src/store/codec.cpp',
'../src/store/segment.cpp',
include_directories: inc_dirs,
cpp_args: ['-DSTRAWBERRY_FAULT_INJECTION=1'],
dependencies: [zstd_dep],
)
test('store_segment', test_store_segment, timeout: 300)
# MANIFEST encoding and crash-atomic publish under injected faults (M1-M3).
test_store_manifest = executable('test_store_manifest',
'test_store_manifest.cpp',
'../src/store/codec.cpp',
'../src/store/segment.cpp',
'../src/store/manifest.cpp',
include_directories: inc_dirs,
cpp_args: ['-DSTRAWBERRY_FAULT_INJECTION=1'],
dependencies: [zstd_dep],
)
test('store_manifest', test_store_manifest, timeout: 300)
# LogStore (store directory: lock, manifest, recovery, rolls, orphans) under
# injected faults and crashes (L1-L6).
test_store_log = executable('test_store_log',
'test_store_log.cpp',
'../src/store/codec.cpp',
'../src/store/segment.cpp',
'../src/store/manifest.cpp',
'../src/store/log_store.cpp',
include_directories: inc_dirs,
cpp_args: ['-DSTRAWBERRY_FAULT_INJECTION=1'],
dependencies: [zstd_dep],
)
test('store_log', test_store_log, timeout: 300)
# Differential: the event-store Database answers every query exactly as the
# old (unqlite-format) store did (writes, transactions, rollbacks, reopens, read-only).
test_store_differential = executable('test_store_differential',
'test_store_differential.cpp',
database_sources,
include_directories: inc_dirs,
dependencies: strawberry_runtime_deps,
)
test('store_differential', test_store_differential, timeout: 300)
# EvidenceStore (app/MCP read-only view) over the event store.
test_evidence_store = executable('test_evidence_store',
'test_evidence_store.cpp',
include_directories: inc_dirs,
dependencies: [strawberry_core_dep],
)
test('evidence_store', test_evidence_store)
# Legacy (unqlite-format) database import (I1-I5).
test_store_import = executable('test_store_import',
'test_store_import.cpp',
database_sources,
include_directories: inc_dirs,
dependencies: strawberry_runtime_deps,
)
test('store_import', test_store_import, timeout: 300)