diff --git a/internal/config/config_validation_internal_test.go b/internal/config/config_validation_internal_test.go index a222c03..abfdee7 100644 --- a/internal/config/config_validation_internal_test.go +++ b/internal/config/config_validation_internal_test.go @@ -5,6 +5,7 @@ import ( "log/slog" "os" "path/filepath" + "slices" "strings" "testing" "time" @@ -216,6 +217,25 @@ func TestCommaSeparatedAllowlistStillSupported(t *testing.T) { } } +// TestAllowlistHostsAcceptsUnderscore checks that an upstream host name with +// an underscore, which pixa can fetch from, is accepted as an entry. +func TestAllowlistHostsAcceptsUnderscore(t *testing.T) { + t.Parallel() + + c, err := configFromYAML(t, signingKeyLine+`allowlist_hosts: + - my_bucket.example.com + - .my_bucket.example.org +`) + if err != nil { + t.Fatalf("host names with an underscore should load, got error: %v", err) + } + + want := []string{"my_bucket.example.com", ".my_bucket.example.org"} + if !slices.Equal(c.AllowlistHosts, want) { + t.Errorf("AllowlistHosts = %v, want %v", c.AllowlistHosts, want) + } +} + // runAbortCases asserts that each case's config aborts startup with an // error message mentioning every expected substring. func runAbortCases(t *testing.T, cases []abortCase) { diff --git a/internal/config/referer_blocklist_internal_test.go b/internal/config/referer_blocklist_internal_test.go index a198272..43d5753 100644 --- a/internal/config/referer_blocklist_internal_test.go +++ b/internal/config/referer_blocklist_internal_test.go @@ -43,6 +43,25 @@ func TestRefererBlocklistAcceptsIPAddresses(t *testing.T) { } } +// TestRefererBlocklistAcceptsUnderscore checks that a host name with an +// underscore, which a page can be served from, is accepted as an entry. +func TestRefererBlocklistAcceptsUnderscore(t *testing.T) { + t.Parallel() + + c, err := configFromYAML(t, signingKeyLine+`referer_blocklist: + - my_site.leech.example + - .my_site.hotlinker.example +`) + if err != nil { + t.Fatalf("host names with an underscore should load, got error: %v", err) + } + + want := []string{"my_site.leech.example", ".my_site.hotlinker.example"} + if !slices.Equal(c.RefererBlocklist, want) { + t.Errorf("RefererBlocklist = %v, want %v", c.RefererBlocklist, want) + } +} + // TestRefererBlocklistOmittedIsEmpty checks that an omitted key blocks no // referer. func TestRefererBlocklistOmittedIsEmpty(t *testing.T) {