fix: updated config file permission requirements for windows (#9732)

* fix: reduced config file permission restriction on windows

Signed-off-by: Soumya Ghosh Dastidar <gdsoumya@gmail.com>

* fix: updated localconfig tests to check error

Signed-off-by: Soumya Ghosh Dastidar <gdsoumya@gmail.com>
This commit is contained in:
Soumya Ghosh Dastidar
2022-06-22 00:32:26 +05:30
committed by GitHub
parent 1639981806
commit 88708504f3
4 changed files with 35 additions and 9 deletions

View File

@@ -0,0 +1,16 @@
//go:build !windows
package localconfig
import (
"fmt"
"os"
)
func getFilePermission(fi os.FileInfo) error {
if fi.Mode().Perm() == 0600 || fi.Mode().Perm() == 0400 {
return nil
}
return fmt.Errorf("config file has incorrect permission flags:%s."+
"change the file permission either to 0400 or 0600.", fi.Mode().Perm().String())
}

View File

@@ -0,0 +1,16 @@
//go:build windows
package localconfig
import (
"fmt"
"os"
)
func getFilePermission(fi os.FileInfo) error {
if fi.Mode().Perm() == 0666 || fi.Mode().Perm() == 0444 {
return nil
}
return fmt.Errorf("config file has incorrect permission flags:%s."+
"change the file permission either to 0444 or 0666.", fi.Mode().Perm().String())
}

View File

@@ -311,11 +311,3 @@ func GetUsername(subject string) string {
}
return subject
}
func getFilePermission(fi os.FileInfo) error {
if fi.Mode().Perm() == 0600 || fi.Mode().Perm() == 0400 {
return nil
}
return fmt.Errorf("config file has incorrect permission flags:%s."+
"change the file permission either to 0400 or 0600.", fi.Mode().Perm().String())
}

View File

@@ -1,3 +1,5 @@
//go:build !windows
package localconfig
import (
@@ -83,7 +85,7 @@ func TestFilePermission(t *testing.T) {
if err := getFilePermission(fi); err != nil {
assert.EqualError(t, err, c.expectedError.Error())
} else {
require.Nil(t, err)
require.Nil(t, c.expectedError)
}
})
}