@@ -13,7 +13,8 @@ import (
1313 "code.gitea.io/gitea/modules/timeutil"
1414 "code.gitea.io/gitea/modules/util"
1515
16- "github.com/keybase/go-crypto/openpgp/packet"
16+ "github.com/ProtonMail/go-crypto/openpgp"
17+ "github.com/ProtonMail/go-crypto/openpgp/packet"
1718 "github.com/stretchr/testify/assert"
1819 "github.com/stretchr/testify/require"
1920)
@@ -403,3 +404,25 @@ func TestTryGetKeyIDFromSignature(t *testing.T) {
403404 IssuerFingerprint : []uint8 {0xb , 0x23 , 0x24 , 0xc7 , 0xe6 , 0xfe , 0x4f , 0x3a , 0x6 , 0x26 , 0xc1 , 0x21 , 0x3 , 0x8d , 0x1a , 0x3e , 0xad , 0xdb , 0xea , 0x9c },
404405 }))
405406}
407+
408+ func TestParseGPGKey (t * testing.T ) {
409+ assert .NoError (t , unittest .PrepareTestDatabase ())
410+ const testEmail = "[email protected] " 411+ assert .NoError (t , db .Insert (db .DefaultContext , & user_model.EmailAddress {UID : 1 , Email : testEmail , IsActivated : true }))
412+ _ = unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : 1 })
413+
414+ e , err := openpgp .NewEntity ("name" , "comment" , testEmail , nil )
415+ require .NoError (t , err )
416+ k , err := parseGPGKey (db .DefaultContext , 1 , e , true )
417+ require .NoError (t , err )
418+ assert .NotEmpty (t , k .KeyID )
419+ assert .NotEmpty (t , k .Emails ) // the key is valid, matches the email
420+
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