@@ -9,14 +9,14 @@ package integration
9
9
import (
10
10
"context"
11
11
"fmt"
12
- "os/exec"
13
12
"testing"
14
13
"time"
15
14
16
15
"github.com/google/uuid"
17
16
"github.com/stretchr/testify/require"
18
17
19
18
"github.com/elastic/elastic-agent-libs/kibana"
19
+ "github.com/elastic/elastic-agent/internal/pkg/agent/install"
20
20
atesting "github.com/elastic/elastic-agent/pkg/testing"
21
21
"github.com/elastic/elastic-agent/pkg/testing/define"
22
22
"github.com/elastic/elastic-agent/pkg/testing/tools"
@@ -30,7 +30,6 @@ func TestDelayEnroll(t *testing.T) {
30
30
Stack : & define.Stack {},
31
31
Local : false ,
32
32
Sudo : true ,
33
- OS : []define.OS {{Type : define .Linux }},
34
33
})
35
34
36
35
ctx , cancel := testcontext .WithDeadline (t , context .Background (), time .Now ().Add (10 * time .Minute ))
@@ -64,6 +63,7 @@ func TestDelayEnroll(t *testing.T) {
64
63
NonInteractive : true ,
65
64
Force : true ,
66
65
DelayEnroll : true ,
66
+ Privileged : false ,
67
67
}
68
68
// Install the Elastic-Agent with the policy that was just
69
69
// created.
@@ -77,11 +77,69 @@ func TestDelayEnroll(t *testing.T) {
77
77
require .NoError (t , err )
78
78
79
79
// Start elastic-agent via service, this should do the enrollment
80
- cmd := exec .Command ("/usr/bin/systemctl" , "start" , "elastic-agent" )
81
- stdErrStdout , err := cmd .CombinedOutput ()
82
- require .NoErrorf (t , err , "systemctl start elastic-agent output was %s" , stdErrStdout )
80
+ err = install .StartService ("" ) // topPath can be blank as this is only starting the service
81
+ require .NoErrorf (t , err , "failed to start service" )
83
82
84
83
// check to make sure enroll worked
85
84
check .ConnectedToFleet (ctx , t , agentFixture , 5 * time .Minute )
85
+ }
86
+
87
+ func TestDelayEnrollUnprivileged (t * testing.T ) {
88
+ info := define .Require (t , define.Requirements {
89
+ Group : Fleet ,
90
+ Stack : & define.Stack {},
91
+ Local : false ,
92
+ Sudo : true ,
93
+ })
94
+
95
+ ctx , cancel := testcontext .WithDeadline (t , context .Background (), time .Now ().Add (10 * time .Minute ))
96
+ defer cancel ()
97
+
98
+ agentFixture , err := define .NewFixtureFromLocalBuild (t , define .Version ())
99
+ require .NoError (t , err )
100
+
101
+ // 1. Create a policy in Fleet with monitoring enabled.
102
+ // To ensure there are no conflicts with previous test runs against
103
+ // the same ESS stack, we add a UUID at the end of the policy
104
+ // name. This policy does not contain any integration.
105
+ t .Log ("Enrolling agent in Fleet with a test policy" )
106
+ createPolicyReq := kibana.AgentPolicy {
107
+ Name : fmt .Sprintf ("test-policy-enroll-%s" , uuid .New ().String ()),
108
+ Namespace : info .Namespace ,
109
+ Description : "test policy for agent enrollment" ,
110
+ MonitoringEnabled : []kibana.MonitoringEnabledOption {
111
+ kibana .MonitoringEnabledLogs ,
112
+ kibana .MonitoringEnabledMetrics ,
113
+ },
114
+ AgentFeatures : []map [string ]interface {}{
115
+ {
116
+ "name" : "test_enroll" ,
117
+ "enabled" : true ,
118
+ },
119
+ },
120
+ }
86
121
122
+ installOpts := atesting.InstallOpts {
123
+ NonInteractive : true ,
124
+ Force : true ,
125
+ DelayEnroll : true ,
126
+ Privileged : false ,
127
+ }
128
+ // Install the Elastic-Agent with the policy that was just
129
+ // created.
130
+ _ , err = tools .InstallAgentWithPolicy (
131
+ ctx ,
132
+ t ,
133
+ installOpts ,
134
+ agentFixture ,
135
+ info .KibanaClient ,
136
+ createPolicyReq )
137
+ require .NoError (t , err )
138
+
139
+ // Start elastic-agent via service, this should do the enrollment
140
+ err = install .StartService ("" ) // topPath can be blank as this is only starting the service
141
+ require .NoErrorf (t , err , "failed to start service" )
142
+
143
+ // check to make sure enroll worked
144
+ check .ConnectedToFleet (ctx , t , agentFixture , 5 * time .Minute )
87
145
}
0 commit comments