From b6e2d1a848b58c61110025d5b15e615fb560b761 Mon Sep 17 00:00:00 2001 From: Liam White Date: Fri, 2 Aug 2019 08:28:08 +0100 Subject: [PATCH] prevent nil pointer exceptions on keys Signed-off-by: Liam White --- pkg/manifest/locate.go | 3 +++ pkg/manifest/locate_test.go | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/pkg/manifest/locate.go b/pkg/manifest/locate.go index 4d7bc3e..2eee541 100644 --- a/pkg/manifest/locate.go +++ b/pkg/manifest/locate.go @@ -53,6 +53,9 @@ type Key struct { // The build version is searched for as a prefix of the OperatingSystemVersion. // If the OperatingSystemVersion is empty it returns the first build listed for that operating system func Locate(key *Key, manifestLocation string) (string, error) { + if key == nil { + return "", errors.New("passed key was nil") + } if u, err := url.Parse(manifestLocation); err != nil || u.Host == "" || u.Scheme == "" { return "", errors.New("only URL manifest locations are supported") } diff --git a/pkg/manifest/locate_test.go b/pkg/manifest/locate_test.go index 8f25d23..fd0a0d4 100644 --- a/pkg/manifest/locate_test.go +++ b/pkg/manifest/locate_test.go @@ -61,13 +61,20 @@ func TestLocate(t *testing.T) { responseStatusCode: http.StatusOK, wantErr: true, }, + { + name: "Error if passed nil key", + reference: "notAReference", + wantErr: true, + }, { name: "Error on non-url manifest locations", + reference: "standard:1.11.0", locationOverride: "not-a-url", wantErr: true, }, { name: "Error on failed fetch", + reference: "standard:1.11.0", responseStatusCode: http.StatusTeapot, wantErr: true, },