@@ -13,7 +13,8 @@ import (
13
13
"code.gitea.io/gitea/modules/timeutil"
14
14
"code.gitea.io/gitea/modules/util"
15
15
16
- "github.com/keybase/go-crypto/openpgp/packet"
16
+ "github.com/ProtonMail/go-crypto/openpgp"
17
+ "github.com/ProtonMail/go-crypto/openpgp/packet"
17
18
"github.com/stretchr/testify/assert"
18
19
"github.com/stretchr/testify/require"
19
20
)
@@ -403,3 +404,25 @@ func TestTryGetKeyIDFromSignature(t *testing.T) {
403
404
IssuerFingerprint : []uint8 {0xb , 0x23 , 0x24 , 0xc7 , 0xe6 , 0xfe , 0x4f , 0x3a , 0x6 , 0x26 , 0xc1 , 0x21 , 0x3 , 0x8d , 0x1a , 0x3e , 0xad , 0xdb , 0xea , 0x9c },
404
405
}))
405
406
}
407
+
408
+ func TestParseGPGKey (t * testing.T ) {
409
+ assert .NoError (t , unittest .PrepareTestDatabase ())
410
+ assert .NoError (t , db .Insert (db .DefaultContext , & user_model.EmailAddress {UID : 1 , Email : "email1@example.com" , IsActivated : true }))
411
+
412
+ // create a key for test email
413
+ e , err := openpgp .NewEntity ("name" , "comment" , "email1@example.com" , nil )
414
+ require .NoError (t , err )
415
+ k , err := parseGPGKey (db .DefaultContext , 1 , e , true )
416
+ require .NoError (t , err )
417
+ assert .NotEmpty (t , k .KeyID )
418
+ assert .NotEmpty (t , k .Emails ) // the key is valid, matches the email
419
+
420
+ // then revoke the key
421
+ for _ , id := range e .Identities {
422
+ id .Revocations = append (id .Revocations , & packet.Signature {RevocationReason : util .ToPointer (packet .KeyCompromised )})
423
+ }
424
+ k , err = parseGPGKey (db .DefaultContext , 1 , e , true )
425
+ require .NoError (t , err )
426
+ assert .NotEmpty (t , k .KeyID )
427
+ assert .Empty (t , k .Emails ) // the key is revoked, matches no email
428
+ }
0 commit comments