Skip to content

Commit

Permalink
[Heartbeat] Fix null pointer in zip url on retry (elastic#25288)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewvc committed Apr 23, 2021
1 parent f548f54 commit 42ad8ae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion x-pack/heartbeat/monitors/browser/source/zipurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func retryingZipRequest(method string, z *ZipURLSource) (resp *http.Response, er
}
time.Sleep(time.Second)
}
if resp.StatusCode > 300 {
if resp != nil && resp.StatusCode > 300 {
return nil, fmt.Errorf("failed to retrieve zip, received status of %d requesting zip URL", resp.StatusCode)
}
return resp, err
Expand Down
14 changes: 14 additions & 0 deletions x-pack/heartbeat/monitors/browser/source/zipurl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ func TestZipUrlWithSameEtag(t *testing.T) {
require.Equal(t, zus.TargetDirectory, target, "Target directory should be same")
}

func TestZipUrlWithBadUrl(t *testing.T) {
_, teardown := setupTests()
defer teardown()

zus := ZipURLSource{
URL: "http://notahost.notadomaintoehutoeuhn",
Folder: "/",
Retries: 2,
}
err := zus.Fetch()
defer zus.Close()
require.Error(t, err)
}

func setupTests() (addr string, teardown func()) {
// go offline, so we dont invoke npm install for unit tests
GoOffline()
Expand Down

0 comments on commit 42ad8ae

Please sign in to comment.