-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
120 lines (98 loc) · 3.27 KB
/
main_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package main
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCreateConfig(t *testing.T) {
os.Setenv(VAULT_ROLE_ID, "123")
os.Setenv(VAULT_SECRET_ID, "123")
os.Setenv(PMVE_KEEP_SECRETS, "true")
os.Setenv(PMVE_DEBUG, "true")
os.Setenv(VAULT_ADDR, "123")
config := CreateConfig()
assert.Equal(t, "123", config.vaultRoleId)
assert.Equal(t, "123", config.vaultSecretId)
assert.Equal(t, "123", config.vaultAddr)
assert.Equal(t, true, config.keepSecrets)
assert.Equal(t, true, config.debug)
}
func TestCreateConfigWithToken(t *testing.T) {
os.Setenv(VAULT_TOKEN, "123")
os.Setenv(PMVE_KEEP_SECRETS, "true")
os.Setenv(VAULT_ADDR, "123")
os.Unsetenv(VAULT_ROLE_ID)
os.Unsetenv(VAULT_SECRET_ID)
config := CreateConfig()
assert.Empty(t, config.vaultRoleId)
assert.Empty(t, config.vaultSecretId)
assert.Equal(t, "123", config.vaultAddr)
assert.Equal(t, "123", config.vaultToken)
assert.Equal(t, true, config.keepSecrets)
assert.Equal(t, true, config.debug)
}
func TestSetupEnvironment(t *testing.T) {
config := &Config{
keepSecrets: true,
vaultAddr: "123",
vaultRoleId: "123",
vaultSecretId: "123",
vaultToken: "123",
debug: true,
}
SetupEnvironment(config)
assert.Equal(t, "123", os.Getenv(VAULT_ADDR))
assert.Equal(t, "123", os.Getenv(VAULT_ROLE_ID))
assert.Equal(t, "123", os.Getenv(VAULT_SECRET_ID))
assert.Equal(t, "123", os.Getenv(VAULT_TOKEN))
config.keepSecrets = false
SetupEnvironment(config)
assert.Empty(t, os.Getenv(VAULT_ADDR))
assert.Empty(t, os.Getenv(VAULT_ROLE_ID))
assert.Empty(t, os.Getenv(VAULT_SECRET_ID))
assert.Empty(t, os.Getenv(VAULT_TOKEN))
}
// ERROR...
// # chumper.github.com/poor-mans-vault-environment.test
// github.com/sethvargo/go-limiter/memorystore.(*store).purge: relocation target runtime.walltime not defined
// github.com/sethvargo/go-limiter/memorystore.newBucket: relocation target runtime.walltime not defined
// github.com/sethvargo/go-limiter/memorystore.(*bucket).take: relocation target runtime.walltime not defined
// FAIL chumper.github.com/poor-mans-vault-environment [build failed]
// FAIL
// func TestReplaceEnvironment(t *testing.T) {
// cluster, client := createVault(t)
// defer cluster.Cleanup()
// // Set up environment
// os.Setenv("TEST_SEC", "vault:/secret/foo#secret")
// ReplaceEnvironment(client)
// if os.Getenv("TEST_SEC") != "bar" {
// t.Fatalf("Secret TEST_SEC not replaced: %s", os.Getenv("TEST_SEC"))
// }
// }
// func createVault(t *testing.T) (*vault.TestCluster, *api.Client) {
// cluster := vault.NewTestCluster(t, &vault.CoreConfig{
// DevToken: "root",
// }, &vault.TestClusterOptions{
// HandlerFunc: vaulthttp.Handler,
// })
// cluster.Start()
// core := cluster.Cores[0].Core
// vault.TestWaitActive(t, core)
// client := cluster.Cores[0].Client
// return cluster, client
// // err := putSecret(client, map[string]interface{}{"foo": "bar"}, "secret")
// // if err != nil {
// // t.Fatal(err)
// // }
// // data, err := client.Logical().Read("secret/data/secret")
// // if err != nil {
// // t.Fatal(err)
// // }
// // if secret, ok := data.Data["foo"].(string); ok {
// // if secret != "bar" {
// // t.Fatalf("Wrong secret returned: %s", secret)
// // }
// // } else {
// // t.Fatal("Could not get secret")
// // }
// }