diff --git a/pkg/config/config.go b/pkg/config/config.go index b8f0e9e53..408ba6582 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -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") + } } } diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 13dd25ccc..40fbc1f89 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -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" { + return 0200 + } + return 0777 +} + +func correctPerm() os.FileMode { if runtime.GOOS == "windows" { - t.SkipNow() + 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