MCPcopy
hub / github.com/willnorris/imageproxy / TestReferrerMatches

Function TestReferrerMatches

imageproxy_test.go:206–226  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

204}
205
206func TestReferrerMatches(t *testing.T) {
207 hosts := []string{"a.test"}
208
209 tests := []struct {
210 referrer string
211 valid bool
212 }{
213 {"", false},
214 {"%", false},
215 {"http://a.test/", true},
216 {"http://b.test/", false},
217 }
218
219 for _, tt := range tests {
220 r, _ := http.NewRequest("GET", "/", nil)
221 r.Header.Set("Referer", tt.referrer)
222 if got, want := referrerMatches(hosts, r), tt.valid; got != want {
223 t.Errorf("referrerMatches(%v, %v) returned %v, want %v", hosts, r, got, want)
224 }
225 }
226}
227
228func TestValidSignature(t *testing.T) {
229 key := []byte("c0ffee")

Callers

nothing calls this directly

Calls 2

referrerMatchesFunction · 0.85
SetMethod · 0.65

Tested by

no test coverage detected