-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging_test.go
More file actions
47 lines (42 loc) · 1.06 KB
/
Copy pathlogging_test.go
File metadata and controls
47 lines (42 loc) · 1.06 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
package main
import (
"os"
"path/filepath"
"runtime"
"strings"
"testing"
)
// The TUI log must live in a per-user directory with user-only permissions:
// logged request URLs can carry tokens, and the old world-readable
// $TMPDIR/weeb.log leaked them on shared systems.
func TestDefaultLogPathIsPerUserAndPrivate(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("unix permission semantics")
}
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
path := defaultLogPath()
if !strings.HasPrefix(path, home) {
t.Fatalf("log path %q should live under the user dir %q", path, home)
}
dirInfo, err := os.Stat(filepath.Dir(path))
if err != nil {
t.Fatal(err)
}
if got := dirInfo.Mode().Perm(); got != 0o700 {
t.Errorf("log dir mode = %o, want 0700", got)
}
f, err := openLogFile(path)
if err != nil {
t.Fatal(err)
}
defer f.Close()
fileInfo, err := f.Stat()
if err != nil {
t.Fatal(err)
}
if got := fileInfo.Mode().Perm(); got != 0o600 {
t.Errorf("log file mode = %o, want 0600", got)
}
}