forked from Vodafone/vault-plugin-aead
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath_aead_test.go
More file actions
96 lines (79 loc) · 2.5 KB
/
Copy pathpath_aead_test.go
File metadata and controls
96 lines (79 loc) · 2.5 KB
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
package aeadplugin
import (
"context"
"encoding/json"
"testing"
"github.com/hashicorp/vault/sdk/logical"
"github.com/stretchr/testify/assert"
)
func TestPathAeadEncrypt(test *testing.T) {
backend, storage := testBackend(test)
prepareTestData(test, backend, storage)
updatedData := make(map[string]interface{})
updatedData["random_field1"] = "plaintext"
contextVar := context.Background()
response, errorRequest := backend.HandleRequest(contextVar, &logical.Request{
Storage: storage,
Operation: logical.UpdateOperation,
Path: "encrypt",
Data: updatedData,
})
if errorRequest != nil {
test.Fatal(errorRequest)
}
expectedMockObject := map[string]interface{}{
"random_field1": "AQKE8bGXsDZ5DHjLdThQAB96z0YgmUN1F6jWCYNO",
}
assert.EqualValues(test, expectedMockObject, response.Data)
}
func TestPathAeadDecrypt(test *testing.T) {
backend, storage := testBackend(test)
prepareTestData(test, backend, storage)
updatedData := make(map[string]interface{})
updatedData["random_field1"] = "AQKE8bGXsDZ5DHjLdThQAB96z0YgmUN1F6jWCYNO"
contextVar := context.Background()
response, errorRequest := backend.HandleRequest(contextVar, &logical.Request{
Storage: storage,
Operation: logical.UpdateOperation,
Path: "decrypt",
Data: updatedData,
})
if errorRequest != nil {
test.Fatal(errorRequest)
}
expectedMockObject := map[string]interface{}{
"random_field1": "plaintext",
}
assert.EqualValues(test, expectedMockObject, response.Data)
}
func prepareTestData(test *testing.T, backend *backend, storage logical.Storage) {
encryptionKey := encryptionJsonKeyStruct{
PrimaryKeyID: 42267057,
Key: []Key{
Key{
KeyData: struct {
TypeURL string `json:"typeUrl"`
Value string `json:"value"`
KeyMaterialType string `json:"keyMaterialType"`
}{
TypeURL: "type.googleapis.com/google.crypto.tink.AesSivKey",
Value: "EkDAEgACCd1/yruZMuI49Eig5Glb5koi0DXgx1mXVALYJWNRn5wYuQR46ggNuMhFfhrJCsddVp/Q7Pot2hvHoaQS",
KeyMaterialType: "SYMMETRIC",
},
Status: "ENABLED",
KeyID: 42267057,
OutputPrefixType: "TINK",
},
},
}
encryptionJsonKey, errorMarshaling := json.Marshal(&encryptionKey)
if errorMarshaling != nil {
test.Fatal("marshalingError", errorMarshaling)
}
encryptionMap := map[string]interface{}{
"random_field1": string(encryptionJsonKey),
"random_field2": string(encryptionJsonKey),
}
// store the config
saveConfig(backend, storage, encryptionMap, true, test)
}