-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathdomain_test.go
More file actions
198 lines (167 loc) · 7.35 KB
/
Copy pathdomain_test.go
File metadata and controls
198 lines (167 loc) · 7.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
// 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 2023-present Datadog, Inc.
package domain
import (
"fmt"
"path/filepath"
"reflect"
"testing"
"time"
"github.com/DataDog/datadog-agent/test/e2e-framework/components/activedirectory"
scenwindows "github.com/DataDog/datadog-agent/test/e2e-framework/scenarios/aws/ec2/windows"
awsHostWindows "github.com/DataDog/datadog-agent/test/e2e-framework/testing/provisioners/aws/host/windows"
agentclient "github.com/DataDog/datadog-agent/test/e2e-framework/testing/utils/e2e/client/agentclient"
"github.com/DataDog/datadog-agent/test/new-e2e/tests/windows"
"github.com/stretchr/testify/assert"
testifysuite "github.com/stretchr/testify/suite"
"github.com/DataDog/datadog-agent/test/e2e-framework/testing/e2e"
"github.com/DataDog/datadog-agent/test/e2e-framework/testing/environments"
platformCommon "github.com/DataDog/datadog-agent/test/new-e2e/tests/agent-platform/common"
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"
installtest "github.com/DataDog/datadog-agent/test/new-e2e/tests/windows/install-test"
)
const (
TestDomain = "datadogqalab.com"
TestUser = "TestUser"
TestPassword = "Test1234#"
)
func TestInstallsOnDomainController(t *testing.T) {
suites := []e2e.Suite[environments.WindowsHost]{
&testBasicInstallSuite{},
&testUpgradeSuite{},
&testInstallUserSyntaxSuite{},
}
for _, suite := range suites {
suite := suite
t.Run(reflect.TypeOf(suite).Elem().Name(), func(t *testing.T) {
t.Parallel()
e2e.Run(t, suite,
// Keep the stack alive on failure so the team can investigate Active
// Directory provisioning failures (see WINA-1965). A Datadog log monitor
// on the "SkipDeleteOnFailure feature is enabled" line notifies
// #windows-products-ops.
e2e.WithSkipDeleteOnFailure(),
e2e.WithProvisioner(awsHostWindows.ProvisionerNoAgent(
awsHostWindows.WithRunOptions(
scenwindows.WithActiveDirectoryOptions(
activedirectory.WithDomainController(TestDomain, TestPassword),
activedirectory.WithDomainUser(TestUser, TestPassword),
),
),
)))
})
}
}
type testInstallSuite struct {
windows.BaseAgentInstallerSuite[environments.WindowsHost]
}
func (suite *testInstallSuite) testGivenDomainUserCanInstallAgent(username string) {
host := suite.Env().RemoteHost
_, err := suite.InstallAgent(host,
windowsAgent.WithPackage(suite.AgentPackage),
windowsAgent.WithAgentUser(username),
windowsAgent.WithAgentUserPassword(fmt.Sprintf("\"%s\"", TestPassword)),
windowsAgent.WithValidAPIKey(),
windowsAgent.WithFakeIntake(suite.Env().FakeIntake),
windowsAgent.WithInstallLogFile(filepath.Join(suite.SessionOutputDir(), "TC-INS-DC-006_install.log")))
suite.Require().NoError(err, "should succeed to install Agent on a Domain Controller with a valid domain account & password")
suite.Run("user is a member of expected groups", func() {
installtest.AssertAgentUserGroupMembership(suite.T(), host,
windowsCommon.MakeDownLevelLogonName(TestDomain, TestUser),
)
})
tc := suite.NewTestClientForHost(suite.Env().RemoteHost)
tc.CheckAgentVersion(suite.T(), suite.AgentPackage.AgentVersion())
platformCommon.CheckAgentBehaviour(suite.T(), tc)
suite.EventuallyWithT(func(c *assert.CollectT) {
stats, err := suite.Env().FakeIntake.Client().RouteStats()
assert.NoError(c, err)
assert.NotEmpty(c, stats)
}, 5*time.Minute, 10*time.Second)
}
type testBasicInstallSuite struct {
testInstallSuite
}
func (suite *testBasicInstallSuite) TestGivenDomainUserCanInstallAgent() {
suite.testGivenDomainUserCanInstallAgent(fmt.Sprintf("%s\\%s", TestDomain, TestUser))
}
type testInstallUserSyntaxSuite struct {
testInstallSuite
}
func (suite *testInstallUserSyntaxSuite) TestGivenDomainUserCanInstallAgent() {
suite.testGivenDomainUserCanInstallAgent(fmt.Sprintf("%s@%s", TestUser, TestDomain))
}
type testUpgradeSuite struct {
windows.BaseAgentInstallerSuite[environments.WindowsHost]
}
func (suite *testUpgradeSuite) TestGivenDomainUserCanUpgradeAgent() {
host := suite.Env().RemoteHost
_, err := suite.InstallAgent(host,
windowsAgent.WithLastStablePackage(),
windowsAgent.WithAgentUser(fmt.Sprintf("%s\\%s", TestDomain, TestUser)),
windowsAgent.WithAgentUserPassword(fmt.Sprintf("\"%s\"", TestPassword)),
windowsAgent.WithValidAPIKey(),
windowsAgent.WithFakeIntake(suite.Env().FakeIntake),
windowsAgent.WithInstallLogFile(filepath.Join(suite.SessionOutputDir(), "TC-UPG-DC-001_install_last_stable.log")))
suite.Require().NoError(err, "should succeed to install Agent on a Domain Controller with a valid domain account & password")
tc := suite.NewTestClientForHost(suite.Env().RemoteHost)
suite.setLogLevelDebug(tc)
platformCommon.CheckAgentBehaviour(suite.T(), tc)
_, err = suite.InstallAgent(host,
windowsAgent.WithPackage(suite.AgentPackage),
windowsAgent.WithInstallLogFile(filepath.Join(suite.SessionOutputDir(), "TC-UPG-DC-001_upgrade.log")))
suite.Require().NoError(err, "should succeed to upgrade an Agent on a Domain Controller")
suite.setLogLevelDebug(tc)
tc.CheckAgentVersion(suite.T(), suite.AgentPackage.AgentVersion())
platformCommon.CheckAgentBehaviour(suite.T(), tc)
suite.EventuallyWithT(func(c *assert.CollectT) {
stats, err := suite.Env().FakeIntake.Client().RouteStats()
assert.NoError(c, err)
assert.NotEmpty(c, stats)
}, 5*time.Minute, 10*time.Second)
}
// setLogLevelDebug sets the running Agent's log level to debug, to get more detail in the
// collected agent logs if this test fails (see AfterTest below). This is a runtime setting,
// so it must be re-applied after the Agent process restarts (e.g. after the upgrade step).
func (suite *testUpgradeSuite) setLogLevelDebug(tc *platformCommon.TestClient) {
_, err := tc.AgentClient.ConfigWithError(agentclient.WithArgs([]string{"set", "log_level", "debug"}))
suite.Require().NoError(err, "should set log_level to debug")
}
// AfterTest collects the Agent logs when the test fails, to help debug issues like the
// fakeintake connectivity failures tracked in WINA-3019.
func (suite *testUpgradeSuite) AfterTest(suiteName, testName string) {
if afterTest, ok := any(&suite.BaseAgentInstallerSuite).(testifysuite.AfterTest); ok {
afterTest.AfterTest(suiteName, testName)
}
if suite.T().Failed() {
suite.collectAgentLogs()
}
}
// collectAgentLogs downloads the agent log folder from the remote host into the session
// output dir. Best-effort: missing logs are surfaced as assertion failures but do not
// abort test cleanup.
func (suite *testUpgradeSuite) collectAgentLogs() {
vm := suite.Env().RemoteHost
suite.T().Logf("Collecting agent logs")
logsFolder, err := vm.GetLogsFolder()
if !suite.Assert().NoError(err, "should get logs folder") {
return
}
entries, err := vm.ReadDir(logsFolder)
if !suite.Assert().NoError(err, "should read log folder") {
return
}
for _, entry := range entries {
sourcePath := filepath.Join(logsFolder, entry.Name())
destPath := filepath.Join(suite.SessionOutputDir(), entry.Name())
if entry.IsDir() {
err = vm.GetFolder(sourcePath, destPath)
} else {
err = vm.GetFile(sourcePath, destPath)
}
suite.Assert().NoError(err, "should download %s", entry.Name())
}
}