(t *testing.T)
| 414 | } |
| 415 | |
| 416 | func 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 | |
| 465 | func TestMasterKey_decryptWithGnuPG(t *testing.T) { |
| 466 | t.Run("decrypt", func(t *testing.T) { |
nothing calls this directly
no test coverage detected