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

Function TestMasterKey_EncryptIfNeeded

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

Source from the content-addressed store, hash-verified

307}
308
309func TestMasterKey_EncryptIfNeeded(t *testing.T) {
310 gnuPGHome, err := NewGnuPGHome()
311 assert.NoError(t, err)
312 t.Cleanup(func() {
313 _ = os.RemoveAll(gnuPGHome.String())
314 })
315 assert.NoError(t, gnuPGHome.ImportFile(mockPrivateKey))
316
317 key := NewMasterKeyFromFingerprint(mockFingerprint)
318 gnuPGHome.ApplyToMasterKey(key)
319 assert.NoError(t, key.EncryptIfNeeded([]byte("data")))
320
321 encryptedKey := key.EncryptedKey
322 assert.Contains(t, encryptedKey, "END PGP MESSAGE")
323
324 assert.NoError(t, key.EncryptIfNeeded([]byte("some other data")))
325 assert.Equal(t, encryptedKey, key.EncryptedKey)
326}
327
328func TestMasterKey_EncryptedDataKey(t *testing.T) {
329 key := &MasterKey{EncryptedKey: "some key"}

Callers

nothing calls this directly

Calls 7

StringMethod · 0.95
ImportFileMethod · 0.95
ApplyToMasterKeyMethod · 0.95
NewGnuPGHomeFunction · 0.85
CleanupMethod · 0.80
EncryptIfNeededMethod · 0.65

Tested by

no test coverage detected