Skip to content

Commit

Permalink
store: reword panic message and add test to check httputil client has…
Browse files Browse the repository at this point in the history
… CheckRedirect defined

Signed-off-by: Zeyad Gouda <[email protected]>
  • Loading branch information
ZeyadYasser authored and pedronis committed Aug 9, 2023
1 parent e8c7ba5 commit 0cb8e9d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions httputil/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ func (s *clientSuite) TestClientProxyTakesUserAgent(c *check.C) {
c.Assert(called, check.Equals, true)
}

func (s *clientSuite) TestClientCheckRedirect(c *check.C) {
cli := httputil.NewHTTPClient(&httputil.ClientOptions{})
c.Assert(cli, check.NotNil)
c.Assert(cli.CheckRedirect, check.NotNil)
}

var privKey, _ = rsa.GenerateKey(rand.Reader, 768)

// see crypto/tls/generate_cert.go
Expand Down
2 changes: 1 addition & 1 deletion store/store_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ func downloadImpl(ctx context.Context, name, sha3_384, downloadURL string, user
cli := s.newHTTPClient(nil)
oldCheckRedirect := cli.CheckRedirect
if oldCheckRedirect == nil {
panic("internal error: CheckRedirect cannot be nil")
panic("internal error: the httputil.NewHTTPClient-produced http.Client must have CheckRedirect defined")
}
cli.CheckRedirect = func(req *http.Request, via []*http.Request) error {
// remove user/device auth headers from being sent in "CDN" redirects
Expand Down
2 changes: 1 addition & 1 deletion store/store_download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ func (s *storeDownloadSuite) TestDownloadNoCheckRedirectPanic(c *C) {
downloadFunc := func() {
s.store.Download(s.ctx, "foo", targetFn, &snap.DownloadInfo{}, nil, nil, nil)
}
c.Assert(downloadFunc, PanicMatches, "internal error: CheckRedirect cannot be nil")
c.Assert(downloadFunc, PanicMatches, "internal error: the httputil.NewHTTPClient-produced http.Client must have CheckRedirect defined")
}

func (s *storeDownloadSuite) TestDownloadInfiniteRedirect(c *C) {
Expand Down

0 comments on commit 0cb8e9d

Please sign in to comment.