github.com/pluralsh/plural-cli@v0.9.5/pkg/test/utils.go (about) 1 package test 2 3 import ( 4 "os" 5 "strings" 6 "testing" 7 8 "github.com/pluralsh/plural-cli/pkg/config" 9 "github.com/pluralsh/plural-cli/pkg/crypto" 10 "github.com/stretchr/testify/assert" 11 "gopkg.in/yaml.v2" 12 ) 13 14 func GenDefaultConfig() config.Config { 15 return config.Config{ 16 Email: "test@plural.sh", 17 Token: "abc", 18 NamespacePrefix: "test", 19 Endpoint: "http://example.com", 20 LockProfile: "abc", 21 ReportErrors: false, 22 } 23 } 24 25 func CheckFingerprint(t *testing.T, path string) { 26 b, err := os.ReadFile(path) 27 assert.NoError(t, err) 28 keyID := string(b) 29 if keyID == "" { 30 t.Fatal("expected not empty file") 31 } 32 if !strings.HasPrefix(keyID, "keyid: SHA256:") { 33 t.Fatalf("expected SHA256 format, got %s", keyID) 34 } 35 aesKey, err := crypto.Materialize() 36 assert.NoError(t, err) 37 var k crypto.KeyValidator 38 err = yaml.Unmarshal([]byte(keyID), &k) 39 assert.NoError(t, err) 40 assert.Equal(t, aesKey.ID(), k.KeyID) 41 }