azure_key.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 azure
  12. import (
  13. "encoding/json"
  14. "fmt"
  15. "github.com/Azure/azure-sdk-for-go/profiles/latest/keyvault/keyvault"
  16. // nolint
  17. . "github.com/onsi/ginkgo/v2"
  18. v1 "k8s.io/api/core/v1"
  19. esv1alpha1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1alpha1"
  20. "github.com/external-secrets/external-secrets/e2e/framework"
  21. )
  22. // azure keyvault type=key should retrieve a jwk from the api.
  23. var _ = Describe("[azure]", Label("azure", "keyvault", "key"), func() {
  24. f := framework.New("eso-azure-keytype")
  25. prov := newFromEnv(f)
  26. var jwk *keyvault.JSONWebKey
  27. var keyName string
  28. BeforeEach(func() {
  29. keyName = fmt.Sprintf("%s-%s", f.Namespace.Name, "keytest")
  30. jwk = prov.CreateKey(keyName)
  31. })
  32. AfterEach(func() {
  33. prov.DeleteKey(keyName)
  34. })
  35. ff := framework.TableFunc(f, prov)
  36. It("should sync keyvault objects with type=key", func() {
  37. ff(func(tc *framework.TestCase) {
  38. secretKey := "azkv-key"
  39. keyBytes, _ := json.Marshal(jwk)
  40. tc.ExpectedSecret = &v1.Secret{
  41. Type: v1.SecretTypeOpaque,
  42. Data: map[string][]byte{
  43. secretKey: keyBytes,
  44. },
  45. }
  46. tc.ExternalSecret.Spec.Data = []esv1alpha1.ExternalSecretData{
  47. {
  48. SecretKey: secretKey,
  49. RemoteRef: esv1alpha1.ExternalSecretDataRemoteRef{
  50. Key: "key/" + keyName,
  51. },
  52. },
  53. }
  54. })
  55. })
  56. })