Skip to content

Commit b98b345

Browse files
committed
tests: use named fields in TestAllowed
This will make it easier to add new fields to the test cases struct.
1 parent df0b6d3 commit b98b345

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

imageproxy_test.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func TestCopyHeader(t *testing.T) {
9393
}
9494

9595
func TestAllowed(t *testing.T) {
96-
allowHosts := []string{"good"}
96+
good := []string{"good"}
9797
key := [][]byte{
9898
[]byte("c0ffee"),
9999
}
@@ -121,38 +121,38 @@ func TestAllowed(t *testing.T) {
121121
allowed bool
122122
}{
123123
// no allowHosts or signature key
124-
{"http://test/image", emptyOptions, nil, nil, nil, nil, nil, true},
124+
{url: "http://test/image", allowed: true},
125125

126126
// allowHosts
127-
{"http://good/image", emptyOptions, allowHosts, nil, nil, nil, nil, true},
128-
{"http://bad/image", emptyOptions, allowHosts, nil, nil, nil, nil, false},
127+
{url: "http://good/image", allowHosts: good, allowed: true},
128+
{url: "http://bad/image", allowHosts: good, allowed: false},
129129

130130
// referrer
131-
{"http://test/image", emptyOptions, nil, nil, allowHosts, nil, genRequest(map[string]string{"Referer": "http://good/foo"}), true},
132-
{"http://test/image", emptyOptions, nil, nil, allowHosts, nil, genRequest(map[string]string{"Referer": "http://bad/foo"}), false},
133-
{"http://test/image", emptyOptions, nil, nil, allowHosts, nil, genRequest(map[string]string{"Referer": "MALFORMED!!"}), false},
134-
{"http://test/image", emptyOptions, nil, nil, allowHosts, nil, genRequest(map[string]string{}), false},
131+
{url: "http://test/image", referrers: good, request: genRequest(map[string]string{"Referer": "http://good/foo"}), allowed: true},
132+
{url: "http://test/image", referrers: good, request: genRequest(map[string]string{"Referer": "http://bad/foo"}), allowed: false},
133+
{url: "http://test/image", referrers: good, request: genRequest(map[string]string{"Referer": "MALFORMED!!"}), allowed: false},
134+
{url: "http://test/image", referrers: good, request: genRequest(map[string]string{}), allowed: false},
135135

136136
// signature key
137-
{"http://test/image", Options{Signature: "NDx5zZHx7QfE8E-ijowRreq6CJJBZjwiRfOVk_mkfQQ="}, nil, nil, nil, key, nil, true},
138-
{"http://test/image", Options{Signature: "NDx5zZHx7QfE8E-ijowRreq6CJJBZjwiRfOVk_mkfQQ="}, nil, nil, nil, multipleKey, nil, true}, // signed with key "c0ffee"
139-
{"http://test/image", Options{Signature: "FWIawYV4SEyI4zKJMeGugM-eJM1eI_jXPEQ20ZgRe4A="}, nil, nil, nil, multipleKey, nil, true}, // signed with key "beer"
140-
{"http://test/image", Options{Signature: "deadbeef"}, nil, nil, nil, key, nil, false},
141-
{"http://test/image", Options{Signature: "deadbeef"}, nil, nil, nil, multipleKey, nil, false},
142-
{"http://test/image", emptyOptions, nil, nil, nil, key, nil, false},
137+
{url: "http://test/image", options: Options{Signature: "NDx5zZHx7QfE8E-ijowRreq6CJJBZjwiRfOVk_mkfQQ="}, keys: key, allowed: true},
138+
{url: "http://test/image", options: Options{Signature: "NDx5zZHx7QfE8E-ijowRreq6CJJBZjwiRfOVk_mkfQQ="}, keys: multipleKey, allowed: true}, // signed with key "c0ffee"
139+
{url: "http://test/image", options: Options{Signature: "FWIawYV4SEyI4zKJMeGugM-eJM1eI_jXPEQ20ZgRe4A="}, keys: multipleKey, allowed: true}, // signed with key "beer"
140+
{url: "http://test/image", options: Options{Signature: "deadbeef"}, keys: key, allowed: false},
141+
{url: "http://test/image", options: Options{Signature: "deadbeef"}, keys: multipleKey, allowed: false},
142+
{url: "http://test/image", keys: key, allowed: false},
143143

144144
// allowHosts and signature
145-
{"http://good/image", emptyOptions, allowHosts, nil, nil, key, nil, true},
146-
{"http://bad/image", Options{Signature: "gWivrPhXBbsYEwpmWAKjbJEiAEgZwbXbltg95O2tgNI="}, nil, nil, nil, key, nil, true},
147-
{"http://bad/image", emptyOptions, allowHosts, nil, nil, key, nil, false},
145+
{url: "http://good/image", allowHosts: good, keys: key, allowed: true},
146+
{url: "http://bad/image", options: Options{Signature: "gWivrPhXBbsYEwpmWAKjbJEiAEgZwbXbltg95O2tgNI="}, keys: key, allowed: true},
147+
{url: "http://bad/image", allowHosts: good, keys: key, allowed: false},
148148

149149
// deny requests that match denyHosts, even if signature is valid or also matches allowHosts
150-
{"http://test/image", emptyOptions, nil, []string{"test"}, nil, nil, nil, false},
151-
{"http://test:3000/image", emptyOptions, nil, []string{"test"}, nil, nil, nil, false},
152-
{"http://test/image", emptyOptions, []string{"test"}, []string{"test"}, nil, nil, nil, false},
153-
{"http://test/image", Options{Signature: "NDx5zZHx7QfE8E-ijowRreq6CJJBZjwiRfOVk_mkfQQ="}, nil, []string{"test"}, nil, key, nil, false},
154-
{"http://127.0.0.1/image", emptyOptions, nil, []string{"127.0.0.0/8"}, nil, nil, nil, false},
155-
{"http://127.0.0.1:3000/image", emptyOptions, nil, []string{"127.0.0.0/8"}, nil, nil, nil, false},
150+
{url: "http://test/image", denyHosts: []string{"test"}, allowed: false},
151+
{url: "http://test:3000/image", denyHosts: []string{"test"}, allowed: false},
152+
{url: "http://test/image", allowHosts: []string{"test"}, denyHosts: []string{"test"}, allowed: false},
153+
{url: "http://test/image", options: Options{Signature: "NDx5zZHx7QfE8E-ijowRreq6CJJBZjwiRfOVk_mkfQQ="}, denyHosts: []string{"test"}, keys: key, allowed: false},
154+
{url: "http://127.0.0.1/image", denyHosts: []string{"127.0.0.0/8"}, allowed: false},
155+
{url: "http://127.0.0.1:3000/image", denyHosts: []string{"127.0.0.0/8"}, allowed: false},
156156
}
157157

158158
for _, tt := range tests {

0 commit comments

Comments
 (0)