From 363a712aa28e367eff1f1a8cc529c621a4d6a0bb Mon Sep 17 00:00:00 2001 From: Kevin Schoon Date: Wed, 19 Nov 2025 16:14:16 +0100 Subject: [PATCH] chore: do not clobber ~/.ssh/authorized_keys in certain tests (#10163) The running of `make test` without any additional options will result in the tampering with of ~/.ssh/authorized_keys. This ensures that the tests use a temporary directory by setting SSH.RootPath consistent with other tests in this codebase. Resolves forgejo/forgejo#10164 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10163 Reviewed-by: Michael Kriese Co-authored-by: Kevin Schoon Co-committed-by: Kevin Schoon --- services/asymkey/ssh_key_test.go | 3 +++ services/f3/driver/main_test.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/services/asymkey/ssh_key_test.go b/services/asymkey/ssh_key_test.go index 24b28d295e..d646e3260a 100644 --- a/services/asymkey/ssh_key_test.go +++ b/services/asymkey/ssh_key_test.go @@ -11,6 +11,8 @@ import ( "forgejo.org/models/db" "forgejo.org/models/unittest" user_model "forgejo.org/models/user" + "forgejo.org/modules/setting" + "forgejo.org/modules/test" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -18,6 +20,7 @@ import ( func TestAddLdapSSHPublicKeys(t *testing.T) { require.NoError(t, unittest.PrepareTestDatabase()) + defer test.MockVariableValue(&setting.SSH.RootPath, t.TempDir())() user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) s := &auth.Source{ID: 1} diff --git a/services/f3/driver/main_test.go b/services/f3/driver/main_test.go index b136fd5b23..838baa760b 100644 --- a/services/f3/driver/main_test.go +++ b/services/f3/driver/main_test.go @@ -8,6 +8,8 @@ import ( "testing" "forgejo.org/models/unittest" + "forgejo.org/modules/setting" + "forgejo.org/modules/test" driver_options "forgejo.org/services/f3/driver/options" _ "forgejo.org/models" @@ -22,6 +24,7 @@ import ( func TestF3(t *testing.T) { require.NoError(t, unittest.PrepareTestDatabase()) + defer test.MockVariableValue(&setting.SSH.RootPath, t.TempDir())() tests_f3.ForgeCompliance(t, driver_options.Name) }