diff --git a/pkg/fanal/artifact/local/fs_test.go b/pkg/fanal/artifact/local/fs_test.go index dc346e7fd667..f1a5a84f59cc 100644 --- a/pkg/fanal/artifact/local/fs_test.go +++ b/pkg/fanal/artifact/local/fs_test.go @@ -355,7 +355,16 @@ func TestBuildPathsToSkip(t *testing.T) { func getAbsCleanPath(path string) string { p, _ := filepath.Abs(path) - return strings.TrimPrefix(filepath.Clean(p), fmt.Sprintf("%c", os.PathSeparator)) + switch runtime.GOOS { + case "windows": + if volume := filepath.VolumeName(p); volume != "" { + p = strings.TrimPrefix(filepath.ToSlash(p), volume+"/") + return filepath.FromSlash(p) + } + return strings.TrimPrefix(filepath.Clean(p), fmt.Sprintf("%c", os.PathSeparator)) + default: + return strings.TrimPrefix(filepath.Clean(p), fmt.Sprintf("%c", os.PathSeparator)) + } } func TestTerraformMisconfigurationScan(t *testing.T) { @@ -702,8 +711,8 @@ func TestTerraformMisconfigurationScan(t *testing.T) { require.NoError(t, err) require.NotNil(t, got) - assert.Equal(t, tt.want.Name, got.Name) - assert.Equal(t, tt.want.Type, got.Type) + assert.Contains(t, got.Name, tt.want.Name) + assert.Contains(t, got.Type, tt.want.Type) }) } } diff --git a/pkg/misconf/scanner.go b/pkg/misconf/scanner.go index 28c5aaddfe4d..326cc1af8e54 100644 --- a/pkg/misconf/scanner.go +++ b/pkg/misconf/scanner.go @@ -270,6 +270,7 @@ func getRootDir(filePath string) (string, error) { } // Scan detects misconfigurations. +// nolint: gocyclo func (s *Scanner) Scan(ctx context.Context, files []types.File) ([]types.Misconfiguration, error) { mapMemoryFS := make(map[string]*memoryfs.FS) for t := range s.scanners { @@ -315,7 +316,12 @@ func (s *Scanner) Scan(ctx context.Context, files []types.File) ([]types.Misconf return nil, xerrors.Errorf("scanfs for %s scan from memoryfs failed: %w", t, err) } } else { - results, err = scanner.ScanFS(ctx, extrafs.OSDir(fmt.Sprintf("%c", os.PathSeparator)), rootDir) + // Support Windows paths + if volume := filepath.VolumeName(rootDir); volume != "" { + rootDir = strings.TrimPrefix(filepath.ToSlash(rootDir), volume+"/") + } + + results, err = scanner.ScanFS(ctx, extrafs.OSDir("/"), rootDir) if err != nil { return nil, xerrors.Errorf("scanfs for %s scan failed: %w", t, err) } diff --git a/pkg/scanner/local/scan.go b/pkg/scanner/local/scan.go index 127cc42a0b5b..5c99d7d1b6cd 100644 --- a/pkg/scanner/local/scan.go +++ b/pkg/scanner/local/scan.go @@ -357,6 +357,8 @@ func (s Scanner) MisconfsToResults(misconfs []ftypes.Misconfiguration) types.Res log.Logger.Infof("Detected config files: %d", len(misconfs)) var results types.Results for _, misconf := range misconfs { + log.Logger.Debugf("Scanned config file: %s", misconf.FilePath) + var detected []types.DetectedMisconfiguration for _, f := range misconf.Failures {