(t *testing.T)
| 190 | } |
| 191 | |
| 192 | func TestMasterKey_Encrypt(t *testing.T) { |
| 193 | t.Run("with OpenPGP", func(t *testing.T) { |
| 194 | key := NewMasterKeyFromFingerprint(mockFingerprint) |
| 195 | PubRing(mockPubRing).ApplyToMasterKey(key) |
| 196 | |
| 197 | data := []byte("oh no, my darkest secret") |
| 198 | assert.NoError(t, key.Encrypt(data)) |
| 199 | assert.NotEqual(t, data, key.EncryptedKey) |
| 200 | // Detailed testing is done by TestMasterKey_encryptWithOpenPGP |
| 201 | }) |
| 202 | |
| 203 | t.Run("with GnuPG", func(t *testing.T) { |
| 204 | gnuPGHome, err := NewGnuPGHome() |
| 205 | assert.NoError(t, err) |
| 206 | t.Cleanup(func() { |
| 207 | _ = os.RemoveAll(gnuPGHome.String()) |
| 208 | }) |
| 209 | assert.NoError(t, gnuPGHome.ImportFile(mockPublicKey)) |
| 210 | |
| 211 | key := NewMasterKeyFromFingerprint(mockFingerprint) |
| 212 | gnuPGHome.ApplyToMasterKey(key) |
| 213 | data := []byte("oh no, my darkest secret") |
| 214 | assert.NoError(t, key.Encrypt(data)) |
| 215 | assert.NotEmpty(t, key.EncryptedKey) |
| 216 | assert.NotEqual(t, data, key.EncryptedKey) |
| 217 | // Detailed testing is done by TestMasterKey_encryptWithGnuPG |
| 218 | }) |
| 219 | |
| 220 | t.Run("with error", func(t *testing.T) { |
| 221 | key := NewMasterKeyFromFingerprint(mockFingerprint) |
| 222 | |
| 223 | data := []byte("oh no, my darkest secret") |
| 224 | err := key.Encrypt(data) |
| 225 | assert.Error(t, err) |
| 226 | assert.ErrorContains(t, err, "GnuPG binary error") |
| 227 | assert.ErrorContains(t, err, "github.com/ProtonMail/go-crypto/openpgp error") |
| 228 | }) |
| 229 | |
| 230 | t.Run("with OpenPGP disabled", func(t *testing.T) { |
| 231 | key := NewMasterKeyFromFingerprint(mockFingerprint) |
| 232 | DisableOpenPGP{}.ApplyToMasterKey(key) |
| 233 | |
| 234 | data := []byte("oh no, my darkest secret") |
| 235 | err := key.Encrypt(data) |
| 236 | assert.Error(t, err) |
| 237 | assert.ErrorContains(t, err, "GnuPG binary error") |
| 238 | assert.NotContains(t, err.Error(), "github.com/ProtonMail/go-crypto/openpgp error") |
| 239 | }) |
| 240 | } |
| 241 | |
| 242 | func TestMasterKey_encryptWithOpenPGP(t *testing.T) { |
| 243 | t.Run("encrypt", func(t *testing.T) { |
nothing calls this directly
no test coverage detected