forked from siva-chegondi/caddyvault
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vaultstorage_test.go
93 lines (79 loc) · 2.66 KB
/
vaultstorage_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
package caddyvault_test
import (
"context"
"os"
"path"
"testing"
"github.com/pydio/caddyvault"
"github.com/stretchr/testify/assert"
)
var (
certPath string
vaultStorage *caddyvault.VaultStorage
ctx = context.Background()
)
const certData = `
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAlRuRnThUjU8/prwYxbty
WPT9pURI3lbsKMiB6Fn/VHOKE13p4D8xgOCADpdRagdT6n4etr9atzDKUSvpMtR3
CP5noNc97WiNCggBjVWhs7szEe8ugyqF23XwpHQ6uV1LKH50m92MbOWfCtjU9p/x
qhNpQQ1AZhqNy5Gevap5k8XzRmjSldNAFZMY7Yv3Gi+nyCwGwpVtBUwhuLzgNFK/
yDtw2WcWmUU7NuC8Q6MWvPebxVtCfVp/iQU6q60yyt6aGOBkhAX0LpKAEhKidixY
nP9PNVBvxgu3XZ4P36gZV6+ummKdBVnc3NqwBLu5+CcdRdusmHPHd5pHf4/38Z3/
6qU2a/fPvWzceVTEgZ47QjFMTCTmCwNt29cvi7zZeQzjtwQgn4ipN9NibRH/Ax/q
TbIzHfrJ1xa2RteWSdFjwtxi9C20HUkjXSeI4YlzQMH0fPX6KCE7aVePTOnB69I/
a9/q96DiXZajwlpq3wFctrs1oXqBp5DVrCIj8hU2wNgB7LtQ1mCtsYz//heai0K9
PhE4X6hiE0YmeAZjR0uHl8M/5aW9xCoJ72+12kKpWAa0SFRWLy6FejNYCYpkupVJ
yecLk/4L1W0l6jQQZnWErXZYe0PNFcmwGXy1Rep83kfBRNKRy5tvocalLlwXLdUk
AIU+2GKjyT3iMuzZxxFxPFMCAwEAAQ==
-----END PUBLIC KEY-----
`
// This will run before
// running every test case
func TestMain(m *testing.M) {
os.Setenv("VAULT_TOKEN", "test_vault_token")
vaultStorage = &caddyvault.VaultStorage{
API: "http://localhost:8200",
}
certPath = path.Join("acme", "acme-v02.api.letsencrypt.org", "sites", "tls", "tls.crt")
os.Exit(m.Run())
}
/****************************
* Following were test cases *
****************************/
func TestStore(t *testing.T) {
err := vaultStorage.Store(certPath, []byte(certData))
assert.NoError(t, err, "should store data")
}
func TestLoad(t *testing.T) {
dataInBytes, _ := vaultStorage.Load(certPath)
assert.Equal(t, certData, string(dataInBytes), "Did not found items")
}
func TestExists(t *testing.T) {
status := vaultStorage.Exists(certPath)
assert.True(t, status, "should exists")
}
func TestStat(t *testing.T) {
keyInfo, err := vaultStorage.Stat(certPath)
assert.NoError(t, err, "should not fail")
assert.Equal(t, int64(len(certData)), keyInfo.Size, "key sizes should match")
}
func TestList(t *testing.T) {
list, err := vaultStorage.List(certPath, false)
assert.NoError(t, err, "should not fail listing")
assert.NotEmpty(t, list, "list should not be empty")
}
func TestLock(t *testing.T) {
err := vaultStorage.Lock(ctx, certPath)
assert.NoError(t, err, "should not fail to lock")
err = vaultStorage.Lock(ctx, certPath)
assert.Error(t, err, "should fail to lock")
}
func TestUnlock(t *testing.T) {
err := vaultStorage.Unlock(certPath)
assert.NoError(t, err, "should not fail to unlock")
}
func TestDelete(t *testing.T) {
err := vaultStorage.Delete(certPath)
assert.NoError(t, err, "Should delete check")
}