Skip to content

Commit 0f413c5

Browse files
committed
Add TestTrustedSSHKeys Test via mocked repo
1 parent 5af804a commit 0f413c5

File tree

10 files changed

+40
-0
lines changed

10 files changed

+40
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/main
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[core]
2+
repositoryformatversion = 0
3+
filemode = true
4+
bare = true
5+
ignorecase = true
6+
precomposeunicode = true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Unnamed repository; edit this file 'description' to name the repository.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# git ls-files --others --exclude-from=.git/info/exclude
2+
# Lines that start with '#' are comments.
3+
# For a project mostly in C, the following would be a good set of
4+
# exclude patterns (uncomment them if you want to use them):
5+
# *.[oa]
6+
# *~

tests/gitea-repositories-meta/user2/repo-test-trusted-ssh-keys.git/objects/b7/fca3aa0d80144f9718b0486681944f9c587e33

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
x��[o�0��ٿb�QW�� ���$�@��˛�`�ͥ���&�k_z���|ҙ�NZ�Ϫ�55���
2+
�f�pl9L��ۤ�k��
3+
ۙ u3�H$��PVײ�VŸ�s䟼��.��<��1]B1�. 0�u���t���r��*��^�`2X���
4+
'���S��� c\L�^�n�E�2Z?���X�S��L��x�Iʭ��_�/�hxzl����1��.1'�r�'�)>M�x��&&Aw-����dL�M��b�ぅ��KC��m]��4��f��׹x��I+�g,�n��Y�Ҷ��Z8�� rN�k����v�It���[�������}�0��2PxQ�|Uo�9@��E�!S�D?J��
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# pack-refs with: peeled fully-peeled sorted
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
b7fca3aa0d80144f9718b0486681944f9c587e33

tests/integration/gpg_ssh_git_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,3 +366,23 @@ func importTestingKey() (*openpgp.Entity, error) {
366366
// There should only be one entity in this file.
367367
return keyring[0], nil
368368
}
369+
370+
func TestTrustedSSHKeys(t *testing.T) {
371+
defer tests.PrepareTestEnv(t)()
372+
defer test.MockVariableValue(&setting.Repository.Signing.TrustedSSHKeys, []string{"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIH6Y4idVaW3E+bLw1uqoAfJD7o5Siu+HqS51E9oQLPE9"})()
373+
374+
username := "user2"
375+
testCtx := NewAPITestContext(t, username, "repo-test-trusted-ssh-keys", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
376+
t.Run("CheckMainBranchSignedVerified", doAPIGetBranch(testCtx, "main", func(t *testing.T, branch api.Branch) {
377+
require.NotNil(t, branch.Commit, "no commit provided with branch! %v", branch)
378+
require.NotNil(t, branch.Commit.Verification, "no verification provided with branch commit! %v", branch.Commit)
379+
require.True(t, branch.Commit.Verification.Verified)
380+
}))
381+
382+
setting.Repository.Signing.TrustedSSHKeys = []string{}
383+
t.Run("CheckMainBranchSignedUnverified", doAPIGetBranch(testCtx, "main", func(t *testing.T, branch api.Branch) {
384+
require.NotNil(t, branch.Commit, "no commit provided with branch! %v", branch)
385+
require.NotNil(t, branch.Commit.Verification, "no verification provided with branch commit! %v", branch.Commit)
386+
require.False(t, branch.Commit.Verification.Verified)
387+
}))
388+
}

0 commit comments

Comments
 (0)