forked from helmfile/vals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vals_bitwardensecrets_test.go
77 lines (67 loc) · 1.85 KB
/
vals_bitwardensecrets_test.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package vals
import (
"fmt"
"os"
"testing"
config2 "github.com/helmfile/vals/pkg/config"
)
func TestValues_BitwardenSecrets_String(t *testing.T) {
// TODO
// Pre-requisite:
// 1. Create a Project in Bitwarden Secrets Manager called "vals-test"
// 2. Create a "Machine account", grant "Can read" permission on the "vals-test" project, and generate an access token
// 3. Get the Organization ID from the Bitwarden Secrets Manager URL. For example, if the URL is https://vault.bitwarden.com/#/sm/00000000-0000-0000-0000-000000000000, the Organization ID is 00000000-0000-0000-0000-000000000000.
// 4. Export the following environment variables:
// - BWS_ACCESS_TOKEN
// - BWS_ORGANIZATION_ID
// 5. Create a secret in the "vals-test" project with name "fooKey" and value "myValue"
if os.Getenv("SKIP_TESTS") != "" {
t.Skip("Skipping tests")
}
type testcase struct {
config map[string]interface{}
}
commonInline := map[string]interface{}{
"vals-test": "fooKey",
}
testcases := []testcase{
{
config: map[string]interface{}{
"provider": map[string]interface{}{
"name": "bws",
"type": "string",
"path": "vals-test",
},
"inline": commonInline,
},
},
{
config: map[string]interface{}{
"provider": map[string]interface{}{
"name": "bws",
// implies type=string
"path": "vals-test",
},
"inline": commonInline,
},
},
}
for i := range testcases {
tc := testcases[i]
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
config := config2.Map(tc.config)
vals, err := Load(config)
if err != nil {
t.Fatalf("failed to load config for testcase %d: %v", i, err)
}
{
expected := "myValue"
key := "vals-test"
actual := vals[key]
if actual != expected {
t.Errorf("unepected value for key %q: expected=%q, got=%q", key, expected, actual)
}
}
})
}
}