Web UI (internal/webui): - dependency-free embedded HTML/JS served on the loopback listener - /api/assets (provider/service/exposure/q filters) and /api/stats - optional HTTP basic auth via UI_USER/UI_PASS Prober (internal/probe): - vendor-specific, unauthenticated, non-destructive checks: S3/R2/Spaces ListObjectsV2, GCS JSON object list, Azure ?comp=list, Firebase /.json?shallow=true, Supabase REST, and bare TCP connect for database endpoints (never reported readable, no auth attempted) - exposure_detail records the factual reason (status code, region, tcp port) - bounded random-sample queue instead of FIFO: one high-volume hostname template (mrap) no longer starves every other asset type - schema: cloud_assets.exposure_detail + probed_at (idempotent ALTER) Live: stable ~450MiB under 1GiB, no restarts, UI and probe states (private/reachable/auth_required) flowing, 0 db errors.
73 lines
1.8 KiB
Go
73 lines
1.8 KiB
Go
package store
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"software.sslmate.com/src/certspotter/cttypes"
|
|
|
|
"tea.karlcom.de/karl/bucketeer/internal/model"
|
|
"tea.karlcom.de/karl/bucketeer/internal/pipeline"
|
|
)
|
|
|
|
func TestSTHKeyStableAndUnique(t *testing.T) {
|
|
a := &cttypes.SignedTreeHead{TreeSize: 10, Timestamp: 100}
|
|
if sthKey(a) != sthKey(a) {
|
|
t.Fatal("sthKey is not deterministic")
|
|
}
|
|
b := &cttypes.SignedTreeHead{TreeSize: 11, Timestamp: 100}
|
|
if sthKey(a) == sthKey(b) {
|
|
t.Fatal("sthKey collides for different tree sizes")
|
|
}
|
|
}
|
|
|
|
func TestNonNil(t *testing.T) {
|
|
if got := nonNil(nil); got == nil || len(got) != 0 {
|
|
t.Fatalf("nonNil(nil) = %#v", got)
|
|
}
|
|
in := []string{"a"}
|
|
if got := nonNil(in); len(got) != 1 || got[0] != "a" {
|
|
t.Fatalf("nonNil changed slice: %#v", got)
|
|
}
|
|
}
|
|
|
|
// TestIntegration exercises the real schema when DATABASE_URL is set.
|
|
func TestIntegration(t *testing.T) {
|
|
url := os.Getenv("DATABASE_URL")
|
|
if url == "" {
|
|
t.Skip("DATABASE_URL not set; skipping integration test")
|
|
}
|
|
ctx := t.Context()
|
|
s, err := Open(ctx, url, 2)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer s.Close()
|
|
if err := s.Migrate(ctx); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
f := pipeline.Finding{
|
|
Candidate: model.Candidate{
|
|
Hostname: "it-bucket.s3.eu-central-1.amazonaws.com",
|
|
Original: "it-bucket.s3.eu-central-1.amazonaws.com",
|
|
Provider: model.ProviderAWS,
|
|
Service: model.ServiceS3,
|
|
Source: model.SourceDirectCT,
|
|
},
|
|
IPv4: []string{"1.2.3.4"},
|
|
}
|
|
if err := s.WriteFindings(ctx, []pipeline.Finding{f}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := s.UpdateExposure(ctx, model.ProviderAWS.String(), model.ServiceS3.String(), f.Hostname, model.ExposureReachable, "test"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := s.ListAssets(ctx, AssetFilter{Provider: "aws", Limit: 10}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := s.Stats(ctx); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|