diff --git a/pkg/enterpriseclient/client.go b/pkg/enterpriseclient/client.go index 68bc35508..c474b4119 100644 --- a/pkg/enterpriseclient/client.go +++ b/pkg/enterpriseclient/client.go @@ -25,13 +25,15 @@ func New(privateKeyContents []byte) *HTTPClient { } func NewHTTPClient(origin string, privateKeyContents []byte) *HTTPClient { - privateKey, err := decodePrivateKeyPEM(privateKeyContents) - if err != nil { - privateKey = nil - } c := &HTTPClient{ - privateKey: privateKey, - apiOrigin: origin, + apiOrigin: origin, + } + if privateKeyContents != nil { + privateKey, err := decodePrivateKeyPEM(privateKeyContents) + if err != nil { + privateKey = nil + } + c.privateKey = privateKey } return c diff --git a/pkg/enterpriseclient/client_test.go b/pkg/enterpriseclient/client_test.go new file mode 100644 index 000000000..70e1a20b2 --- /dev/null +++ b/pkg/enterpriseclient/client_test.go @@ -0,0 +1,16 @@ +package enterpriseclient + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestNewNilHTTPClient(t *testing.T) { + req := require.New(t) + client := NewHTTPClient("origin", nil) + req.Equal(&HTTPClient{ + privateKey: nil, + apiOrigin: "origin", + }, client) +}