rename RemoteHosts to AllowHosts

This is what I probably should have called this when I renamed it back
in 70276f36, since this makes it more obvious that it's a list of
allowed hosts.  Renaming now to make room for a `DenyHosts` variable as
part of #85.
This commit is contained in:
Will Norris 2019-03-17 03:05:13 +00:00
parent 4acc0b24ce
commit 5eab3024c6
3 changed files with 37 additions and 37 deletions

View file

@ -97,7 +97,7 @@ func TestCopyHeader(t *testing.T) {
}
func TestAllowed(t *testing.T) {
remoteHosts := []string{"good"}
allowHosts := []string{"good"}
key := []byte("c0ffee")
genRequest := func(headers map[string]string) *http.Request {
@ -109,41 +109,41 @@ func TestAllowed(t *testing.T) {
}
tests := []struct {
url string
options Options
remoteHosts []string
referrers []string
key []byte
request *http.Request
allowed bool
url string
options Options
allowHosts []string
referrers []string
key []byte
request *http.Request
allowed bool
}{
// no remoteHosts or signature key
// no allowHosts or signature key
{"http://test/image", emptyOptions, nil, nil, nil, nil, true},
// remoteHosts
{"http://good/image", emptyOptions, remoteHosts, nil, nil, nil, true},
{"http://bad/image", emptyOptions, remoteHosts, nil, nil, nil, false},
// allowHosts
{"http://good/image", emptyOptions, allowHosts, nil, nil, nil, true},
{"http://bad/image", emptyOptions, allowHosts, nil, nil, nil, false},
// referrer
{"http://test/image", emptyOptions, nil, remoteHosts, nil, genRequest(map[string]string{"Referer": "http://good/foo"}), true},
{"http://test/image", emptyOptions, nil, remoteHosts, nil, genRequest(map[string]string{"Referer": "http://bad/foo"}), false},
{"http://test/image", emptyOptions, nil, remoteHosts, nil, genRequest(map[string]string{"Referer": "MALFORMED!!"}), false},
{"http://test/image", emptyOptions, nil, remoteHosts, nil, genRequest(map[string]string{}), false},
{"http://test/image", emptyOptions, nil, allowHosts, nil, genRequest(map[string]string{"Referer": "http://good/foo"}), true},
{"http://test/image", emptyOptions, nil, allowHosts, nil, genRequest(map[string]string{"Referer": "http://bad/foo"}), false},
{"http://test/image", emptyOptions, nil, allowHosts, nil, genRequest(map[string]string{"Referer": "MALFORMED!!"}), false},
{"http://test/image", emptyOptions, nil, allowHosts, nil, genRequest(map[string]string{}), false},
// signature key
{"http://test/image", Options{Signature: "NDx5zZHx7QfE8E-ijowRreq6CJJBZjwiRfOVk_mkfQQ="}, nil, nil, key, nil, true},
{"http://test/image", Options{Signature: "deadbeef"}, nil, nil, key, nil, false},
{"http://test/image", emptyOptions, nil, nil, key, nil, false},
// remoteHosts and signature
{"http://good/image", emptyOptions, remoteHosts, nil, key, nil, true},
// allowHosts and signature
{"http://good/image", emptyOptions, allowHosts, nil, key, nil, true},
{"http://bad/image", Options{Signature: "gWivrPhXBbsYEwpmWAKjbJEiAEgZwbXbltg95O2tgNI="}, nil, nil, key, nil, true},
{"http://bad/image", emptyOptions, remoteHosts, nil, key, nil, false},
{"http://bad/image", emptyOptions, allowHosts, nil, key, nil, false},
}
for _, tt := range tests {
p := NewProxy(nil, nil)
p.RemoteHosts = tt.remoteHosts
p.AllowHosts = tt.allowHosts
p.SignatureKey = tt.key
p.Referrers = tt.referrers
@ -159,7 +159,7 @@ func TestAllowed(t *testing.T) {
}
func TestValidHost(t *testing.T) {
remoteHosts := []string{"a.test", "*.b.test", "*c.test"}
allowHosts := []string{"a.test", "*.b.test", "*c.test"}
tests := []struct {
url string
@ -182,8 +182,8 @@ func TestValidHost(t *testing.T) {
if err != nil {
t.Errorf("error parsing url %q: %v", tt.url, err)
}
if got, want := validHost(remoteHosts, u), tt.valid; got != want {
t.Errorf("validHost(%v, %q) returned %v, want %v", remoteHosts, u, got, want)
if got, want := validHost(allowHosts, u), tt.valid; got != want {
t.Errorf("validHost(%v, %q) returned %v, want %v", allowHosts, u, got, want)
}
}
}
@ -326,7 +326,7 @@ func TestProxy_ServeHTTP(t *testing.T) {
Client: &http.Client{
Transport: testTransport{},
},
RemoteHosts: []string{"good.test"},
AllowHosts: []string{"good.test"},
ContentTypes: []string{"image/*"},
}