Skip to content

Commit

Permalink
fixes nil pointer exception and removed test that did not make sense …
Browse files Browse the repository at this point in the history
…anymore due to implementation
  • Loading branch information
luispresuelVenafi committed Feb 28, 2024
1 parent 39dabb9 commit 65fb8eb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
6 changes: 6 additions & 0 deletions pkg/venafi/cloud/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,9 @@ func (c *Connector) RequestCertificate(req *certificate.Request) (requestID stri

// We set timeout for the http client
if req.Timeout != 0 {
if c.client == nil {
c.client = &http.Client{}
}
c.client.Timeout = req.Timeout
}
statusCode, status, body, err := c.request("POST", url, cloudReq)
Expand Down Expand Up @@ -901,6 +904,9 @@ func (c *Connector) SupportSynchronousRequestCertificate() bool {
func (c *Connector) RetrieveCertificate(req *certificate.Request) (certificates *certificate.PEMCollection, err error) {
// We set timeout for the http client
if req.Timeout != 0 {
if c.client == nil {
c.client = &http.Client{}
}
c.client.Timeout = req.Timeout
}
if req.PickupID == "" && req.CertID == "" && req.Thumbprint != "" {
Expand Down
6 changes: 6 additions & 0 deletions pkg/venafi/tpp/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,9 @@ func (c *Connector) RequestCertificate(req *certificate.Request) (requestID stri
// - for the Go HTTP client
// In the following we will add for the http client
if req.Timeout != 0 {
if c.client == nil {
c.client = &http.Client{}
}
c.client.Timeout = req.Timeout
}

Expand Down Expand Up @@ -1350,6 +1353,9 @@ func (c *Connector) RetrieveCertificate(req *certificate.Request) (certificates
// In the following we will add for the http client

if req.Timeout != 0 {
if c.client == nil {
c.client = &http.Client{}
}
c.client.Timeout = req.Timeout
}

Expand Down
9 changes: 0 additions & 9 deletions pkg/venafi/tpp/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -901,15 +901,6 @@ func TestRetrieveCertificate(t *testing.T) {
givenTimeout: 3 * time.Second,
expectErr: "unable to retrieve: Unexpected status code on TPP Certificate Retrieval. Status: 500 Certificate \\VED\\Policy\\TLS/SSL\\aexample.com has encountered an error while processing, Status: Post CSR failed with error: Cannot connect to the certificate authority (CA), Stage: 500.",
},
{
name: "should fail when timeout too small while waiting for the cert",
mockRetrieve: []mockResp{
{`202 Certificate \VED\Policy\TLS/SSL\aexample.com being processed, Status: Post CSR, Stage: 500.`,
`{"Stage": 500, "Status": "Post CSR"}`},
},
givenTimeout: 1 * time.Millisecond,
expectErr: "Operation timed out. You may try retrieving the certificate later using Pickup ID: \\VED\\Policy\\Test\\bexample.com",
},
}

serverWith := func(mockRetrieve []mockResp) (_ *httptest.Server, retrieveCount *int32) {
Expand Down

0 comments on commit 65fb8eb

Please sign in to comment.