Skip to content

Commit

Permalink
fix: add Attributes.Created
Browse files Browse the repository at this point in the history
  • Loading branch information
duffney committed Nov 27, 2024
1 parent df398f4 commit ccf970c
Showing 1 changed file with 26 additions and 66 deletions.
92 changes: 26 additions & 66 deletions pkg/keymanagementprovider/azurekeyvault/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -222,6 +223,9 @@ func (m *MockKeyKVClient) NewListKeyVersionsPager(keyName string, options *azkey
Value: []*azkeys.KeyItem{
{
KID: &keyID,
Attributes: &azkeys.KeyAttributes{
Created: &KeyCreated,
},
},
},
},
Expand Down Expand Up @@ -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
Expand All @@ -262,6 +267,9 @@ func (m *MockCertificateKVClient) NewListCertificateVersionsPager(certificateNam
Value: []*azcertificates.CertificateItem{
{
ID: &certID,
Attributes: &azcertificates.CertificateAttributes{
Created: &CertCreated,
},
},
},
},
Expand All @@ -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
Expand All @@ -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
},
Expand All @@ -324,6 +331,10 @@ func TestGetCertificates(t *testing.T) {
Value: []*azcertificates.CertificateItem{
{
ID: &certID,
Attributes: &azcertificates.CertificateAttributes{
Enabled: boolPtr(true),
Created: &certIDCreated,
},
},
},
},
Expand All @@ -337,6 +348,10 @@ func TestGetCertificates(t *testing.T) {
Value: []*azcertificates.CertificateItem{
{
ID: &certIDLatest,
Attributes: &azcertificates.CertificateAttributes{
Enabled: boolPtr(true),
Created: &certIDLatestCreated,
},
},
},
},
Expand Down Expand Up @@ -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\ntveuaBbamdlFkD+53TZeZlxt3GIdq93Iw/UpbQ/pvhbrztMT+UVEkm15sShfX8Xn\nL2st5A4n0V+66QIDAQABoyAwH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7/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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -570,6 +524,9 @@ func TestGetKeys(t *testing.T) {
Value: []*azkeys.KeyItem{
{
KID: &keyID,
Attributes: &azkeys.KeyAttributes{
Created: &keyCreated,
},
},
},
},
Expand All @@ -582,6 +539,9 @@ func TestGetKeys(t *testing.T) {
Value: []*azkeys.KeyItem{
{
KID: &keyIDLatest,
Attributes: &azkeys.KeyAttributes{
Created: &keyCreatedLatest,
},
},
},
},
Expand Down

0 comments on commit ccf970c

Please sign in to comment.