add imageproxy-sign tool for calculating signatures

it's a little bit rough, but seems to work pretty well.

Ref #145
This commit is contained in:
Will Norris 2019-03-27 21:51:22 +00:00
parent 38d3bcc7fe
commit e1558d5626
3 changed files with 120 additions and 0 deletions

View file

@ -0,0 +1,34 @@
package main
import (
"net/url"
"testing"
)
func TestParseURL(t *testing.T) {
tests := []struct {
input, output string
}{
{"/", "/#0x0"},
// imageproxy URLs
{"http://localhost:8080//http://example.com/", "http://example.com/#0x0"},
{"http://localhost:8080/10,r90,jpeg/http://example.com/", "http://example.com/#10x10,jpeg,r90"},
// remote URLs, with and without options
{"http://example.com/", "http://example.com/#0x0"},
{"http://example.com/#r90,jpeg", "http://example.com/#0x0,jpeg,r90"},
// ensure signature values are stripped
{"http://localhost:8080/sc0ffee/http://example.com/", "http://example.com/#0x0"},
{"http://example.com/#sc0ffee", "http://example.com/#0x0"},
}
for _, tt := range tests {
want, _ := url.Parse(tt.output)
got := parseURL(tt.input)
if got.String() != want.String() {
t.Errorf("parseURL(%q) returned %q, want %q", tt.input, got, want)
}
}
}