mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 11:08:10 +00:00
Vault 3992 ToB Config and Plugins Permissions (#14817)
* updating changes from ent PR * adding changelog * fixing err * fixing semgrep error
This commit is contained in:
100
helper/osutil/fileinfo_unix_test.go
Normal file
100
helper/osutil/fileinfo_unix_test.go
Normal file
@@ -0,0 +1,100 @@
|
||||
//go:build !windows
|
||||
|
||||
package osutil
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/user"
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFileUIDEqual(t *testing.T) {
|
||||
currentUser, err := user.Current()
|
||||
if err != nil {
|
||||
t.Errorf("failed to get details of current process owner. The error is: %v", err)
|
||||
}
|
||||
uid, err := strconv.Atoi(currentUser.Uid)
|
||||
if err != nil {
|
||||
t.Errorf("failed to convert uid to int. The error is: %v", err)
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
uid int
|
||||
expected bool
|
||||
}{
|
||||
{
|
||||
uid: uid,
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
uid: uid + 1,
|
||||
expected: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
err := os.Mkdir("testFile", 0o777)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
info, err := os.Stat("testFile")
|
||||
if err != nil {
|
||||
t.Errorf("error stating %q: %v", "testFile", err)
|
||||
}
|
||||
|
||||
result := FileUIDEqual(info, tc.uid)
|
||||
if result != tc.expected {
|
||||
t.Errorf("invalid result. expected %t for uid %v", tc.expected, tc.uid)
|
||||
}
|
||||
err = os.RemoveAll("testFile")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileGIDEqual(t *testing.T) {
|
||||
currentUser, err := user.Current()
|
||||
if err != nil {
|
||||
t.Errorf("failed to get details of current process owner. The error is: %v", err)
|
||||
}
|
||||
gid, err := strconv.Atoi(currentUser.Gid)
|
||||
if err != nil {
|
||||
t.Errorf("failed to convert gid to int. The error is: %v", err)
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
gid int
|
||||
expected bool
|
||||
}{
|
||||
{
|
||||
gid: gid,
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
gid: gid + 1,
|
||||
expected: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
err := os.Mkdir("testFile", 0o777)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
info, err := os.Stat("testFile")
|
||||
if err != nil {
|
||||
t.Errorf("error stating %q: %v", "testFile", err)
|
||||
}
|
||||
|
||||
result := FileGIDEqual(info, tc.gid)
|
||||
if result != tc.expected {
|
||||
t.Errorf("invalid result. expected %t for gid %v", tc.expected, tc.gid)
|
||||
}
|
||||
err = os.RemoveAll("testFile")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user