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