Skip to content

Commit 5208137

Browse files
authored
fix faro tests windows (#3643)
* fix faro tests windows * remove invalid path test
1 parent 667b7d6 commit 5208137

File tree

2 files changed

+2
-64
lines changed

2 files changed

+2
-64
lines changed

internal/component/faro/receiver/sourcemaps.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type (
4646
type osFileService struct{}
4747

4848
func (fs osFileService) ValidateFilePath(name string) (string, error) {
49-
if strings.Contains(name, "\\") || strings.Contains(name, "..") {
49+
if strings.Contains(name, "..") {
5050
return "", fmt.Errorf("invalid file name: %s", name)
5151
}
5252
return name, nil

internal/component/faro/receiver/sourcemaps_test.go

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"path/filepath"
1111
"testing"
1212

13-
"github.com/go-kit/log"
1413
"github.com/grafana/alloy/internal/component/faro/receiver/internal/payload"
1514
alloyutil "github.com/grafana/alloy/internal/util"
1615
"github.com/prometheus/client_golang/prometheus"
@@ -601,71 +600,10 @@ func Test_sourceMapsStoreImpl_RealWorldPathValidation(t *testing.T) {
601600

602601
actual := transformException(logger, store, input, "123")
603602
require.Equal(t, input, actual)
604-
require.Equal(t, []string{"/foo/bar/baz/qux/folder/file.js.map"}, fileService.stats)
603+
require.Equal(t, []string{filepath.FromSlash("/foo/bar/baz/qux/folder/file.js.map")}, fileService.stats)
605604
require.Empty(t, fileService.reads, "should not read file when stat fails")
606605
}
607606

608-
func Test_sourceMapsStoreImpl_InvalidPathMetrics(t *testing.T) {
609-
var (
610-
logBuf bytes.Buffer
611-
logger = log.NewLogfmtLogger(log.NewSyncWriter(&logBuf))
612-
reg = prometheus.NewRegistry()
613-
store = newSourceMapsStore(
614-
logger,
615-
SourceMapsArguments{
616-
Download: false,
617-
Locations: []LocationArguments{
618-
{
619-
MinifiedPathPrefix: "http://foo.com/",
620-
Path: "/var/build/latest/",
621-
},
622-
},
623-
},
624-
newSourceMapMetrics(reg),
625-
nil,
626-
newTestFileService(),
627-
)
628-
)
629-
630-
input := &payload.Exception{
631-
Stacktrace: &payload.Stacktrace{
632-
Frames: []payload.Frame{
633-
{
634-
Colno: 6,
635-
Filename: "http://foo.com/..\\etc\\passwd",
636-
Function: "eval",
637-
Lineno: 5,
638-
},
639-
},
640-
},
641-
}
642-
643-
transformException(logger, store, input, "123")
644-
645-
logOutput := logBuf.String()
646-
require.Contains(t, logOutput, "msg=\"source map path contains invalid characters\"")
647-
require.Contains(t, logOutput, "url=http://foo.com/..\\etc\\passwd")
648-
require.Contains(t, logOutput, "file_path=/var/build/latest/..\\etc\\passwd.map")
649-
650-
metrics, err := reg.Gather()
651-
require.NoError(t, err)
652-
653-
var found bool
654-
for _, metric := range metrics {
655-
if metric.GetName() == "faro_receiver_sourcemap_file_reads_total" {
656-
for _, m := range metric.GetMetric() {
657-
for _, label := range m.GetLabel() {
658-
if label.GetName() == "status" && label.GetValue() == "invalid_path" {
659-
found = true
660-
require.Equal(t, float64(1), m.GetCounter().GetValue())
661-
}
662-
}
663-
}
664-
}
665-
}
666-
require.True(t, found, "Expected to find metric with invalid_path status")
667-
}
668-
669607
type mockHTTPClient struct {
670608
responses []struct {
671609
*http.Response

0 commit comments

Comments
 (0)