Skip to content

Commit 0dfbe29

Browse files
committed
fix lint issue
1 parent 23d0265 commit 0dfbe29

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

internal/config/types.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -504,16 +504,14 @@ func isAllowedDir(path string, allowedDirs []string) (bool, error) {
504504
path = filepath.Dir(path)
505505
}
506506
if err != nil {
507-
if os.IsNotExist(err) {
508-
// Path does not exist, we can still check if it's an allowed directory
509-
} else {
507+
if !os.IsNotExist(err) {
510508
// Some other error occurred
511509
return false, fmt.Errorf("PathError %s %w", path, err)
512-
}
510+
} // else the path does not exist, we will check if it's in an allowed directory
513511
}
514512

515513
for _, dir := range allowedDirs {
516-
// Check if the path is a subdirectory of the allowed directory
514+
// Check if the path is a direct match, or is a subdirectory of the allowed directory
517515
if slices.Contains(allowedDirs, path) || strings.HasPrefix(path, dir+"/") {
518516
slog.Info(fmt.Sprintf("Allowed directory %s is allowed", path))
519517
return true, nil

internal/config/types_test.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,7 @@ func TestTypes_isAllowedDir(t *testing.T) {
6767
filePath: "/not-nginx-test/idontexist.conf",
6868
},
6969
{
70-
name: "Test 7: File is in allowed directory with trailing slash",
71-
allowed: true,
72-
allowedDirs: []string{
73-
"/etc/nginx/",
74-
},
75-
filePath: "/etc/nginx/nginx.conf",
76-
},
77-
{
78-
name: "Test 8: Prefix match",
70+
name: "Test 7: Prefix match not allowed",
7971
allowed: false,
8072
allowedDirs: []string{
8173
"/etc/nginx",

0 commit comments

Comments
 (0)