Skip to content

Commit

Permalink
feat(providers): add basic test for GKMS
Browse files Browse the repository at this point in the history
Signed-off-by: Mateusz Hromada <[email protected]>

# Conflicts:
#	pkg/stringprovider/stringprovider.go
#	vals.go
  • Loading branch information
ruanda committed Dec 4, 2023
1 parent ed6f58c commit 89ed394
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions vals_gkms_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package vals

import (
"fmt"
"testing"

"github.com/google/go-cmp/cmp"
)

func TestValues_GKMS(t *testing.T) {
// TODO
// create gkms and encrypt test value
// gcloud kms keyrings create "test" --location "global"
// gcloud kms keys create "default" --location "global" --keyring "test" --purpose "encryption"
// echo -n "test_value" \
// | gcloud kms encrypt \
// --location "global" \
// --keyring "test" \
// --key "default" \
// --plaintext-file - \
// --ciphertext-file - \
// | base64 -w0 \
// | tr '/+' '_-'
//
// run with:
//
// go test -run '^(TestValues_GKMS)$'

type testcase struct {
template map[string]interface{}
expected map[string]interface{}
}

plain_value := "test_value"
encrypted_value := "CiQAmPqoGAKT97oUK0DdiI_cLDm3j6iPDK4-TJ3yQII-snFHCckSMwAkTpnEoD5wOeRaZrt3eC1ewFMuw617fqqjTStrsar9ciGERzk5t6uMgA0HKzSxGMdjHQ=="

project := "test-project"
location := "global"
keyring := "test"
crypto_key := "default"

testcases := []testcase{
{
template: map[string]interface{}{
"test_key": fmt.Sprintf("ref+gkms://%s?project=%s&location=%s&keyring=%s&crypto_key=%s", encrypted_value, project, location, keyring, crypto_key),
},
expected: map[string]interface{}{
"test_key": plain_value,
},
},
}

for i := range testcases {
tc := testcases[i]
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
vals, err := Eval(tc.template)
if err != nil {
t.Fatalf("%v", err)
}
diff := cmp.Diff(tc.expected, vals)
if diff != "" {
t.Errorf("unexpected diff: %s", diff)
}
})
}
}

0 comments on commit 89ed394

Please sign in to comment.