@@ -18,11 +18,12 @@ import (
18
18
)
19
19
20
20
var camoConfig = Config {
21
- HMACKey : []byte ("0x24FEEDFACEDEADBEEFCAFE" ),
22
- MaxSize : 5120 * 1024 ,
23
- RequestTimeout : time .Duration (10 ) * time .Second ,
24
- MaxRedirects : 3 ,
25
- ServerName : "go-camo" ,
21
+ HMACKey : []byte ("0x24FEEDFACEDEADBEEFCAFE" ),
22
+ MaxSize : 5120 * 1024 ,
23
+ RequestTimeout : time .Duration (10 ) * time .Second ,
24
+ MaxRedirects : 3 ,
25
+ ServerName : "go-camo" ,
26
+ AllowContentVideo : false ,
26
27
}
27
28
28
29
func makeReq (testURL string ) (* http.Request , error ) {
@@ -56,14 +57,14 @@ func processRequest(req *http.Request, status int, camoConfig Config) (*httptest
56
57
return record , nil
57
58
}
58
59
59
- func makeTestReq (testURL string , status int ) (* httptest.ResponseRecorder , error ) {
60
+ func makeTestReq (testURL string , status int , config Config ) (* httptest.ResponseRecorder , error ) {
60
61
req , err := makeReq (testURL )
61
62
if err != nil {
62
63
return nil , err
63
64
}
64
- record , err := processRequest (req , status , camoConfig )
65
+ record , err := processRequest (req , status , config )
65
66
if err != nil {
66
- return nil , err
67
+ return record , err
67
68
}
68
69
return record , nil
69
70
}
@@ -86,7 +87,7 @@ func TestNotFound(t *testing.T) {
86
87
func TestSimpleValidImageURL (t * testing.T ) {
87
88
t .Parallel ()
88
89
testURL := "http://www.google.com/images/srpr/logo11w.png"
89
- record , err := makeTestReq (testURL , 200 )
90
+ record , err := makeTestReq (testURL , 200 , camoConfig )
90
91
if assert .Nil (t , err ) {
91
92
// validate headers
92
93
assert .Equal (t , "test" , record .HeaderMap .Get ("X-Go-Camo" ), "Expected custom response header not found" )
@@ -97,128 +98,145 @@ func TestSimpleValidImageURL(t *testing.T) {
97
98
func TestGoogleChartURL (t * testing.T ) {
98
99
t .Parallel ()
99
100
testURL := "http://chart.apis.google.com/chart?chs=920x200&chxl=0:%7C2010-08-13%7C2010-09-12%7C2010-10-12%7C2010-11-11%7C1:%7C0%7C0%7C0%7C0%7C0%7C0&chm=B,EBF5FB,0,0,0&chco=008Cd6&chls=3,1,0&chg=8.3,20,1,4&chd=s:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&chxt=x,y&cht=lc"
100
- _ , err := makeTestReq (testURL , 200 )
101
+ _ , err := makeTestReq (testURL , 200 , camoConfig )
101
102
assert .Nil (t , err )
102
103
}
103
104
104
105
func TestChunkedImageFile (t * testing.T ) {
105
106
t .Parallel ()
106
107
testURL := "https://www.igvita.com/posts/12/spdyproxy-diagram.png"
107
- _ , err := makeTestReq (testURL , 200 )
108
+ _ , err := makeTestReq (testURL , 200 , camoConfig )
108
109
assert .Nil (t , err )
109
110
}
110
111
111
112
func TestFollowRedirects (t * testing.T ) {
112
113
t .Parallel ()
113
114
testURL := "http://cl.ly/1K0X2Y2F1P0o3z140p0d/boom-headshot.gif"
114
- _ , err := makeTestReq (testURL , 200 )
115
+ _ , err := makeTestReq (testURL , 200 , camoConfig )
115
116
assert .Nil (t , err )
116
117
}
117
118
118
119
func TestStrangeFormatRedirects (t * testing.T ) {
119
120
t .Parallel ()
120
121
testURL := "http://cl.ly/DPcp/Screen%20Shot%202012-01-17%20at%203.42.32%20PM.png"
121
- _ , err := makeTestReq (testURL , 200 )
122
+ _ , err := makeTestReq (testURL , 200 , camoConfig )
122
123
assert .Nil (t , err )
123
124
}
124
125
125
126
func TestRedirectsWithPathOnly (t * testing.T ) {
126
127
t .Parallel ()
127
128
testURL := "http://httpbin.org/redirect-to?url=%2Fredirect-to%3Furl%3Dhttp%3A%2F%2Fwww.google.com%2Fimages%2Fsrpr%2Flogo11w.png"
128
- _ , err := makeTestReq (testURL , 200 )
129
+ _ , err := makeTestReq (testURL , 200 , camoConfig )
129
130
assert .Nil (t , err )
130
131
}
131
132
132
133
func TestFollowTempRedirects (t * testing.T ) {
133
134
t .Parallel ()
134
135
testURL := "http://httpbin.org/redirect-to?url=http://www.google.com/images/srpr/logo11w.png"
135
- _ , err := makeTestReq (testURL , 200 )
136
+ _ , err := makeTestReq (testURL , 200 , camoConfig )
136
137
assert .Nil (t , err )
137
138
}
138
139
139
140
func TestBadContentType (t * testing.T ) {
140
141
t .Parallel ()
141
142
testURL := "http://httpbin.org/response-headers?Content-Type=what"
142
- _ , err := makeTestReq (testURL , 400 )
143
+ _ , err := makeTestReq (testURL , 400 , camoConfig )
144
+ assert .Nil (t , err )
145
+ }
146
+
147
+ func TestVideoContentTypeAllowed (t * testing.T ) {
148
+ t .Parallel ()
149
+
150
+ camoConfigWithVideo := Config {
151
+ HMACKey : []byte ("0x24FEEDFACEDEADBEEFCAFE" ),
152
+ MaxSize : 180 * 1024 ,
153
+ RequestTimeout : time .Duration (10 ) * time .Second ,
154
+ MaxRedirects : 3 ,
155
+ ServerName : "go-camo" ,
156
+ AllowContentVideo : true ,
157
+ }
158
+
159
+ testURL := "http://mirrors.standaloneinstaller.com/video-sample/small.mp4"
160
+ _ , err := makeTestReq (testURL , 200 , camoConfigWithVideo )
143
161
assert .Nil (t , err )
144
162
}
145
163
146
164
func Test404InfiniRedirect (t * testing.T ) {
147
165
t .Parallel ()
148
166
testURL := "http://httpbin.org/redirect/4"
149
- _ , err := makeTestReq (testURL , 404 )
167
+ _ , err := makeTestReq (testURL , 404 , camoConfig )
150
168
assert .Nil (t , err )
151
169
}
152
170
153
171
func Test404URLWithoutHTTPHost (t * testing.T ) {
154
172
t .Parallel ()
155
173
testURL := "/picture/Mincemeat/Pimp.jpg"
156
- _ , err := makeTestReq (testURL , 404 )
174
+ _ , err := makeTestReq (testURL , 404 , camoConfig )
157
175
assert .Nil (t , err )
158
176
}
159
177
160
178
func Test404ImageLargerThan5MB (t * testing.T ) {
161
179
t .Parallel ()
162
180
testURL := "http://apod.nasa.gov/apod/image/0505/larryslookout_spirit_big.jpg"
163
- _ , err := makeTestReq (testURL , 404 )
181
+ _ , err := makeTestReq (testURL , 404 , camoConfig )
164
182
assert .Nil (t , err )
165
183
}
166
184
167
185
func Test404HostNotFound (t * testing.T ) {
168
186
t .Parallel ()
169
187
testURL := "http://flabergasted.cx"
170
- _ , err := makeTestReq (testURL , 404 )
188
+ _ , err := makeTestReq (testURL , 404 , camoConfig )
171
189
assert .Nil (t , err )
172
190
}
173
191
174
192
func Test404OnExcludes (t * testing.T ) {
175
193
t .Parallel ()
176
194
testURL := "http://iphone.internal.example.org/foo.cgi"
177
- _ , err := makeTestReq (testURL , 404 )
195
+ _ , err := makeTestReq (testURL , 404 , camoConfig )
178
196
assert .Nil (t , err )
179
197
}
180
198
181
199
func Test404OnNonImageContent (t * testing.T ) {
182
200
t .Parallel ()
183
201
testURL := "https://github.com/atmos/cinderella/raw/master/bootstrap.sh"
184
- _ , err := makeTestReq (testURL , 404 )
202
+ _ , err := makeTestReq (testURL , 404 , camoConfig )
185
203
assert .Nil (t , err )
186
204
}
187
205
188
206
func Test404On10xIpRange (t * testing.T ) {
189
207
t .Parallel ()
190
208
testURL := "http://10.0.0.1/foo.cgi"
191
- _ , err := makeTestReq (testURL , 404 )
209
+ _ , err := makeTestReq (testURL , 404 , camoConfig )
192
210
assert .Nil (t , err )
193
211
}
194
212
195
213
func Test404On169Dot254Net (t * testing.T ) {
196
214
t .Parallel ()
197
215
testURL := "http://169.254.0.1/foo.cgi"
198
- _ , err := makeTestReq (testURL , 404 )
216
+ _ , err := makeTestReq (testURL , 404 , camoConfig )
199
217
assert .Nil (t , err )
200
218
}
201
219
202
220
func Test404On172Dot16Net (t * testing.T ) {
203
221
t .Parallel ()
204
222
for i := 16 ; i < 32 ; i ++ {
205
223
testURL := "http://172.%d.0.1/foo.cgi"
206
- _ , err := makeTestReq (fmt .Sprintf (testURL , i ), 404 )
224
+ _ , err := makeTestReq (fmt .Sprintf (testURL , i ), 404 , camoConfig )
207
225
assert .Nil (t , err )
208
226
}
209
227
}
210
228
211
229
func Test404On192Dot168Net (t * testing.T ) {
212
230
t .Parallel ()
213
231
testURL := "http://192.168.0.1/foo.cgi"
214
- _ , err := makeTestReq (testURL , 404 )
232
+ _ , err := makeTestReq (testURL , 404 , camoConfig )
215
233
assert .Nil (t , err )
216
234
}
217
235
218
236
func Test404OnLocalhost (t * testing.T ) {
219
237
t .Parallel ()
220
238
testURL := "http://localhost/foo.cgi"
221
- record , err := makeTestReq (testURL , 404 )
239
+ record , err := makeTestReq (testURL , 404 , camoConfig )
222
240
if assert .Nil (t , err ) {
223
241
assert .Equal (t , "Bad url host\n " , record .Body .String (), "Expected 404 response body but got '%s' instead" , record .Body .String ())
224
242
}
@@ -228,7 +246,7 @@ func Test404OnLocalhost(t *testing.T) {
228
246
func Test404OnLoopback (t * testing.T ) {
229
247
t .Parallel ()
230
248
testURL := "http://i.i.com.com/foo.cgi"
231
- record , err := makeTestReq (testURL , 404 )
249
+ record , err := makeTestReq (testURL , 404 , camoConfig )
232
250
if assert .Nil (t , err ) {
233
251
assert .Equal (t , "Denylist host failure\n " , record .Body .String (), "Expected 404 response body but got '%s' instead" , record .Body .String ())
234
252
}
0 commit comments