From 3ce2968da49d3a9821519071ed5a7dfd97def1b1 Mon Sep 17 00:00:00 2001 From: Florian Ritterhoff Date: Wed, 9 Aug 2023 19:06:09 +0200 Subject: [PATCH] fix: correct date parsing in case of null value --- sectigo/client_test.go | 11 +++++++++++ sectigo/misc/date.go | 3 +++ 2 files changed, 14 insertions(+) diff --git a/sectigo/client_test.go b/sectigo/client_test.go index 41c0433..f66097a 100644 --- a/sectigo/client_test.go +++ b/sectigo/client_test.go @@ -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("foobar@test.de") + 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() diff --git a/sectigo/misc/date.go b/sectigo/misc/date.go index 56988d3..42f3905 100644 --- a/sectigo/misc/date.go +++ b/sectigo/misc/date.go @@ -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