Skip to content

Commit

Permalink
[windows][e2e] Port security agent functional tests to e2e (#27611)
Browse files Browse the repository at this point in the history
  • Loading branch information
derekwbrown authored Jul 18, 2024
1 parent 1296242 commit bec830a
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@
/test/new-e2e/tests/orchestrator @DataDog/container-app
/test/new-e2e/tests/process @DataDog/processes
/test/new-e2e/tests/sysprobe-functional @DataDog/windows-kernel-integrations
/test/new-e2e/tests/security-agent-functional @DataDog/windows-kernel-integrations
/test/new-e2e/tests/cws @DataDog/agent-security
/test/new-e2e/tests/agent-metrics-logs @DataDog/agent-metrics-logs
/test/new-e2e/tests/windows @DataDog/windows-agent @DataDog/windows-kernel-integrations
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

package secagentfunctional

import (
"flag"
"os"
"path/filepath"
"testing"
"time"

"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments"
awshost "github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments/aws/host"
"github.com/DataDog/datadog-agent/test/new-e2e/tests/windows"
windowsCommon "github.com/DataDog/datadog-agent/test/new-e2e/tests/windows/common"
windowsAgent "github.com/DataDog/datadog-agent/test/new-e2e/tests/windows/common/agent"
componentsos "github.com/DataDog/test-infra-definitions/components/os"
"github.com/DataDog/test-infra-definitions/scenarios/aws/ec2"
"github.com/stretchr/testify/require"
)

type vmSuite struct {
e2e.BaseSuite[environments.Host]

testspath string
}

var (
devMode = flag.Bool("devmode", false, "run tests in dev mode")
)

func TestVMSuite(t *testing.T) {
suiteParams := []e2e.SuiteOption{e2e.WithProvisioner(awshost.ProvisionerNoAgentNoFakeIntake(awshost.WithEC2InstanceOptions(ec2.WithOS(componentsos.WindowsDefault))))}
if *devMode {
suiteParams = append(suiteParams, e2e.WithDevMode())
}

e2e.Run(t, &vmSuite{}, suiteParams...)
}

func (v *vmSuite) SetupSuite() {
t := v.T()

// Get the absolute path to the test assets directory
currDir, err := os.Getwd()
require.NoError(t, err)

reporoot, _ := filepath.Abs(filepath.Join(currDir, "..", "..", "..", ".."))
kitchenDir := filepath.Join(reporoot, "test", "kitchen", "site-cookbooks")
v.testspath = filepath.Join(kitchenDir, "dd-security-agent-check", "files", "tests")
}

func (v *vmSuite) TestSystemProbeCWSSuite() {
v.BaseSuite.SetupSuite()
t := v.T()
// get the remote host
vm := v.Env().RemoteHost

rs := windows.NewRemoteExecutable(vm, t, "testsuite.exe", v.testspath)
err := rs.FindTestPrograms()
require.NoError(t, err)

err = rs.CreateRemotePaths()
require.NoError(t, err)

err = rs.CopyFiles()
require.NoError(t, err)

// install the agent (just so we can get the driver(s) installed)
agentPackage, err := windowsAgent.GetPackageFromEnv()
require.NoError(t, err)
remoteMSIPath, err := windowsCommon.GetTemporaryFile(vm)
require.NoError(t, err)
t.Logf("Getting install package %s...", agentPackage.URL)
err = windowsCommon.PutOrDownloadFile(vm, agentPackage.URL, remoteMSIPath)
require.NoError(t, err)

err = windowsCommon.InstallMSI(vm, remoteMSIPath, "", "")
t.Log("Install complete")
require.NoError(t, err)

time.Sleep(30 * time.Second)
// disable the agent, and enable the drivers for testing
_, err = vm.Execute("stop-service -force datadogagent")
require.NoError(t, err)
_, err = vm.Execute("sc.exe config datadogagent start= disabled")
require.NoError(t, err)
_, err = vm.Execute("sc.exe config ddnpm start= demand")
require.NoError(t, err)
_, err = vm.Execute("start-service ddnpm")
require.NoError(t, err)

rs.RunTests("5m") // security agent tests can take a while waiting for ETW to start.
}
4 changes: 2 additions & 2 deletions test/new-e2e/tests/sysprobe-functional/sysprobe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (v *vmSuite) SetupSuite() {
v.testspath = filepath.Join(kitchenDir, "dd-system-probe-check", "files", "default", "tests")
}

func (v *vmSuite) TestSystemProbeSuite() {
func (v *vmSuite) TestSystemProbeNPMSuite() {
v.BaseSuite.SetupSuite()
t := v.T()
// get the remote host
Expand Down Expand Up @@ -127,5 +127,5 @@ func (v *vmSuite) TestSystemProbeSuite() {
_, err = vm.Execute("start-service ddnpm")
require.NoError(t, err)

rs.RunTests()
rs.RunTests("")
}
9 changes: 7 additions & 2 deletions test/new-e2e/tests/windows/remoteexecutable.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,20 @@ func (rs *RemoteExecutable) CopyFiles() error {

// RunTests iterates through all of the tests that were copied and executes them one by one.
// it captures the output, and logs it.
func (rs *RemoteExecutable) RunTests() error {
func (rs *RemoteExecutable) RunTests(timeoutarg string) error {

if timeoutarg == "" {
timeoutarg = "2m"
}
tmo := "\"-test.timeout=" + timeoutarg + "\""

for _, testsuite := range rs.testfiles {
rs.t.Logf("Running testsuite: %s", testsuite)
remotePath := filepath.Join(remoteDirBase, testsuite) //, "testsuite.exe")

// google test programs compiled in this way run with no timeout by default.
// don't allow an individual test to take too long
executeAndLogOutput(rs.t, rs.vm, remotePath, "\"-test.v\"", "\"-test.timeout=2m\"")
executeAndLogOutput(rs.t, rs.vm, remotePath, "\"-test.v\"", tmo)
}
return nil
}
Expand Down

0 comments on commit bec830a

Please sign in to comment.