feat: human-readable scan_id from UTC time + request CIDRs + short random suffix
Made-with: Cursor
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package scans
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewScanIDShape(t *testing.T) {
|
||||
id, err := newScanID([]string{"192.168.160.0/24"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
parts := strings.Split(id, "_")
|
||||
if len(parts) < 3 {
|
||||
t.Fatalf("expected at least time_slug_suffix, got %q", id)
|
||||
}
|
||||
if len(parts[len(parts)-1]) != 4 {
|
||||
t.Fatalf("expected 4-hex suffix, got %q", id)
|
||||
}
|
||||
if !strings.Contains(id, "192.168.160.0_24") {
|
||||
t.Fatalf("expected sanitized cidr in id: %q", id)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSanitizeScanSlug(t *testing.T) {
|
||||
if g := sanitizeScanSlug("10.0.0.0/8"); g != "10.0.0.0_8" {
|
||||
t.Fatalf("got %q", g)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user