|
6 | 6 | package config |
7 | 7 |
|
8 | 8 | import ( |
9 | | - "os" |
10 | 9 | "testing" |
11 | 10 |
|
12 | 11 | "github.com/stretchr/testify/require" |
@@ -77,53 +76,3 @@ func TestTypes_isAllowedDir(t *testing.T) { |
77 | 76 | }) |
78 | 77 | } |
79 | 78 | } |
80 | | - |
81 | | -func TestTypes_isAllowedDirWithSymlink(t *testing.T) { |
82 | | - t.Run("Test 1: Symlink in allowed directory is not allowed", func(t *testing.T) { |
83 | | - allowedDirs := []string{"/etc/nginx"} |
84 | | - filePath := "file.conf" |
85 | | - symlinkPath := "file_link" |
86 | | - |
87 | | - // Create a temp directory for the symlink |
88 | | - tempDir := t.TempDir() |
89 | | - defer os.RemoveAll(tempDir) // Clean up the temp directory after the test |
90 | | - |
91 | | - // Ensure the temp directory is in the allowedDirs |
92 | | - allowedDirs = append(allowedDirs, tempDir) |
93 | | - |
94 | | - filePath = tempDir + "/" + filePath |
95 | | - defer os.RemoveAll(filePath) |
96 | | - err := os.WriteFile(filePath, []byte("test content"), 0o600) |
97 | | - require.NoError(t, err) |
98 | | - |
99 | | - // Create a symlink for testing |
100 | | - symlinkPath = tempDir + "/" + symlinkPath |
101 | | - defer os.Remove(symlinkPath) |
102 | | - err = os.Symlink(filePath, symlinkPath) |
103 | | - require.NoError(t, err) |
104 | | - |
105 | | - result, err := isAllowedDir(symlinkPath, allowedDirs) |
106 | | - require.Error(t, err) |
107 | | - require.False(t, result, "Symlink in allowed directory should return false") |
108 | | - }) |
109 | | -} |
110 | | - |
111 | | -func TestTypes_isSymlink(t *testing.T) { |
112 | | - // create temp dir |
113 | | - tempDir := t.TempDir() |
114 | | - tempConf := tempDir + "test.conf" |
115 | | - defer os.RemoveAll(tempDir) |
116 | | - |
117 | | - t.Run("Test 1: File is not a symlink", func(t *testing.T) { |
118 | | - filePath := tempConf |
119 | | - err := os.WriteFile(filePath, []byte("test content"), 0o600) |
120 | | - require.NoError(t, err) |
121 | | - require.False(t, isSymlink(filePath), "File is not a symlink") |
122 | | - }) |
123 | | - t.Run("Test 2: File is a symlink", func(t *testing.T) { |
124 | | - filePath := tempDir + "test_conf_link" |
125 | | - err := os.Symlink(tempConf, filePath) |
126 | | - require.NoError(t, err) |
127 | | - require.True(t, isSymlink(filePath), "File is a symlink") |
128 | | - }) |
129 | | -} |
0 commit comments