(t *testing.T)
| 331 | } |
| 332 | |
| 333 | func TestMasterKey_Decrypt(t *testing.T) { |
| 334 | // Mock encrypted data |
| 335 | gnuPGHome, err := NewGnuPGHome() |
| 336 | assert.NoError(t, err) |
| 337 | t.Cleanup(func() { |
| 338 | _ = os.RemoveAll(gnuPGHome.String()) |
| 339 | }) |
| 340 | assert.NoError(t, gnuPGHome.ImportFile(mockPrivateKey)) |
| 341 | |
| 342 | fingerprint := shortenFingerprint(mockFingerprint) |
| 343 | |
| 344 | data := []byte("this data is absolutely top secret") |
| 345 | stdout, stderr, err := gpgExec(context.Background(), gnuPGHome.String(), []string{ |
| 346 | "--no-default-recipient", |
| 347 | "--yes", |
| 348 | "--encrypt", |
| 349 | "-a", |
| 350 | "-r", |
| 351 | fingerprint, |
| 352 | "--trusted-key", |
| 353 | fingerprint, |
| 354 | "--no-encrypt-to", |
| 355 | }, bytes.NewReader(data)) |
| 356 | assert.Nil(t, err) |
| 357 | assert.NoErrorf(t, gnuPGHome.ImportFile(mockPrivateKey), stderr.String()) |
| 358 | |
| 359 | encryptedData := stdout.String() |
| 360 | assert.NotEqualValues(t, data, encryptedData) |
| 361 | |
| 362 | // Actual tests |
| 363 | t.Run("with OpenPGP", func(t *testing.T) { |
| 364 | key := NewMasterKeyFromFingerprint(mockFingerprint) |
| 365 | key.EncryptedKey = encryptedData |
| 366 | SecRing(mockSecRing).ApplyToMasterKey(key) |
| 367 | |
| 368 | got, err := key.Decrypt() |
| 369 | assert.NoError(t, err) |
| 370 | assert.Equal(t, data, got) |
| 371 | // Detailed testing is done by TestMasterKey_decryptWithOpenPGP |
| 372 | }) |
| 373 | |
| 374 | t.Run("with GnuPG", func(t *testing.T) { |
| 375 | gnuPGHome, err := NewGnuPGHome() |
| 376 | assert.NoError(t, err) |
| 377 | t.Cleanup(func() { |
| 378 | _ = os.RemoveAll(gnuPGHome.String()) |
| 379 | }) |
| 380 | assert.NoError(t, gnuPGHome.ImportFile(mockPrivateKey)) |
| 381 | |
| 382 | key := NewMasterKeyFromFingerprint(mockFingerprint) |
| 383 | key.EncryptedKey = encryptedData |
| 384 | gnuPGHome.ApplyToMasterKey(key) |
| 385 | |
| 386 | got, err := key.Decrypt() |
| 387 | assert.NoError(t, err) |
| 388 | assert.Equal(t, data, got) |
| 389 | // Detailed testing is done by TestMasterKey_decryptWithGnuPG |
| 390 | }) |
nothing calls this directly
no test coverage detected