This guide explains how to test the Stackdog Security modules.
# Start development environment
docker-compose up -d
# View logs
docker-compose logs -f stackdog
# Run tests inside container
docker-compose exec stackdog cargo test --lib# Setup environment
cp .env.sample .env
# Create database directory
mkdir -p db
# Set database URL
export DATABASE_URL=./db/stackdog.db
# Run tests (schema is initialized automatically via init_database)
cargo test --libThe following modules can be tested without database connection:
cargo test --lib -- events::syscall::tests
cargo test --lib -- events::security::testscargo test --lib -- rules::engine::tests
cargo test --lib -- rules::signatures::tests
cargo test --lib -- rules::builtin::tests
cargo test --lib -- rules::result::tests
cargo test --lib -- rules::signature_matcher::tests
cargo test --lib -- rules::threat_scorer::tests
cargo test --lib -- rules::stats::testscargo test --lib -- alerting::alert::tests
cargo test --lib -- alerting::manager::tests
cargo test --lib -- alerting::dedup::tests
cargo test --lib -- alerting::notifications::tests# These require root and Linux
sudo cargo test --lib -- firewall::nftables::tests
sudo cargo test --lib -- firewall::iptables::tests
sudo cargo test --lib -- firewall::quarantine::tests# eBPF tests require Linux with eBPF support
sudo cargo test --lib -- collectors::ebpf::tests# Make executable
chmod +x scripts/test.sh
# Run test script
./scripts/test.sh| Module | Tests | Database Required | Root Required | Platform |
|---|---|---|---|---|
| events/* | 64+ | No | No | All |
| rules/* | 100+ | No | No | All |
| alerting/* | 52+ | No | No | All |
| firewall/* | 44+ | No | Yes (some) | Linux |
| collectors/ebpf/* | 35+ | No | Yes | Linux |
Integration tests require:
- SQLite database
- Migrations run
- (Optional) Docker daemon for container tests
# Run integration tests
cargo test --test integrationSome existing code (auth middleware) has compatibility issues with actix-web 4.x. These modules are being updated.
Workaround: Test only the new security modules:
cargo test --lib -- events:: rules:: alerting::If you see database connection errors:
# Create SQLite database
mkdir -p db
touch db/stackdog.db
# Set environment variable
export DATABASE_URL=./db/stackdog.db
eBPF tests require:
- Linux kernel 4.19+
- Root privileges
- BTF support (recommended)
# Check kernel version
uname -r
# Check eBPF support
bpftool version# Default (SQLite)
docker-compose up
# With PostgreSQL (optional)
docker-compose --profile postgres up
# With Adminer (database UI)
docker-compose --profile adminer up# Required
APP_HOST=0.0.0.0
APP_PORT=5000
DATABASE_URL=./db/stackdog.db
# Optional
RUST_LOG=debug
RUST_BACKTRACE=fullTables are created automatically by init_database on startup. Ensure DATABASE_URL points to a writable path.
# For eBPF/firewall tests
sudo cargo test --lib# Install nftables
sudo apt-get install nftables # Debian/Ubuntu
sudo yum install nftables # RHEL/CentOS# Install iptables
sudo apt-get install iptables # Debian/Ubuntu
sudo yum install iptables # RHEL/CentOS- Run unit tests for security modules
- Setup Docker environment for integration tests
- Run eBPF tests on Linux VM (if developing on macOS)
- DEVELOPMENT.md - Full development guide
- QUICKSTART.md - Quick start guide
- TODO.md - Task tracking