mirror of
https://github.com/go-gitea/gitea.git
synced 2024-11-15 18:08:23 -07:00
Fix GPG email checking to be case insensitive (#1988)
This commit is contained in:
parent
6678593b3c
commit
1a906f800d
@ -211,9 +211,9 @@ func parseGPGKey(ownerID int64, e *openpgp.Entity) (*GPGKey, error) {
|
||||
emails := make([]*EmailAddress, len(e.Identities))
|
||||
n := 0
|
||||
for _, ident := range e.Identities {
|
||||
|
||||
email := strings.ToLower(strings.TrimSpace(ident.UserId.Email))
|
||||
for _, e := range userEmails {
|
||||
if e.Email == ident.UserId.Email && e.IsActivated {
|
||||
if e.Email == email && e.IsActivated {
|
||||
emails[n] = e
|
||||
break
|
||||
}
|
||||
|
@ -183,3 +183,42 @@ Unknown GPG key with good email
|
||||
err = verifySign(goodSig, goodHash, cannotsignkey)
|
||||
assert.Error(t, err, "Validate a bad signature with a kay that can not sign")
|
||||
}
|
||||
|
||||
func TestCheckGPGUserEmail(t *testing.T) {
|
||||
testEmailWithUpperCaseLetters := `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||
Version: GnuPG v1
|
||||
|
||||
mQENBFlEBvMBCADe+EQcfv/aKbMFy7YB8e/DE+hY39sfjvdvSgeXtNhfmYvIOUjT
|
||||
ORMCvce2Oxzb3HTI0rjYsJpzo9jEQ53dB3vdr0ne5Juby6N7QPjof3NR+ko50Ki2
|
||||
0ilOjYuA0v6VHLIn70UBa9NEf+XDuE7P+Lbtl2L9B9OMXtcTAZoA3cJySgtNFNIG
|
||||
AVefPi8LeOcekL39wxJEA8OzdCyO5oENEwAG1tzjy9DDNJf74/dBBh2NiXeSeMxZ
|
||||
RYeYzqEa2UTDP1fkUl7d2/hV36cKZWZr+l4SQ5bM7HeLj2SsfabLfqKoVWgkfAzQ
|
||||
VwtkbRpzMiDLMte2ZAyTJUc+77YbFoyAmOcjABEBAAG0HFVzZXIgT25lIDxVc2Vy
|
||||
MUBFeGFtcGxlLmNvbT6JATgEEwECACIFAllEBvMCGwMGCwkIBwMCBhUIAgkKC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FlVk0W0bLBrs3fTDw1lS/N8HpyQb+5ryQmiIb2a48aygCS/h2qeRlX1d
|
||||
Q0KHb+QcycSgbDx0ZAvdIacuKvBBcbxrsmFUI4LR+oIup0G9gUc0roPvr014jYQL
|
||||
7f8r/8fpcN8t+I/41QHCs6L/BEIdTHW3rTQ6
|
||||
=zHo9
|
||||
-----END PGP PUBLIC KEY BLOCK-----`
|
||||
|
||||
key, err := AddGPGKey(1, testEmailWithUpperCaseLetters)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Len(t, key.Emails, 1)
|
||||
assert.Equal(t, "user1@example.com", key.Emails[0].Email)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user