1
0
mirror of https://github.com/getsops/sops.git synced 2026-02-05 12:45:21 +01:00
Files
sops/gcpkms/keysource_test.go

37 lines
1.2 KiB
Go
Raw Permalink Normal View History

2017-09-12 15:36:48 +03:00
package gcpkms
2017-09-11 22:21:46 +03:00
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
2017-09-12 15:36:48 +03:00
func TestGCPKMSKeySourceFromString(t *testing.T) {
2017-09-11 22:21:46 +03:00
s := "projects/sops-testing1/locations/global/keyRings/creds/cryptoKeys/key1, projects/sops-testing2/locations/global/keyRings/creds/cryptoKeys/key2"
2017-09-15 14:40:57 -07:00
ks := MasterKeysFromResourceIDString(s)
2017-09-11 22:21:46 +03:00
k1 := ks[0]
k2 := ks[1]
2017-09-15 14:40:57 -07:00
expectedResourceID1 := "projects/sops-testing1/locations/global/keyRings/creds/cryptoKeys/key1"
expectedResourceID2 := "projects/sops-testing2/locations/global/keyRings/creds/cryptoKeys/key2"
if k1.ResourceID != expectedResourceID1 {
t.Errorf("ResourceID mismatch. Expected %s, found %s", expectedResourceID1, k1.ResourceID)
2017-09-11 22:21:46 +03:00
}
2017-09-15 14:40:57 -07:00
if k2.ResourceID != expectedResourceID2 {
t.Errorf("ResourceID mismatch. Expected %s, found %s", expectedResourceID2, k2.ResourceID)
2017-09-11 22:21:46 +03:00
}
}
func TestKeyToMap(t *testing.T) {
key := MasterKey{
CreationDate: time.Date(2016, time.October, 31, 10, 0, 0, 0, time.UTC),
2017-09-15 14:40:57 -07:00
ResourceID: "foo",
2017-09-11 22:21:46 +03:00
EncryptedKey: "this is encrypted",
}
assert.Equal(t, map[string]interface{}{
"resource_id": "foo",
"enc": "this is encrypted",
"created_at": "2016-10-31T10:00:00Z",
}, key.ToMap())
}