Skip to content

Commit

Permalink
handle nil private key in http client init
Browse files Browse the repository at this point in the history
  • Loading branch information
laverya committed Apr 29, 2020
1 parent 326496e commit df0cbb3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pkg/enterpriseclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions pkg/enterpriseclient/client_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit df0cbb3

Please sign in to comment.