Skip to content

Commit e61a64c

Browse files
committed
fix relative paths in benchmark test
1 parent 8d28e73 commit e61a64c

File tree

3 files changed

+4
-7
lines changed

3 files changed

+4
-7
lines changed

internal/config/types.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"context"
1010
"errors"
1111
"fmt"
12-
"log/slog"
1312
"path/filepath"
1413
"slices"
1514
"strings"
@@ -476,14 +475,11 @@ func isAllowedDir(path string, allowedDirs []string) bool {
476475
}
477476

478477
func checkDirIsAllowed(path string, allowedDirs []string) bool {
479-
slog.Info(filepath.Clean(path))
480478
if slices.Contains(allowedDirs, path) {
481-
slog.Info("Path is allowed", "path", path)
482479
return true
483480
}
484481

485-
if path == "/" { // root directory reached, path is not allowed
486-
slog.Info("Path is not allowed")
482+
if path == "/" || !strings.HasPrefix(path, "/") { // root directory reached with no match, path is not allowed
487483
return false
488484
}
489485

internal/datasource/config/nginx_config_parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func NewNginxConfigParser(agentConfig *config.Config) *NginxConfigParser {
7474
}
7575

7676
func (ncp *NginxConfigParser) Parse(ctx context.Context, instance *mpi.Instance) (*model.NginxConfigContext, error) {
77-
configPath := instance.GetInstanceRuntime().GetConfigPath()
77+
configPath, _ := filepath.Abs(instance.GetInstanceRuntime().GetConfigPath())
7878

7979
if !ncp.agentConfig.IsDirectoryAllowed(configPath) {
8080
return nil, fmt.Errorf("config path %s is not in allowed directories", configPath)

internal/datasource/config/nginx_config_parser_benchmark_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ func BenchmarkNginxConfigParser_Parse(b *testing.B) {
3535
for _, configFilePath := range configFilePaths {
3636
func(configFilePath string) {
3737
b.Run(configFilePath, func(bb *testing.B) {
38+
absPath, _ := filepath.Abs(configFilePath)
3839
agentConfig.AllowedDirectories = []string{
39-
filepath.Dir(configFilePath),
40+
filepath.Dir(absPath),
4041
}
4142

4243
nginxConfigParser := NewNginxConfigParser(

0 commit comments

Comments
 (0)