Repository navigation
Expand file tree
/
Copy pathv2paths_test.go
More file actions
65 lines (61 loc) · 1.92 KB
/
Copy pathv2paths_test.go
File metadata and controls
65 lines (61 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"os"
"path/filepath"
"testing"
)
func TestProductionDataLayoutAndSharedRuntime(t *testing.T) {
home := t.TempDir()
if err := preparePasuDirectories(home); err != nil {
t.Fatal(err)
}
if pasuRuntimeDirectory(home) != filepath.Join(home, ".ssh/pasu") {
t.Fatal("SSH socket root changed")
}
if pasuDataDirectory(home) != filepath.Join(home, ".ssh/pasu/profiles", pasuTeamID+"."+pasuGUIIdentifier) {
t.Fatal("data identity changed")
}
for _, path := range []string{pasuRuntimeDirectory(home), filepath.Join(pasuRuntimeDirectory(home), "profiles"), pasuDataDirectory(home)} {
if err := requireOwnedDir(path); err != nil {
t.Fatal(err)
}
}
}
func TestDataDirectoryRejectsSymlink(t *testing.T) {
home := t.TempDir()
if err := os.MkdirAll(filepath.Join(home, ".ssh/pasu"), 0700); err != nil {
t.Fatal(err)
}
outside := t.TempDir()
if err := os.Symlink(outside, filepath.Join(home, ".ssh/pasu/profiles")); err != nil {
t.Fatal(err)
}
if err := preparePasuDirectories(home); err == nil {
t.Fatal("accepted linked profile root")
}
entries, err := os.ReadDir(outside)
if err != nil || len(entries) != 0 {
t.Fatalf("wrote outside data root: %v %v", entries, err)
}
}
func TestDataDirectoryRejectsUnsafePermissionsWithoutChangingThem(t *testing.T) {
for _, relative := range []string{".ssh/pasu", ".ssh/pasu/profiles", ".ssh/pasu/profiles/" + pasuTeamID + "." + pasuGUIIdentifier} {
t.Run(relative, func(t *testing.T) {
home := t.TempDir()
if err := preparePasuDirectories(home); err != nil {
t.Fatal(err)
}
path := filepath.Join(home, relative)
if err := os.Chmod(path, 0755); err != nil {
t.Fatal(err)
}
if err := preparePasuDirectories(home); err == nil {
t.Fatal("accepted an accessible data directory")
}
info, err := os.Stat(path)
if err != nil || info.Mode().Perm() != 0755 {
t.Fatalf("silently changed existing permissions: %v %v", info, err)
}
})
}
}