Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

Commit

Permalink
prevent nil pointer exceptions on keys
Browse files Browse the repository at this point in the history
Signed-off-by: Liam White <liam@tetrate.io>
  • Loading branch information
liamawhite committed Aug 2, 2019
1 parent 98f2a01 commit b6e2d1a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/manifest/locate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/manifest/locate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down

0 comments on commit b6e2d1a

Please sign in to comment.