vault.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. limitations under the License.
  10. */
  11. package vault
  12. import (
  13. // nolint
  14. . "github.com/onsi/ginkgo"
  15. // nolint
  16. . "github.com/onsi/ginkgo/extensions/table"
  17. "github.com/external-secrets/external-secrets/e2e/framework"
  18. "github.com/external-secrets/external-secrets/e2e/suite/common"
  19. )
  20. var _ = Describe("[vault] ", func() {
  21. f := framework.New("eso-vault")
  22. DescribeTable("sync secrets",
  23. framework.TableFunc(f,
  24. newVaultProvider(f)),
  25. // uses token auth
  26. compose("with token auth", f, common.JSONDataFromSync, useTokenAuth),
  27. compose("with token auth", f, common.JSONDataWithProperty, useTokenAuth),
  28. compose("with token auth", f, common.JSONDataWithTemplate, useTokenAuth),
  29. compose("with token auth", f, common.DataPropertyDockerconfigJSON, useTokenAuth),
  30. compose("with token auth", f, common.JSONDataWithoutTargetName, useTokenAuth),
  31. // use cert auth
  32. compose("with cert auth", f, common.JSONDataFromSync, useCertAuth),
  33. compose("with cert auth", f, common.JSONDataWithProperty, useCertAuth),
  34. compose("with cert auth", f, common.JSONDataWithTemplate, useCertAuth),
  35. compose("with cert auth", f, common.DataPropertyDockerconfigJSON, useCertAuth),
  36. compose("with cert auth", f, common.JSONDataWithoutTargetName, useTokenAuth),
  37. // use approle auth
  38. compose("with appRole auth", f, common.JSONDataFromSync, useApproleAuth),
  39. compose("with appRole auth", f, common.JSONDataWithProperty, useApproleAuth),
  40. compose("with appRole auth", f, common.JSONDataWithTemplate, useApproleAuth),
  41. compose("with appRole auth", f, common.DataPropertyDockerconfigJSON, useApproleAuth),
  42. compose("with appRole auth", f, common.JSONDataWithoutTargetName, useTokenAuth),
  43. // use v1 provider
  44. compose("with v1 kv provider", f, common.JSONDataFromSync, useV1Provider),
  45. compose("with v1 kv provider", f, common.JSONDataWithProperty, useV1Provider),
  46. compose("with v1 kv provider", f, common.JSONDataWithTemplate, useV1Provider),
  47. compose("with v1 kv provider", f, common.DataPropertyDockerconfigJSON, useV1Provider),
  48. compose("with v1 kv provider", f, common.JSONDataWithoutTargetName, useTokenAuth),
  49. // use jwt provider
  50. compose("with jwt provider", f, common.JSONDataFromSync, useJWTProvider),
  51. compose("with jwt provider", f, common.JSONDataWithProperty, useJWTProvider),
  52. compose("with jwt provider", f, common.JSONDataWithTemplate, useJWTProvider),
  53. compose("with jwt provider", f, common.DataPropertyDockerconfigJSON, useJWTProvider),
  54. compose("with jwt provider", f, common.JSONDataWithoutTargetName, useTokenAuth),
  55. // use kubernetes provider
  56. compose("with kubernetes provider", f, common.JSONDataFromSync, useKubernetesProvider),
  57. compose("with kubernetes provider", f, common.JSONDataWithProperty, useKubernetesProvider),
  58. compose("with kubernetes provider", f, common.JSONDataWithTemplate, useKubernetesProvider),
  59. compose("with kubernetes provider", f, common.DataPropertyDockerconfigJSON, useKubernetesProvider),
  60. compose("with kubernetes provider", f, common.JSONDataWithoutTargetName, useTokenAuth),
  61. )
  62. })
  63. func compose(descAppend string, f *framework.Framework, fn func(f *framework.Framework) (string, func(*framework.TestCase)), tweaks ...func(*framework.TestCase)) TableEntry {
  64. desc, tfn := fn(f)
  65. tweaks = append(tweaks, tfn)
  66. te := Entry(desc + " " + descAppend)
  67. // need to convert []func to []interface{}
  68. ifs := make([]interface{}, len(tweaks))
  69. for i := 0; i < len(tweaks); i++ {
  70. ifs[i] = tweaks[i]
  71. }
  72. te.Parameters = ifs
  73. return te
  74. }
  75. func useTokenAuth(tc *framework.TestCase) {
  76. tc.ExternalSecret.Spec.SecretStoreRef.Name = tc.Framework.Namespace.Name
  77. }
  78. func useCertAuth(tc *framework.TestCase) {
  79. tc.ExternalSecret.Spec.SecretStoreRef.Name = certAuthProviderName
  80. }
  81. func useApproleAuth(tc *framework.TestCase) {
  82. tc.ExternalSecret.Spec.SecretStoreRef.Name = appRoleAuthProviderName
  83. }
  84. func useV1Provider(tc *framework.TestCase) {
  85. tc.ExternalSecret.Spec.SecretStoreRef.Name = kvv1ProviderName
  86. }
  87. func useJWTProvider(tc *framework.TestCase) {
  88. tc.ExternalSecret.Spec.SecretStoreRef.Name = jwtProviderName
  89. }
  90. func useKubernetesProvider(tc *framework.TestCase) {
  91. tc.ExternalSecret.Spec.SecretStoreRef.Name = kubernetesProviderName
  92. }