-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocketdir_test.go
More file actions
40 lines (32 loc) · 1.13 KB
/
socketdir_test.go
File metadata and controls
40 lines (32 loc) · 1.13 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
package ts
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSocketDir_ensureSecureSocketDir_Good_NestedPath(t *testing.T) {
dir := filepath.Join(t.TempDir(), "core", "socket")
require.NoError(t, ensureSecureSocketDir(dir))
}
func TestSocketDir_ensureSecureSocketDir_Bad_NonDirectory(t *testing.T) {
baseDir := t.TempDir()
blocker := filepath.Join(baseDir, "blocked")
require.NoError(t, os.WriteFile(blocker, []byte("file"), 0644))
err := ensureSecureSocketDir(filepath.Join(blocker, "core.sock"))
require.Error(t, err)
assert.Contains(t, err.Error(), "not a directory")
}
func TestSocketDir_ensureSecureSocketDir_Ugly_SymlinkComponent(t *testing.T) {
baseDir := t.TempDir()
targetDir := filepath.Join(baseDir, "target")
linkDir := filepath.Join(baseDir, "link")
require.NoError(t, os.MkdirAll(targetDir, 0755))
if err := os.Symlink(targetDir, linkDir); err != nil {
t.Skipf("symlinks are not available: %v", err)
}
err := ensureSecureSocketDir(filepath.Join(linkDir, "core.sock"))
require.Error(t, err)
assert.Contains(t, err.Error(), "symlink")
}