From 1bc2ce6aa160de68fab08e2b01f7feceef5c561e Mon Sep 17 00:00:00 2001 From: elij Date: Tue, 18 Jun 2024 14:16:20 -0700 Subject: [PATCH] add test --- pkg/camo/proxy_test.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/pkg/camo/proxy_test.go b/pkg/camo/proxy_test.go index e1a7b6c..a3110e1 100644 --- a/pkg/camo/proxy_test.go +++ b/pkg/camo/proxy_test.go @@ -214,7 +214,6 @@ func TestVideoContentTypeAllowed(t *testing.T) { // bump limit, try again (should succeed) camoConfigWithVideo.MaxSize = 5000 * 1024 _, err = makeTestReq(testURL, 200, camoConfigWithVideo) - // fmt.Println(err) assert.Check(t, err) } @@ -260,6 +259,30 @@ func TestCredetialURLsAllowed(t *testing.T) { assert.Check(t, err) } +func TestMaxSizeRedirect(t *testing.T) { + t.Parallel() + + camoConfigWithMaxSizeRedirect := Config{ + HMACKey: []byte("0x24FEEDFACEDEADBEEFCAFE"), + MaxSize: 1 * 1024, + RequestTimeout: time.Duration(10) * time.Second, + MaxRedirects: 3, + MaxSizeRedirect: "http://example.com/some-image.png", + ServerName: "go-camo", + AllowContentVideo: true, + } + + testURL := "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerEscapes.mp4" + + // try a range request (should fail, MaxSize is smaller than requested range) + req, err := makeReq(camoConfigWithMaxSizeRedirect, testURL) + assert.Check(t, err) + req.Header.Add("Range", "bytes=0-1025") + resp, err := processRequest(req, 302, camoConfigWithMaxSizeRedirect, nil) + assert.Check(t, is.Equal(resp.Header.Get("Location"), camoConfigWithMaxSizeRedirect.MaxSizeRedirect)) + assert.Check(t, err) +} + func TestSupplyAcceptIfNoneGiven(t *testing.T) { t.Parallel() testURL := "http://images.anandtech.com/doci/6673/OpenMoboAMD30_575px.png"