From ccf970c483d334e3001564a7453a82635d67a7ab Mon Sep 17 00:00:00 2001 From: Josh Duffney Date: Wed, 27 Nov 2024 11:46:30 -0600 Subject: [PATCH] fix: add Attributes.Created --- .../azurekeyvault/provider_test.go | 92 ++++++------------- 1 file changed, 26 insertions(+), 66 deletions(-) diff --git a/pkg/keymanagementprovider/azurekeyvault/provider_test.go b/pkg/keymanagementprovider/azurekeyvault/provider_test.go index fe0246f10..2f3f015ff 100644 --- a/pkg/keymanagementprovider/azurekeyvault/provider_test.go +++ b/pkg/keymanagementprovider/azurekeyvault/provider_test.go @@ -209,6 +209,7 @@ func (m *MockKeyKVClient) NewListKeyVersionsPager(keyName string, options *azkey if m.NewListKeyVersionsPagerFunc != nil { return m.NewListKeyVersionsPagerFunc(keyName, options) } + KeyCreated := time.Now() return runtime.NewPager(runtime.PagingHandler[azkeys.ListKeyVersionsResponse]{ More: func(_ azkeys.ListKeyVersionsResponse) bool { return false @@ -222,6 +223,9 @@ func (m *MockKeyKVClient) NewListKeyVersionsPager(keyName string, options *azkey Value: []*azkeys.KeyItem{ { KID: &keyID, + Attributes: &azkeys.KeyAttributes{ + Created: &KeyCreated, + }, }, }, }, @@ -249,6 +253,7 @@ func (m *MockCertificateKVClient) NewListCertificateVersionsPager(certificateNam if m.NewListCertificateVersionsPagerFunc != nil { return m.NewListCertificateVersionsPagerFunc(certificateName, options) } + CertCreated := time.Now() return runtime.NewPager(runtime.PagingHandler[azcertificates.ListCertificateVersionsResponse]{ More: func(_ azcertificates.ListCertificateVersionsResponse) bool { return false @@ -262,6 +267,9 @@ func (m *MockCertificateKVClient) NewListCertificateVersionsPager(certificateNam Value: []*azcertificates.CertificateItem{ { ID: &certID, + Attributes: &azcertificates.CertificateAttributes{ + Created: &CertCreated, + }, }, }, }, @@ -284,7 +292,9 @@ func boolPtr(b bool) *bool { // TestGetCertificates tests the GetCertificates function func TestGetCertificates(t *testing.T) { certID := azcertificates.ID("https://testkv.vault.azure.net/certificates/cert1/d47a1c09f5b6437da28e9c72b1f4e0fd") + certIDCreated := time.Now() certIDLatest := azcertificates.ID("https://testkv.vault.azure.net/certificates/cert1/8f2e5a13c4b74960d7a8e2f1c0d6b3a9") + certIDLatestCreated := time.Now().Add(1 * time.Minute) secretID := azsecrets.ID("https://testkv.vault.azure.net/secrets/secret1") testCases := []struct { name string @@ -302,9 +312,6 @@ func TestGetCertificates(t *testing.T) { CertificateBundle: azcertificates.CertificateBundle{ ID: &certID, KID: stringPtr("https://testkv.vault.azure.net/keys/key1"), - Attributes: &azcertificates.CertificateAttributes{ - Enabled: boolPtr(true), - }, }, }, nil }, @@ -324,6 +331,10 @@ func TestGetCertificates(t *testing.T) { Value: []*azcertificates.CertificateItem{ { ID: &certID, + Attributes: &azcertificates.CertificateAttributes{ + Enabled: boolPtr(true), + Created: &certIDCreated, + }, }, }, }, @@ -337,6 +348,10 @@ func TestGetCertificates(t *testing.T) { Value: []*azcertificates.CertificateItem{ { ID: &certIDLatest, + Attributes: &azcertificates.CertificateAttributes{ + Enabled: boolPtr(true), + Created: &certIDLatestCreated, + }, }, }, }, @@ -416,69 +431,6 @@ func TestGetCertificates(t *testing.T) { }, expectedErr: false, }, - // { - // name: "Certificate disabled error", - // versionHistoryLimit: 1, - // mockCertificateKVClient: &MockCertificateKVClient{ - // GetCertificateFunc: func(_ context.Context, _ string, _ string) (azcertificates.GetCertificateResponse, error) { - // return azcertificates.GetCertificateResponse{}, errors.New("error") - // }, - // }, - // mockSecretKVClient: &MockSecretKVClient{ - // GetSecretFunc: func(_ context.Context, _ string, _ string) (azsecrets.GetSecretResponse, error) { - // rawResponse := `{ - // "error": { - // "code": "Forbidden", - // "message": "Operation get is not allowed on a disabled secret.", - // "innererror": { - // "code": "SecretDisabled" - // } - // } - // }` - - // httpErr := &azcore.ResponseError{ - // StatusCode: http.StatusForbidden, - // RawResponse: &http.Response{ - // Body: io.NopCloser(strings.NewReader(rawResponse)), - // }, - // } - // return azsecrets.GetSecretResponse{}, httpErr - // }, - // }, - // expectedErr: true, - // }, - // { - // name: "Certificate enabled", - // mockCertificateKVClient: &MockCertificateKVClient{ - // GetCertificateFunc: func(_ context.Context, _ string, _ string) (azcertificates.GetCertificateResponse, error) { - // return azcertificates.GetCertificateResponse{ - // CertificateBundle: azcertificates.CertificateBundle{ - // ID: &certID, - // KID: stringPtr("https://testkv.vault.azure.net/keys/key1"), - // Attributes: &azcertificates.CertificateAttributes{ - // Enabled: boolPtr(true), - // }, - // }, - // }, nil - // }, - // }, - // mockSecretKVClient: &MockSecretKVClient{ - // GetSecretFunc: func(_ context.Context, _ string, _ string) (azsecrets.GetSecretResponse, error) { - // return azsecrets.GetSecretResponse{ - // SecretBundle: azsecrets.SecretBundle{ - // ID: &secretID, - // Kid: stringPtr("https://testkv.vault.azure.net/keys/key1"), - // ContentType: stringPtr("application/x-pem-file"), - // Attributes: &azsecrets.SecretAttributes{ - // Enabled: boolPtr(true), - // }, - // Value: stringPtr("-----BEGIN CERTIFICATE-----\nMIIC8TCCAdmgAwIBAgIUaNrwbhs/I1ecqUYdzD2xuAVNdmowDQYJKoZIhvcNAQEL\nBQAwKjEPMA0GA1UECgwGUmF0aWZ5MRcwFQYDVQQDDA5SYXRpZnkgUm9vdCBDQTAe\nFw0yMzA2MjEwMTIyMzdaFw0yNDA2MjAwMTIyMzdaMBkxFzAVBgNVBAMMDnJhdGlm\neS5kZWZhdWx0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtskG1BUt\n4Fw2lbm53KbwZb1hnLmWdwRotZyznhhk/yrUDcq3uF6klwpk/E2IKfUKIo6doHSk\nXaEZXR68UtXygvA4wdg7xZ6kKpXy0gu+RxGE6CGtDHTyDDzITu+NBjo21ZSsyGpQ\nJeIKftUCHdwdygKf0CdJx8A29GBRpHGCmJadmt7tTzOnYjmbuPVLeqJo/Ex9qXcG\nZbxoxnxr5NCocFeKx+EbLo+k/KjdFB2PKnhgzxAaMMMP6eXPr8l5AlzkC83EmPvN\ntveuaBbam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Er\nJn++iqN8na18a9DFBPTTrLPe3CxATGrMfosCMZ6LP3iFLLc/FaSpwcnugWdewsUK\nYs+sUY7jFWR7x7/1nyFWyRrQviM4f4TY+K7NAgMBAAGjYzBhMB0GA1UdDgQWBBQH\nYePW7QPP2p1utr3r6gqzEkKs+DAfBgNVHSMEGDAWgBQHYePW7QPP2p1utr3r6gqz\nEkKs+DAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwICBDANBgkqhkiG9w0B\nAQsFAAOCAQEAjKp4vx3bFaKVhAbQeTsDjWJgmXLK2vLgt74MiUwSF6t0wehlfszE\nIcJagGJsvs5wKFf91bnwiqwPjmpse/thPNBAxh1uEoh81tOklv0BN790vsVpq3t+\ncnUvWPiCZdRlAiGGFtRmKk3Keq4sM6UdiUki9s+wnxypHVb4wIpVxu5R271Lnp5I\n+rb2EQ48iblt4XZPczf/5QJdTgbItjBNbuO8WVPOqUIhCiFuAQziLtNUq3p81dHO\nQ2BPgmaitCpIUYHVYighLauBGCH8xOFzj4a4KbOxKdxyJTd0La/vRCKaUtJX67Lc\nfQYVR9HXQZ0YlmwPcmIG5v7wBfcW34NUvA==\n-----END CERTIFICATE-----\n"), - // }, - // }, nil - // }, - // }, - // expectedErr: false, - // }, { name: "getCertsFromSecretBundle error", versionHistoryLimit: 1, @@ -529,6 +481,8 @@ func TestGetCertificates(t *testing.T) { func TestGetKeys(t *testing.T) { keyID := azkeys.ID("https://testkv.vault.azure.net/keys/key1/c1f03df1113d460491d970737dfdc35d") keyIDLatest := azkeys.ID("https://testkv.vault.azure.net/keys/key1/8f2e5a13c4b74960d7a8e2f1c0d6b3a9") + keyCreated := time.Now() + keyCreatedLatest := time.Now().Add(1 * time.Minute) keyTY := azkeys.JSONWebKeyTypeRSA testCases := []struct { name string @@ -570,6 +524,9 @@ func TestGetKeys(t *testing.T) { Value: []*azkeys.KeyItem{ { KID: &keyID, + Attributes: &azkeys.KeyAttributes{ + Created: &keyCreated, + }, }, }, }, @@ -582,6 +539,9 @@ func TestGetKeys(t *testing.T) { Value: []*azkeys.KeyItem{ { KID: &keyIDLatest, + Attributes: &azkeys.KeyAttributes{ + Created: &keyCreatedLatest, + }, }, }, },