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

Function TestMasterKey_decryptWithOpenPGP

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

Source from the content-addressed store, hash-verified

414}
415
416func TestMasterKey_decryptWithOpenPGP(t *testing.T) {
417 t.Run("decrypt", func(t *testing.T) {
418 gnuPGHome, err := NewGnuPGHome()
419 assert.NoError(t, err)
420 t.Cleanup(func() {
421 _ = os.RemoveAll(gnuPGHome.String())
422 })
423 assert.NoError(t, gnuPGHome.ImportFile(mockPrivateKey))
424
425 fingerprint := shortenFingerprint(mockFingerprint)
426
427 data := []byte("this data is absolutely top secret")
428 stdout, stderr, err := gpgExec(context.Background(), gnuPGHome.String(), []string{
429 "--no-default-recipient",
430 "--yes",
431 "--encrypt",
432 "-a",
433 "-r",
434 fingerprint,
435 "--trusted-key",
436 fingerprint,
437 "--no-encrypt-to",
438 }, bytes.NewReader(data))
439 assert.Nil(t, err)
440 assert.NoErrorf(t, gnuPGHome.ImportFile(mockPrivateKey), stderr.String())
441
442 encryptedData := stdout.String()
443 assert.NotEqualValues(t, data, encryptedData)
444
445 key := NewMasterKeyFromFingerprint(mockFingerprint)
446 SecRing(mockSecRing).ApplyToMasterKey(key)
447 key.EncryptedKey = encryptedData
448
449 got, err := key.decryptWithOpenPGP()
450 assert.NoError(t, err)
451 assert.Equal(t, data, got)
452 })
453
454 t.Run("invalid data error", func(t *testing.T) {
455 key := NewMasterKeyFromFingerprint(mockFingerprint)
456 key.EncryptedKey = "absolute invalid"
457 SecRing(mockSecRing).ApplyToMasterKey(key)
458 got, err := key.decryptWithOpenPGP()
459 assert.Error(t, err)
460 assert.ErrorContains(t, err, "armor decoding failed: EOF")
461 assert.Nil(t, got)
462 })
463}
464
465func TestMasterKey_decryptWithGnuPG(t *testing.T) {
466 t.Run("decrypt", func(t *testing.T) {

Callers

nothing calls this directly

Calls 11

StringMethod · 0.95
ImportFileMethod · 0.95
NewGnuPGHomeFunction · 0.85
shortenFingerprintFunction · 0.85
gpgExecFunction · 0.85
SecRingTypeAlias · 0.85
CleanupMethod · 0.80
decryptWithOpenPGPMethod · 0.80
ApplyToMasterKeyMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected