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

Function TestMasterKey_Encrypt

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

Source from the content-addressed store, hash-verified

190}
191
192func 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
242func TestMasterKey_encryptWithOpenPGP(t *testing.T) {
243 t.Run("encrypt", func(t *testing.T) {

Callers

nothing calls this directly

Calls 10

StringMethod · 0.95
ImportFileMethod · 0.95
ApplyToMasterKeyMethod · 0.95
PubRingTypeAlias · 0.85
NewGnuPGHomeFunction · 0.85
CleanupMethod · 0.80
EncryptMethod · 0.65
ApplyToMasterKeyMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected