MCPcopy Index your code
hub / github.com/willnorris/imageproxy / TestValidSignature

Function TestValidSignature

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

Source from the content-addressed store, hash-verified

226}
227
228func TestValidSignature(t *testing.T) {
229 key := []byte("c0ffee")
230
231 tests := []struct {
232 url string
233 options Options
234 valid bool
235 }{
236 {"http://test/image", Options{Signature: "NDx5zZHx7QfE8E-ijowRreq6CJJBZjwiRfOVk_mkfQQ="}, true},
237 {"http://test/image", Options{Signature: "NDx5zZHx7QfE8E-ijowRreq6CJJBZjwiRfOVk_mkfQQ"}, true},
238 {"http://test/image", emptyOptions, false},
239 // url-only signature with options
240 {"http://test/image", Options{Signature: "NDx5zZHx7QfE8E-ijowRreq6CJJBZjwiRfOVk_mkfQQ", Rotate: 90}, true},
241 // signature calculated from url plus options
242 {"http://test/image", Options{Signature: "ZGTzEm32o4iZ7qcChls3EVYaWyrDd9u0etySo0-WkF8=", Rotate: 90}, true},
243 // invalid base64 encoded signature
244 {"http://test/image", Options{Signature: "!!"}, false},
245 }
246
247 for _, tt := range tests {
248 u, err := url.Parse(tt.url)
249 if err != nil {
250 t.Errorf("error parsing url %q: %v", tt.url, err)
251 }
252 req := &Request{u, tt.options, &http.Request{}}
253 if got, want := validSignature(key, req), tt.valid; got != want {
254 t.Errorf("validSignature(%v, %v) returned %v, want %v", key, req, got, want)
255 }
256 }
257}
258
259func TestShould304(t *testing.T) {
260 tests := []struct {

Callers

nothing calls this directly

Calls 1

validSignatureFunction · 0.85

Tested by

no test coverage detected