Skip to content

Commit 745a690

Browse files
committed
resolve fixme
1 parent c771cd6 commit 745a690

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

custom/conf/app.example.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,7 @@ LEVEL = Info
12331233
;;
12341234
;; Determines which additional ssh keys are trusted for all signed commits regardless of the user
12351235
;; This is useful for ssh signing key rotation.
1236+
;; Exposes the provided SIGNING_NAME and SIGNING_EMAIL as the signer, regardless of the SIGNING_FORMAT value.
12361237
;; Multiple keys should be comma separated.
12371238
;; E.g."ssh-<algorithm> <key>". or "ssh-<algorithm> <key1>, ssh-<algorithm> <key2>".
12381239
;TRUSTED_SSH_KEYS =

services/asymkey/commit.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,10 @@ func ParseCommitWithSSHSignature(ctx context.Context, c *git.Commit, committerUs
417417

418418
// Try the pre-set trusted keys (for key-rotation purpose)
419419
for _, k := range setting.Repository.Signing.TrustedSSHKeys {
420-
// FIXME: why here uses "commiterUser" as "signerUser" but below don't? why here uses "c.Committer.Email" but below uses "gpgSettings.Email"?
421-
signerUser := committerUser
420+
signerUser := &user_model.User{
421+
Name: setting.Repository.Signing.SigningName,
422+
Email: setting.Repository.Signing.SigningEmail,
423+
}
422424
commitVerification := verifySSHCommitVerificationByInstanceKey(c, committerUser, signerUser, c.Committer.Email, k)
423425
if commitVerification != nil && commitVerification.Verified {
424426
return commitVerification

services/asymkey/commit_test.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
func TestParseCommitWithSSHSignature(t *testing.T) {
2020
// Here we only test the TrustedSSHKeys. The complete signing test is in tests/integration/gpg_ssh_git_test.go
2121
t.Run("TrustedSSHKey", func(t *testing.T) {
22+
defer test.MockVariableValue(&setting.Repository.Signing.SigningName, "gitea")()
23+
defer test.MockVariableValue(&setting.Repository.Signing.SigningEmail, "[email protected]")()
2224
defer test.MockVariableValue(&setting.Repository.Signing.TrustedSSHKeys, []string{"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIH6Y4idVaW3E+bLw1uqoAfJD7o5Siu+HqS51E9oQLPE9"})()
2325

2426
commit, err := git.CommitFromReader(nil, git.Sha1ObjectFormat.EmptyObjectID(), strings.NewReader(`tree 9a93ffa76e8b72bdb6431910b3a506fa2b39f42e
@@ -34,11 +36,18 @@ gpgsig -----BEGIN SSH SIGNATURE-----
3436
Initial commit with signed file
3537
`))
3638
require.NoError(t, err)
37-
ret := ParseCommitWithSSHSignature(t.Context(), commit, &user_model.User{Name: "foo", Email: "[email protected]"})
39+
committingUser := &user_model.User{
40+
ID: 2,
41+
Name: "User Two",
42+
43+
}
44+
ret := ParseCommitWithSSHSignature(t.Context(), commit, committingUser)
3845
require.NotNil(t, ret)
3946
assert.True(t, ret.Verified)
4047
assert.False(t, ret.Warning)
41-
assert.NotNil(t, ret.CommittingUser) // FIXME: test the CommittingUser and SigningUser correctly
42-
assert.NotNil(t, ret.SigningUser) // FIXME: test the CommittingUser and SigningUser correctly
48+
assert.Equal(t, ret.CommittingUser, committingUser)
49+
assert.NotNil(t, ret.SigningUser)
50+
assert.Equal(t, ret.SigningUser.Name, "gitea")
51+
assert.Equal(t, ret.SigningUser.Email, "[email protected]")
4352
})
4453
}

0 commit comments

Comments
 (0)