@@ -11,19 +11,17 @@ import (
1111 "encoding/json"
1212 "net/http"
1313 "net/url"
14+ "strings"
1415 "testing"
1516 "time"
1617
1718 "github.com/stretchr/testify/require"
1819
19- "github.com/elastic/elastic-agent-libs/kibana"
2020 "github.com/elastic/elastic-agent/pkg/testing/define"
2121 "github.com/elastic/elastic-agent/pkg/testing/tools/fleettools"
2222 "github.com/elastic/elastic-agent/testing/integration"
2323)
2424
25- const cloudAgentPolicyID = "policy-elastic-agent-on-cloud"
26-
2725// TestFIPSAgentConnectingToFIPSFleetServerInECHFRH ensures that a FIPS-capable Elastic Agent
2826// running in an ECH FRH (FedRamp High) environment is able to successfully connect to its
2927// own local Fleet Server instance (which, by definition should also be FIPS-capable and
@@ -62,30 +60,47 @@ func TestFIPSAgentConnectingToFIPSFleetServerInECHFRH(t *testing.T) {
6260
6361 require .Equalf (t , "HEALTHY" , body .Status , "response status code: %d" , resp .StatusCode )
6462
65- // Get all Agents
63+ // Get agent running cloud policy
6664 require .Eventually (t , func () bool {
6765 ctx , cancel := context .WithTimeout (t .Context (), 5 * time .Second )
6866 defer cancel ()
69- agents , err := info .KibanaClient .ListAgents (ctx , kibana.ListAgentsRequest {})
67+
68+ searchResp , err := info .ESClient .Search (info .ESClient .Search .WithContext (ctx ), info .ESClient .Search .WithIndex (".fleet-agents" ), info .ESClient .Search .WithBody (strings .NewReader (`{
69+ "query": {
70+ "term": {
71+ "policy_id": "policy-elastic-agent-on-cloud"
72+ }
73+ }
74+ }` )))
7075 require .NoError (t , err )
76+ defer searchResp .Body .Close ()
77+ require .Equal (t , http .StatusOK , searchResp .StatusCode )
7178
72- // Find Fleet Server's own Agent and get its status and whether it's
73- // FIPS-capable
74- var agentStatus string
75- var agentIsFIPS bool
76- for _ , item := range agents .Items {
77- if item .PolicyID == cloudAgentPolicyID {
78- t .Logf ("Found fleet-server entry: %+v" , item )
79- agentStatus = item .Status
80- agentIsFIPS = item .LocalMetadata .Elastic .Agent .FIPS
81- break
82- }
83- }
79+ respObj := struct {
80+ Hits struct {
81+ Total struct {
82+ Value int `json:"value"`
83+ } `json:"total"`
84+ Hits []struct {
85+ Source struct {
86+ LocalMetadata struct {
87+ Elastic struct {
88+ Agent struct {
89+ FIPS bool `json:"fips"`
90+ } `json:"agent"`
91+ } `json:"elastic"`
92+ } `json:"local_metadata"`
93+ LastCheckinStatus string `json:"last_checkin_status"`
94+ LastCheckinReason string `json:"last_checkin_reason"`
95+ } `json:"_source"`
96+ } `json:"hits"`
97+ } `json:"hits"`
98+ }{}
8499
85- // Check that this Agent is online (i.e. healthy) and is FIPS-capable. This
86- // will prove that a FIPS-capable Agent is able to connect to a FIPS-capable
87- // Fleet Server, with both running in ECH.
88- require . Equal ( t , "online" , agentStatus )
89- return agentIsFIPS
100+ err = json . NewDecoder ( searchResp . Body ). Decode ( & respObj )
101+ require . NoError ( t , err )
102+ require . Equal ( t , 1 , respObj . Hits . Total . Value , "expected only one hit from the ES query" )
103+ t . Logf ( "FIPS: %v, Status: %s" , respObj . Hits . Hits [ 0 ]. Source . LocalMetadata . Elastic . Agent . FIPS , respObj . Hits . Hits [ 0 ]. Source . LastCheckinStatus )
104+ return respObj . Hits . Hits [ 0 ]. Source . LocalMetadata . Elastic . Agent . FIPS && respObj . Hits . Hits [ 0 ]. Source . LastCheckinStatus == "online"
90105 }, 10 * time .Second , 200 * time .Millisecond , "Fleet Server's Elastic Agent should be healthy and FIPS-capable" )
91106}
0 commit comments