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

Function TestMasterKey_encryptWithOpenPGP

pgp/keysource_test.go:242–271  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

240}
241
242func TestMasterKey_encryptWithOpenPGP(t *testing.T) {
243 t.Run("encrypt", func(t *testing.T) {
244 key := NewMasterKeyFromFingerprint(mockFingerprint)
245 PubRing(mockPubRing).ApplyToMasterKey(key)
246
247 data := []byte("oh no, my darkest secret")
248 assert.NoError(t, key.encryptWithOpenPGP(data))
249
250 assert.NotEmpty(t, key.EncryptedKey)
251 assert.NotEqual(t, data, key.EncryptedKey)
252
253 secRing, err := loadRing(mockSecRing)
254 assert.NoError(t, err)
255 block, err := armor.Decode(strings.NewReader(key.EncryptedKey))
256 assert.NoError(t, err)
257 md, err := openpgp.ReadMessage(block.Body, secRing, nil, nil)
258 assert.NoError(t, err)
259 b, err := io.ReadAll(md.UnverifiedBody)
260 assert.NoError(t, err)
261
262 assert.Equal(t, data, b)
263 })
264
265 t.Run("invalid fingerprint error", func(t *testing.T) {
266 key := NewMasterKeyFromFingerprint("invalid")
267 err := key.encryptWithOpenPGP([]byte("invalid"))
268 assert.Error(t, err)
269 assert.ErrorContains(t, err, "key with fingerprint 'invalid' is not available in keyring")
270 })
271}
272
273func TestMasterKey_encryptWithGnuPG(t *testing.T) {
274 t.Run("encrypt", func(t *testing.T) {

Callers

nothing calls this directly

Calls 6

PubRingTypeAlias · 0.85
loadRingFunction · 0.85
encryptWithOpenPGPMethod · 0.80
ApplyToMasterKeyMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected