Skip to content

Commit

Permalink
dont run tests without elevated permissions on windows, fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Pickett committed Apr 2, 2024
1 parent b92989d commit d1dadc7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/osquery/runtime/runtime_posix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@ func requirePgidMatch(t *testing.T, pid int) {
require.Equal(t, pgid, pid)
}

// TestOsquerySlowStart tests that the launcher can handle a slow-starting osqueryd process.
// This this is only enabled on non-Windows platforms because suspending we have not yet
// figured out how to suspend a process on windows via golang.
// hasPermissionsToRunTest always return true for non-windows platforms since
// elveated permissions are not required to run the tests
func hasPermissionsToRunTest() bool {
return true
}

// TestOsquerySlowStart tests that launcher can handle a slow-starting osqueryd process.
// This this is only enabled on non-Windows platforms because we have not yet figured
// out how to suspend and resume a process on Windows via golang.
func TestOsquerySlowStart(t *testing.T) {
t.Parallel()
rootDirectory, rmRootDirectory, err := osqueryTempDir()
Expand Down
5 changes: 5 additions & 0 deletions pkg/osquery/runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ var testOsqueryBinaryDirectory string

// TestMain overrides the default test main function. This allows us to share setup/teardown.
func TestMain(m *testing.M) {
if !hasPermissionsToRunTest() {
fmt.Println("these tests must be run as an administrator on windows")
return
}

binDirectory, rmBinDirectory, err := osqueryTempDir()
if err != nil {
fmt.Println("Failed to make temp dir for test binaries")
Expand Down
8 changes: 8 additions & 0 deletions pkg/osquery/runtime/runtime_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ package runtime

import (
"testing"

"golang.org/x/sys/windows"
)

func requirePgidMatch(_ *testing.T, _ int) {}

// hasPermissionsToRunTest return true if the current process has elevated permissions (administrator),
// this is required to run tests on windows
func hasPermissionsToRunTest() bool {
return windows.GetCurrentProcessToken().IsElevated()
}

0 comments on commit d1dadc7

Please sign in to comment.