Single stateless Go process that consumes CT logs via embedded (patched) CertSpotter internals, classifies cloud/database/storage DNS identifiers in-process with a zero-allocation classifier, enriches via round-robin DNS resolvers with CNAME following, and batch-writes useful findings to PostgreSQL. - third_party/certspotter: 2-hunk IdentifierSink patch, no stdout/JSON/files - internal/classify: AWS/Azure/GCP/Firebase/Cloudflare R2/DigitalOcean/Supabase/OCI - internal/dns: sharded bounded TTL cache, multi-resolver load balancing + failover - internal/pipeline: bounded queues, dedup, direct-priority load shedding - internal/store: pgx batch writer, Postgres CT checkpoints (no cert contents) - internal/probe: optional non-destructive reachability checks (off by default) - Docker: distroless non-root, read-only rootfs, no app volume, resource limits - tests enforce 0 allocs/op on the classifier and sink hot path
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package config
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestLoadDefaults(t *testing.T) {
|
|
t.Setenv("DATABASE_URL", "postgres://localhost/ctcloud")
|
|
c, err := Load()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if c.DatabaseURL != "postgres://localhost/ctcloud" {
|
|
t.Fatalf("database url = %q", c.DatabaseURL)
|
|
}
|
|
if c.DNSWorkers != 16 || c.DNSMaxCNAMEdepth != 8 {
|
|
t.Fatalf("unexpected DNS defaults: %+v", c)
|
|
}
|
|
if c.ActiveProbing {
|
|
t.Fatal("active probing must default to false")
|
|
}
|
|
}
|
|
|
|
func TestLoadOverrides(t *testing.T) {
|
|
t.Setenv("DATABASE_URL", "postgres://localhost/ctcloud")
|
|
t.Setenv("DNS_WORKERS", "4")
|
|
t.Setenv("ACTIVE_PROBING", "true")
|
|
t.Setenv("DB_FLUSH_INTERVAL", "250ms")
|
|
t.Setenv("STATS_INTERVAL", "30s")
|
|
c, err := Load()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if c.DNSWorkers != 4 || !c.ActiveProbing {
|
|
t.Fatalf("overrides not applied: %+v", c)
|
|
}
|
|
if c.DBFlushInterval != 250*time.Millisecond || c.StatsInterval != 30*time.Second {
|
|
t.Fatalf("duration overrides not applied: %+v", c)
|
|
}
|
|
}
|
|
|
|
func TestLoadInvalid(t *testing.T) {
|
|
t.Setenv("DATABASE_URL", "")
|
|
if _, err := Load(); err == nil {
|
|
t.Fatal("expected error without DATABASE_URL")
|
|
}
|
|
t.Setenv("DATABASE_URL", "postgres://localhost/ctcloud")
|
|
t.Setenv("LOG_LEVEL", "verbose")
|
|
if _, err := Load(); err == nil {
|
|
t.Fatal("expected error for bad LOG_LEVEL")
|
|
}
|
|
}
|