|
|
@@ -340,6 +340,22 @@ func TestIBMSecretManagerGetSecret(t *testing.T) {
|
|
|
}
|
|
|
setSecretCert := funcSetCertSecretTest(importedCert, "good case: imported_cert type with property", sm.Secret_SecretType_ImportedCert, true)
|
|
|
|
|
|
+ // good case: imported_cert type without a private_key
|
|
|
+ importedCertNoPvtKey := func(smtc *secretManagerTestCase) {
|
|
|
+ secret := &sm.ImportedCertificate{
|
|
|
+ SecretType: utilpointer.To(sm.Secret_SecretType_ImportedCert),
|
|
|
+ Name: utilpointer.To("testyname"),
|
|
|
+ ID: utilpointer.To(secretUUID),
|
|
|
+ Certificate: utilpointer.To(secretCertificate),
|
|
|
+ }
|
|
|
+ smtc.name = "good case: imported cert without private key"
|
|
|
+ smtc.apiInput.ID = utilpointer.To(secretUUID)
|
|
|
+ smtc.apiOutput = secret
|
|
|
+ smtc.ref.Key = "imported_cert/" + secretUUID
|
|
|
+ smtc.ref.Property = "private_key"
|
|
|
+ smtc.expectedSecret = ""
|
|
|
+ }
|
|
|
+
|
|
|
// bad case: imported_cert type without property
|
|
|
badSecretCert := funcSetCertSecretTest(importedCert, "bad case: imported_cert type without property", sm.Secret_SecretType_ImportedCert, false)
|
|
|
|
|
|
@@ -493,6 +509,7 @@ func TestIBMSecretManagerGetSecret(t *testing.T) {
|
|
|
makeValidSecretManagerTestCaseCustom(setSecretKVWithOutKey),
|
|
|
makeValidSecretManagerTestCaseCustom(badSecretKV),
|
|
|
makeValidSecretManagerTestCaseCustom(badSecretCert),
|
|
|
+ makeValidSecretManagerTestCaseCustom(importedCertNoPvtKey),
|
|
|
makeValidSecretManagerTestCaseCustom(setSecretPublicCert),
|
|
|
makeValidSecretManagerTestCaseCustom(badSecretPublicCert),
|
|
|
makeValidSecretManagerTestCaseCustom(setSecretPrivateCert),
|
|
|
@@ -500,16 +517,16 @@ func TestIBMSecretManagerGetSecret(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
sm := providerIBM{}
|
|
|
- for k, v := range successCases {
|
|
|
+ for _, v := range successCases {
|
|
|
t.Run(v.name, func(t *testing.T) {
|
|
|
sm.IBMClient = v.mockClient
|
|
|
sm.cache = NewCache(10, 1*time.Minute)
|
|
|
out, err := sm.GetSecret(context.Background(), *v.ref)
|
|
|
if !ErrorContains(err, v.expectError) {
|
|
|
- t.Errorf("[%d] unexpected error: %s, expected: '%s'", k, err.Error(), v.expectError)
|
|
|
+ t.Errorf("unexpected error:\n%s, expected:\n'%s'", err.Error(), v.expectError)
|
|
|
}
|
|
|
if string(out) != v.expectedSecret {
|
|
|
- t.Errorf("[%d] unexpected secret: expected %s, got %s", k, v.expectedSecret, string(out))
|
|
|
+ t.Errorf("unexpected secret: expected:\n%s\ngot:\n%s", v.expectedSecret, string(out))
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
@@ -779,6 +796,29 @@ func TestGetSecretMap(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // good case: imported_cert without a private_key
|
|
|
+ setimportedCertWithNoPvtKey := func(smtc *secretManagerTestCase) {
|
|
|
+ secret := &sm.ImportedCertificate{
|
|
|
+ CreatedBy: utilpointer.To("testCreatedBy"),
|
|
|
+ CreatedAt: &strfmt.DateTime{},
|
|
|
+ Downloaded: utilpointer.To(false),
|
|
|
+ Labels: []string{"abc", "def", "xyz"},
|
|
|
+ LocksTotal: utilpointer.To(int64(20)),
|
|
|
+ Certificate: utilpointer.To(secretCertificate),
|
|
|
+ Intermediate: utilpointer.To(secretIntermediate),
|
|
|
+ }
|
|
|
+ smtc.name = "good case: imported_cert without private key"
|
|
|
+ smtc.apiInput.ID = utilpointer.To(secretUUID)
|
|
|
+ smtc.apiOutput = secret
|
|
|
+ smtc.ref.Key = "imported_cert/" + secretUUID
|
|
|
+
|
|
|
+ smtc.expectedData = map[string][]byte{
|
|
|
+ "certificate": []byte(secretCertificate),
|
|
|
+ "intermediate": []byte(secretIntermediate),
|
|
|
+ "private_key": []byte(""),
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// good case: public_cert with metadata
|
|
|
setPublicCertWithMetadata := func(smtc *secretManagerTestCase) {
|
|
|
secret := &sm.PublicCertificate{
|
|
|
@@ -992,6 +1032,7 @@ func TestGetSecretMap(t *testing.T) {
|
|
|
makeValidSecretManagerTestCaseCustom(badSecretKVWithUnknownProperty),
|
|
|
makeValidSecretManagerTestCaseCustom(setSecretPublicCert),
|
|
|
makeValidSecretManagerTestCaseCustom(setSecretPrivateCert),
|
|
|
+ makeValidSecretManagerTestCaseCustom(setimportedCertWithNoPvtKey),
|
|
|
makeValidSecretManagerTestCaseCustom(setSecretIamWithMetadata),
|
|
|
makeValidSecretManagerTestCaseCustom(setArbitraryWithMetadata),
|
|
|
makeValidSecretManagerTestCaseCustom(setSecretUserPassWithMetadata),
|
|
|
@@ -1003,15 +1044,15 @@ func TestGetSecretMap(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
sm := providerIBM{}
|
|
|
- for k, v := range successCases {
|
|
|
+ for _, v := range successCases {
|
|
|
t.Run(v.name, func(t *testing.T) {
|
|
|
sm.IBMClient = v.mockClient
|
|
|
out, err := sm.GetSecretMap(context.Background(), *v.ref)
|
|
|
if !ErrorContains(err, v.expectError) {
|
|
|
- t.Errorf(" unexpected error: %s, expected: '%s'", err.Error(), v.expectError)
|
|
|
+ t.Errorf("unexpected error: %s, expected: '%s'", err.Error(), v.expectError)
|
|
|
}
|
|
|
if err == nil && !reflect.DeepEqual(out, v.expectedData) {
|
|
|
- t.Errorf("[%d] unexpected secret data: expected %+v, got %v", k, v.expectedData, out)
|
|
|
+ t.Errorf("unexpected secret data: expected:\n%+v\ngot:\n%+v", v.expectedData, out)
|
|
|
}
|
|
|
})
|
|
|
}
|