Skip to content

Commit

Permalink
enhancment(4889): removed redundant unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kaanyalti committed Dec 11, 2024
1 parent 6931af0 commit 346eed7
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 77 deletions.
25 changes: 0 additions & 25 deletions internal/pkg/agent/cmd/enroll_match_fileowner_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,11 @@ package cmd
import (
"os"
"path/filepath"
"strconv"
"testing"

"github.com/stretchr/testify/require"
)

func TestGetFileOwnerUnix(t *testing.T) {
cu := os.Geteuid()

path := t.TempDir()
fp := filepath.Join(path, "testfile")
fi, err := os.Create(fp)
require.NoError(t, err)
defer fi.Close()

fo, err := getFileOwner(fp)
require.NoError(t, err)

require.Equal(t, fo, strconv.Itoa(cu))
}

func TestIsFileOwnerUnix(t *testing.T) {
cu := os.Geteuid()

isOwner, err := isFileOwner(strconv.Itoa(cu), strconv.Itoa(cu))
require.NoError(t, err)

require.True(t, isOwner)
}

func TestIsOwnerExecUnix(t *testing.T) {
path := t.TempDir()
fp := filepath.Join(path, "testfile")
Expand Down
52 changes: 0 additions & 52 deletions internal/pkg/agent/cmd/enroll_match_fileowner_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,58 +16,6 @@ import (
"golang.org/x/sys/windows"
)

func TestGetFileOwnerWindows(t *testing.T) {
var token windows.Token
err := windows.OpenProcessToken(windows.CurrentProcess(), windows.TOKEN_QUERY, &token)
require.NoError(t, err)
defer token.Close()

tokenUser, err := token.GetTokenUser()
require.NoError(t, err)

path := t.TempDir()
fp := filepath.Join(path, "testfile")
fi, err := os.Create(fp)
require.NoError(t, err)
defer fi.Close()

err = windows.SetNamedSecurityInfo(
fp,
windows.SE_FILE_OBJECT,
windows.OWNER_SECURITY_INFORMATION,
tokenUser.User.Sid,
nil,
nil,
nil,
)
require.NoError(t, err)

fo, err := getFileOwner(fp)
require.NoError(t, err)

var foSid *windows.SID
err = windows.ConvertStringSidToSid(windows.StringToUTF16Ptr(fo), &foSid)
require.NoError(t, err)

require.True(t, foSid.Equals(tokenUser.User.Sid))
}

func TestIsFileOwnerWindows(t *testing.T) {
var token windows.Token
err := windows.OpenProcessToken(windows.CurrentProcess(), windows.TOKEN_QUERY, &token)
require.NoError(t, err)
defer token.Close()

tokenUser, err := token.GetTokenUser()
require.NoError(t, err)

tStr := tokenUser.User.Sid.String()

eq, err := isFileOwner(tStr, tStr)
require.NoError(t, err)
require.True(t, eq, fmt.Sprintf("expected \"true\" received \"%v\"", eq))
}

func TestIsOwnerExecWindows(t *testing.T) {
path := t.TempDir()
fp := filepath.Join(path, "testfile")
Expand Down

0 comments on commit 346eed7

Please sign in to comment.