Azure has two levels: the account maps to DNS (<account>.blob.core.windows.net) and anonymous access is per container with no anonymous container enumeration. Discovery now tests incoming labels as Azure account names (DNS existence) and, for accounts that exist, probes a small set of common containers, indexing any that list anonymously. CONTENT still never downloaded. Also document that docker compose down -v wipes all discovered assets; use stop/start to keep the pgdata volume. Live: connectsystem.blob.core.windows.net indexed (33 objects).
62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
package discover
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestCandidatesAreExactLabelsOnly(t *testing.T) {
|
|
got := candidates("assets.example.com")
|
|
if len(got) != 2 || got[0] != "assets" || got[1] != "example" {
|
|
t.Fatalf("candidates = %v, want [assets example] (no fabricated names)", got)
|
|
}
|
|
for _, c := range got {
|
|
if !validBucketName(c) {
|
|
t.Fatalf("invalid candidate %q", c)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestValidAzureAccount(t *testing.T) {
|
|
for _, ok := range []string{"myaccount", "abc123", "a1b2c3d4e5f6g7h8i9j0k1l2"} {
|
|
if !validAzureAccount(ok) {
|
|
t.Fatalf("%q should be a valid Azure account name", ok)
|
|
}
|
|
}
|
|
for _, bad := range []string{"ab", "has-hyphen", "UPPER", "with.dot", "a1b2c3d4e5f6g7h8i9j0k1l2m3"} {
|
|
if validAzureAccount(bad) {
|
|
t.Fatalf("%q should be rejected as an Azure account name", bad)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestBaseLabelsSkipsNoise(t *testing.T) {
|
|
got := baseLabels("www.example.com")
|
|
if len(got) != 1 || got[0] != "example" {
|
|
t.Fatalf("baseLabels = %v, want [example]", got)
|
|
}
|
|
if baseLabels("example") != nil {
|
|
t.Fatal("single label must yield no base")
|
|
}
|
|
}
|
|
|
|
func TestTargets(t *testing.T) {
|
|
d := New(Config{})
|
|
ts := d.targets("example")
|
|
if len(ts) != 2 {
|
|
t.Fatalf("got %d targets, want 2", len(ts))
|
|
}
|
|
var s3, gcs bool
|
|
for _, tg := range ts {
|
|
switch {
|
|
case strings.Contains(tg.URL, "example.s3.amazonaws.com/?list-type=2"):
|
|
s3 = true
|
|
case strings.Contains(tg.URL, "storage.googleapis.com/example"):
|
|
gcs = true
|
|
}
|
|
}
|
|
if !s3 || !gcs {
|
|
t.Fatalf("missing targets: s3=%v gcs=%v (%v)", s3, gcs, ts)
|
|
}
|
|
}
|