mirror of
https://github.com/gomods/athens
synced 2026-02-03 11:00:32 +00:00
Checks for windows permissions (#902)
* Checks for windows permissions * Fix bug * fix test * Update perms * Fix perms
This commit is contained in:
+10
-2
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/gomods/athens/pkg/errors"
|
||||
@@ -140,8 +141,15 @@ func checkFilePerms(files ...string) error {
|
||||
continue
|
||||
}
|
||||
|
||||
if fInfo.Mode() != 0600 {
|
||||
return errors.E(op, f+" should have 0600 as permission")
|
||||
if runtime.GOOS == "windows" {
|
||||
if (fInfo.Mode() & 0600) != 0600 {
|
||||
return errors.E(op, f+" should have 0600 as permission")
|
||||
}
|
||||
} else {
|
||||
// Assume unix based system (MacOS and Linux)
|
||||
if fInfo.Mode() != 0640 {
|
||||
return errors.E(op, f+" should have 0640 as permission")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -297,26 +297,34 @@ func restoreEnv(envVars map[string]string) {
|
||||
}
|
||||
}
|
||||
|
||||
func Test_checkFilePerms(t *testing.T) {
|
||||
// TODO: os.Chmod(..) doesn't work on Windows as it does on Unix
|
||||
// Skip for now
|
||||
// issue: https://github.com/gomods/athens/issues/879
|
||||
func invalidPerm() os.FileMode {
|
||||
if runtime.GOOS == "windows" {
|
||||
t.SkipNow()
|
||||
return 0200
|
||||
}
|
||||
return 0777
|
||||
}
|
||||
|
||||
func correctPerm() os.FileMode {
|
||||
if runtime.GOOS == "windows" {
|
||||
return 0600
|
||||
}
|
||||
return 0640
|
||||
}
|
||||
|
||||
func Test_checkFilePerms(t *testing.T) {
|
||||
f1, err := ioutil.TempFile(os.TempDir(), "prefix-")
|
||||
if err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
defer os.Remove(f1.Name())
|
||||
err = os.Chmod(f1.Name(), 0777)
|
||||
err = os.Chmod(f1.Name(), invalidPerm())
|
||||
|
||||
f2, err := ioutil.TempFile(os.TempDir(), "prefix-")
|
||||
if err != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
defer os.Remove(f2.Name())
|
||||
err = os.Chmod(f2.Name(), 0600)
|
||||
err = os.Chmod(f2.Name(), correctPerm())
|
||||
|
||||
type args struct {
|
||||
files []string
|
||||
|
||||
Reference in New Issue
Block a user