|
|
@@ -278,12 +278,12 @@ func TestIBMSecretManagerGetSecret(t *testing.T) {
|
|
|
|
|
|
// bad case: arbitrary type secret which is destroyed
|
|
|
badArbitSecret := func(smtc *secretManagerTestCase) {
|
|
|
- secret := &sm.UsernamePasswordSecret{
|
|
|
- SecretType: utilpointer.To(sm.Secret_SecretType_UsernamePassword),
|
|
|
+ secret := &sm.ArbitrarySecret{
|
|
|
+ SecretType: utilpointer.To(sm.Secret_SecretType_Arbitrary),
|
|
|
Name: utilpointer.To("testyname"),
|
|
|
ID: utilpointer.To(secretUUID),
|
|
|
}
|
|
|
- smtc.name = "bad case: username_password type without property"
|
|
|
+ smtc.name = "bad case: arbitrary type without property"
|
|
|
smtc.apiInput.ID = utilpointer.To(secretUUID)
|
|
|
smtc.apiOutput = secret
|
|
|
smtc.ref.Key = secretUUID
|
|
|
@@ -387,6 +387,36 @@ func TestIBMSecretManagerGetSecret(t *testing.T) {
|
|
|
}
|
|
|
setSecretIamByNameNew := funcSetSecretIamNew("testyname", "testGroup", "good case: iam_credenatials type - get API Key by name - new mechanism")
|
|
|
|
|
|
+ // good case: service_credentials type
|
|
|
+ dummySrvCreds := &sm.ServiceCredentialsSecretCredentials{
|
|
|
+ Apikey: &secretAPIKey,
|
|
|
+ }
|
|
|
+
|
|
|
+ funcSetSecretSrvCred := func(secretName, name string) func(*secretManagerTestCase) {
|
|
|
+ return func(smtc *secretManagerTestCase) {
|
|
|
+ secret := &sm.ServiceCredentialsSecret{
|
|
|
+ SecretType: utilpointer.To(sm.Secret_SecretType_ServiceCredentials),
|
|
|
+ Name: utilpointer.To("testyname"),
|
|
|
+ ID: utilpointer.To(secretUUID),
|
|
|
+ Credentials: dummySrvCreds,
|
|
|
+ }
|
|
|
+ secretMetadata := &sm.ServiceCredentialsSecretMetadata{
|
|
|
+ Name: utilpointer.To("testyname"),
|
|
|
+ ID: utilpointer.To(secretUUID),
|
|
|
+ }
|
|
|
+ smtc.apiInput.ID = utilpointer.To(secretUUID)
|
|
|
+ smtc.name = name
|
|
|
+ smtc.apiOutput = secret
|
|
|
+ smtc.listInput.Search = utilpointer.To("testyname")
|
|
|
+ smtc.listOutput.Secrets = make([]sm.SecretMetadataIntf, 1)
|
|
|
+ smtc.listOutput.Secrets[0] = secretMetadata
|
|
|
+ smtc.ref.Key = "service_credentials/" + secretName
|
|
|
+ smtc.expectedSecret = "{\"apikey\":\"01234567890\"}"
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ setSecretSrvCredByID := funcSetSecretSrvCred(secretUUID, "good case: service_credentials type - get creds by ID")
|
|
|
+
|
|
|
funcSetCertSecretTest := func(secret sm.SecretIntf, name, certType string, good bool) func(*secretManagerTestCase) {
|
|
|
return func(smtc *secretManagerTestCase) {
|
|
|
smtc.name = name
|
|
|
@@ -589,6 +619,7 @@ func TestIBMSecretManagerGetSecret(t *testing.T) {
|
|
|
makeValidSecretManagerTestCaseCustom(setSecretPrivateCert),
|
|
|
makeValidSecretManagerTestCaseCustom(badSecretPrivateCert),
|
|
|
makeValidSecretManagerTestCaseCustom(setSecretIamByNameNew),
|
|
|
+ makeValidSecretManagerTestCaseCustom(setSecretSrvCredByID),
|
|
|
}
|
|
|
|
|
|
sm := providerIBM{}
|
|
|
@@ -628,6 +659,10 @@ func TestGetSecretMap(t *testing.T) {
|
|
|
},
|
|
|
}
|
|
|
|
|
|
+ dummySrvCreds := &sm.ServiceCredentialsSecretCredentials{
|
|
|
+ Apikey: &secretAPIKey,
|
|
|
+ }
|
|
|
+
|
|
|
// good case: arbitrary
|
|
|
setArbitrary := func(smtc *secretManagerTestCase) {
|
|
|
payload := `{"foo":"bar"}`
|
|
|
@@ -721,6 +756,21 @@ func TestGetSecretMap(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //good case: service_credentials
|
|
|
+ setSecretSrvCreds := func(smtc *secretManagerTestCase) {
|
|
|
+ secret := &sm.ServiceCredentialsSecret{
|
|
|
+ Name: utilpointer.To("testyname"),
|
|
|
+ ID: utilpointer.To(secretUUID),
|
|
|
+ SecretType: utilpointer.To(sm.Secret_SecretType_IamCredentials),
|
|
|
+ Credentials: dummySrvCreds,
|
|
|
+ }
|
|
|
+ smtc.name = "good case: service_credentials"
|
|
|
+ smtc.apiInput.ID = utilpointer.To(secretUUID)
|
|
|
+ smtc.apiOutput = secret
|
|
|
+ smtc.ref.Key = "service_credentials/" + secretUUID
|
|
|
+ smtc.expectedData["credentials"] = []byte(fmt.Sprintf("%+v", map[string]string{"apikey": secretAPIKey}))
|
|
|
+ }
|
|
|
+
|
|
|
// good case: imported_cert
|
|
|
importedCert := &sm.ImportedCertificate{
|
|
|
SecretType: utilpointer.To(sm.Secret_SecretType_ImportedCert),
|
|
|
@@ -1131,6 +1181,7 @@ func TestGetSecretMap(t *testing.T) {
|
|
|
|
|
|
successCases := []*secretManagerTestCase{
|
|
|
makeValidSecretManagerTestCaseCustom(badSecretIam),
|
|
|
+ makeValidSecretManagerTestCaseCustom(setSecretSrvCreds),
|
|
|
makeValidSecretManagerTestCaseCustom(setArbitrary),
|
|
|
makeValidSecretManagerTestCaseCustom(setNilMockClient),
|
|
|
makeValidSecretManagerTestCaseCustom(setAPIErr),
|