Skip to content

Commit

Permalink
refs #239 Add e2e test case for decrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
h3poteto committed Jun 3, 2021
1 parent 8c82414 commit fd2608a
Showing 1 changed file with 48 additions and 34 deletions.
82 changes: 48 additions & 34 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,44 +139,58 @@ var _ = Describe("E2E", func() {
return true, nil
})
})
AfterEach(func() {
ctx := context.Background()
err := k8sClient.Delete(ctx, kmsSecret)
if err != nil {
panic(err)
}
})
Context("Encrypted data using aws cli", func() {
const (
key = "PASSWORD"
value = "my_password"
)
BeforeEach(func() {
keyID := os.Getenv("KMS_KEY_ID")
if keyID == "" {
panic(fmt.Errorf("KMS_KEY_ID is required"))
}
data, err := util.EncryptString(value, keyID, os.Getenv("AWS_REGION"))
if err != nil {
panic(err)
}
kmsSecret = fixtures.NewKMSSecret(ns, "test-secret", region, map[string][]byte{
key: data,
})
})
It("Secret data should be decrepted", func() {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
Expect(setupError).To(BeNil())
res := corev1.Secret{}
err := wait.Poll(1*time.Second, 5*time.Minute, func() (bool, error) {
err := k8sClient.Get(ctx, types.NamespacedName{Namespace: kmsSecret.Namespace, Name: kmsSecret.Name}, &res)
decrypt := func(key, value, expected string) {
BeforeEach(func() {
keyID := os.Getenv("KMS_KEY_ID")
if keyID == "" {
panic(fmt.Errorf("KMS_KEY_ID is required"))
}
data, err := util.EncryptString(value, keyID, os.Getenv("AWS_REGION"))
if err != nil {
if apierrors.IsNotFound(err) {
return false, nil
}
klog.Error(err)
return false, err
panic(err)
}
return true, nil
kmsSecret = fixtures.NewKMSSecret(ns, "test-secret", region, map[string][]byte{
key: data,
})
})
It("Secret data should be decrepted", func() {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
Expect(setupError).To(BeNil())
res := corev1.Secret{}
err := wait.Poll(1*time.Second, 5*time.Minute, func() (bool, error) {
err := k8sClient.Get(ctx, types.NamespacedName{Namespace: kmsSecret.Namespace, Name: kmsSecret.Name}, &res)
if err != nil {
if apierrors.IsNotFound(err) {
return false, nil
}
klog.Error(err)
return false, err
}
return true, nil
})
Expect(err).To(BeNil())
val, ok := res.Data[key]
Expect(ok).To(BeTrue())
Expect(string(val)).To(Equal(expected))
})
Expect(err).To(BeNil())
val, ok := res.Data[key]
Expect(ok).To(BeTrue())
Expect(string(val)).To(Equal(value))
}
Context("Value is plain text", func() {
decrypt("api_key", "hogehoge", "hogehoge")
})
Context("Value is yaml object", func() {
decrypt("api_key", "hoge: fuga", "hoge: fuga")
})
Context("Value is yaml formatted text", func() {
decrypt("api_key", "--- hogehoge", "hogehoge")
})
})
})
Expand Down

0 comments on commit fd2608a

Please sign in to comment.