Add python to allowed script extensions (#43467)

Fixes #43334
This commit is contained in:
Carlo 2026-04-13 14:46:54 -04:00 committed by GitHub
parent 3e7afc8752
commit ce21d9172a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 0 deletions

View file

@ -1140,6 +1140,7 @@ var defaultAllowedExtensions = map[string]bool{
var allowedScriptExtensions = map[string]bool{
".sh": true,
".ps1": true,
".py": true,
}
// GlobExpandOptions configures how flattenBaseItems expands glob patterns.

View file

@ -2007,6 +2007,25 @@ func TestResolveScriptPaths(t *testing.T) {
require.Len(t, result, 2)
})
t.Run("glob_filters_non_script_extensions", func(t *testing.T) {
t.Parallel()
dir := t.TempDir()
require.NoError(t, os.WriteFile(filepath.Join(dir, "a.sh"), []byte("#!/bin/bash"), 0o644))
require.NoError(t, os.WriteFile(filepath.Join(dir, "b.ps1"), []byte("Write-Host"), 0o644))
require.NoError(t, os.WriteFile(filepath.Join(dir, "c.py"), []byte("#!/usr/bin/env python3"), 0o644))
require.NoError(t, os.WriteFile(filepath.Join(dir, "d.txt"), []byte("not a script"), 0o644))
items := []fleet.BaseItem{{Paths: ptr.String("*")}} //nolint:modernize
result, errs := resolveScriptPaths(items, dir, nopLogf)
require.Empty(t, errs)
require.Len(t, result, 3)
got := make([]string, 0, len(result))
for _, r := range result {
got = append(got, filepath.Base(*r.Path))
}
assert.Equal(t, []string{"a.sh", "b.ps1", "c.py"}, got)
})
t.Run("inline_not_allowed", func(t *testing.T) {
t.Parallel()
items := []fleet.BaseItem{{}}