MCPcopy
hub / github.com/getsops/sops / TestMasterKey_Encrypt

Function TestMasterKey_Encrypt

hcvault/keysource_test.go:188–218  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

186}
187
188func TestMasterKey_Encrypt(t *testing.T) {
189 if testSkipDocker {
190 return
191 }
192
193 key := NewMasterKey(testVaultAddress, testEnginePath, "encrypt")
194 (Token(testVaultToken)).ApplyToMasterKey(key)
195 assert.NoError(t, createVaultKey(key))
196
197 dataKey := []byte("the majority of your brain is fat")
198 assert.NoError(t, key.Encrypt(dataKey))
199 assert.NotEmpty(t, key.EncryptedKey)
200
201 client, err := vaultClient(key.VaultAddress, key.token, nil)
202 assert.NoError(t, err)
203
204 payload := decryptPayload(key.EncryptedKey)
205 secret, err := client.Logical().Write(key.decryptPath(), payload)
206 assert.NoError(t, err)
207
208 decryptedData, err := dataKeyFromSecret(secret)
209 assert.NoError(t, err)
210 assert.Equal(t, dataKey, decryptedData)
211
212 key.EnginePath = "invalid"
213 assert.Error(t, key.Encrypt(dataKey))
214
215 key.EnginePath = testEnginePath
216 key.token = ""
217 assert.Error(t, key.Encrypt(dataKey))
218}
219
220func TestMasterKey_EncryptIfNeeded(t *testing.T) {
221 if testSkipDocker {

Callers

nothing calls this directly

Calls 10

EncryptMethod · 0.95
decryptPathMethod · 0.95
TokenTypeAlias · 0.85
createVaultKeyFunction · 0.85
vaultClientFunction · 0.85
decryptPayloadFunction · 0.85
dataKeyFromSecretFunction · 0.85
NewMasterKeyFunction · 0.70
ApplyToMasterKeyMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected