@@ -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+ assert .
NoError (
t ,
db .
Insert (
db .
DefaultContext ,
& user_model.
EmailAddress {
UID :
1 ,
Email :
"[email protected] " ,
IsActivated :
true }))
411+
412+ // create a key for test email
413+ e ,
err := openpgp .
NewEntity (
"name" ,
"comment" ,
"[email protected] " ,
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