Skip to content

Commit

Permalink
fix: correct date parsing in case of null value
Browse files Browse the repository at this point in the history
  • Loading branch information
fritterhoff committed Aug 9, 2023
1 parent 943716b commit 3ce2968
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions sectigo/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ func TestClientService_Collect(t *testing.T) {
assert.Equal(t, "Test", *cert)
}

func TestClientService_ListByEmailNil(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder("GET", "https://cert-manager.com/api/smime/v2/byPersonEmail/foobar%40test.de", httpmock.NewStringResponder(200, `[{ "id": 1, "state": "rejected", "certificateDetails": {}, "serialNumber": "", "orderNumber": 0, "backendCertId": null, "expires": null}]`))
logger, _ := zap.NewProduction()
c := NewClient(http.DefaultClient, logger, "", "", "")
list, err := c.ClientService.ListByEmail("[email protected]")
assert.Nil(t, err)
assert.Equal(t, 1, httpmock.GetTotalCallCount())
assert.Len(t, *list, 1)
}
func TestClientService_ListByEmail(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
Expand Down
3 changes: 3 additions & 0 deletions sectigo/misc/date.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ type JSONDate struct {
// The time is expected to be a quoted string in the format YYYY-MM-DD.
func (t *JSONDate) UnmarshalJSON(buf []byte) error {
val := strings.Trim(string(buf), `"`)
if val == "null" {
return nil
}
tt, err := time.Parse("2006-01-02", val)
if err != nil {
return err
Expand Down

0 comments on commit 3ce2968

Please sign in to comment.