diff --git a/internal/plugin/installer/http_installer_test.go b/internal/plugin/installer/http_installer_test.go index 3ae813b14..cbea756a1 100644 --- a/internal/plugin/installer/http_installer_test.go +++ b/internal/plugin/installer/http_installer_test.go @@ -29,7 +29,6 @@ import ( "path/filepath" "strconv" "strings" - "syscall" "testing" "github.com/stretchr/testify/assert" @@ -167,8 +166,7 @@ func TestExtract(t *testing.T) { tempDir := t.TempDir() // Get current umask to predict expected permissions - currentUmask := syscall.Umask(0) - syscall.Umask(currentUmask) + currentUmask := processUmask() // Write a tarball to a buffer for us to extract var tarbuf bytes.Buffer @@ -226,8 +224,10 @@ func TestExtract(t *testing.T) { require.NotErrorIs(t, err, fs.ErrNotExist, "Expected %s to exist but doesn't", pluginYAMLFullPath) } require.NoError(t, err) - require.Equalf(t, expectedPluginYAMLPerm, info.Mode().Perm(), "Expected %s to have %o mode but has %o (umask: %o)", - pluginYAMLFullPath, expectedPluginYAMLPerm, info.Mode().Perm(), currentUmask) + if posixPermsSupported { + require.Equalf(t, expectedPluginYAMLPerm, info.Mode().Perm(), "Expected %s to have %o mode but has %o (umask: %o)", + pluginYAMLFullPath, expectedPluginYAMLPerm, info.Mode().Perm(), currentUmask) + } readmeFullPath := filepath.Join(tempDir, "README.md") info, err = os.Stat(readmeFullPath) @@ -235,8 +235,10 @@ func TestExtract(t *testing.T) { require.NotErrorIs(t, err, fs.ErrNotExist, "Expected %s to exist but doesn't", readmeFullPath) } require.NoError(t, err) - require.Equalf(t, expectedReadmePerm, info.Mode().Perm(), "Expected %s to have %o mode but has %o (umask: %o)", - readmeFullPath, expectedReadmePerm, info.Mode().Perm(), currentUmask) + if posixPermsSupported { + require.Equalf(t, expectedReadmePerm, info.Mode().Perm(), "Expected %s to have %o mode but has %o (umask: %o)", + readmeFullPath, expectedReadmePerm, info.Mode().Perm(), currentUmask) + } } func TestCleanJoin(t *testing.T) { diff --git a/internal/plugin/installer/umask_unix_test.go b/internal/plugin/installer/umask_unix_test.go new file mode 100644 index 000000000..632509028 --- /dev/null +++ b/internal/plugin/installer/umask_unix_test.go @@ -0,0 +1,31 @@ +//go:build !windows + +/* +Copyright The Helm Authors. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package installer + +import "syscall" + +// posixPermsSupported reports whether the platform honors POSIX file +// permission bits, allowing tests to assert on extracted file modes. +const posixPermsSupported = true + +// processUmask returns the current process umask without changing it. +func processUmask() int { + umask := syscall.Umask(0) + syscall.Umask(umask) + return umask +} diff --git a/internal/plugin/installer/umask_windows_test.go b/internal/plugin/installer/umask_windows_test.go new file mode 100644 index 000000000..fd60c0191 --- /dev/null +++ b/internal/plugin/installer/umask_windows_test.go @@ -0,0 +1,28 @@ +//go:build windows + +/* +Copyright The Helm Authors. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package installer + +// posixPermsSupported reports whether the platform honors POSIX file +// permission bits, allowing tests to assert on extracted file modes. +// Windows does not, so permission assertions are skipped there. +const posixPermsSupported = false + +// processUmask returns 0 on Windows, which has no umask concept. +func processUmask() int { + return 0 +}