Fix tsh profile dir (#26010)

This fixes a bug introduced in #25950
This commit is contained in:
Zac Bergquist 2023-05-10 12:23:31 -06:00 committed by GitHub
parent 7922af1567
commit bfe8d77428
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View file

@ -318,7 +318,7 @@ func defaultProfilePath() string {
// a user lookup (which can be very slow on large AD environments)
home, err := os.UserHomeDir()
if err == nil && home != "" {
return home
return filepath.Join(home, profileDir)
}
home = os.TempDir()

View file

@ -20,6 +20,7 @@ package profile_test
import (
"os"
"path/filepath"
"runtime"
"testing"
"github.com/gravitational/trace"
@ -102,3 +103,16 @@ func TestAppPath(t *testing.T) {
expected := filepath.Join(dir, "keys", "proxy", "testuser-app", "example.com", "banana-x509.pem")
require.Equal(t, expected, p.AppCertPath("banana"))
}
func TestProfilePath(t *testing.T) {
switch runtime.GOOS {
case "darwin", "linux":
default:
t.Skip("this test only runs on Unix")
}
dir := t.TempDir()
t.Setenv("HOME", dir)
require.Equal(t, "/foo/bar", profile.FullProfilePath("/foo/bar"))
require.Equal(t, filepath.Join(dir, ".tsh"), profile.FullProfilePath(""))
}