2026-09-22 13:13:10 +02:00
|
|
|
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)
|
|
|
|
|
}
|
2026-09-22 13:58:28 +02:00
|
|
|
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 {
|
2026-09-22 13:13:10 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|