@@ -12,6 +12,8 @@ import (
1212 "encoding/json"
1313 "testing"
1414
15+ ftesting "github.com/elastic/fleet-server/v7/internal/pkg/testing"
16+
1517 "github.com/stretchr/testify/require"
1618
1719 "github.com/elastic/fleet-server/v7/internal/pkg/model"
@@ -29,6 +31,9 @@ var logstashOutputPolicy string
2931//go:embed testdata/remote_es_policy.json
3032var testPolicyRemoteES string
3133
34+ //go:embed testdata/policy_with_secrets.json
35+ var policyWithSecrets string
36+
3237func TestNewParsedPolicy (t * testing.T ) {
3338 // Run two formatting of the same payload to validate that the sha2 remains the same
3439 testcases := []struct {
@@ -102,3 +107,24 @@ func TestNewParsedPolicyRemoteES(t *testing.T) {
102107 // Validate that default was found
103108 require .Equal (t , "remote" , pp .Default .Name )
104109}
110+
111+ func TestNewParsedPolicyWithSecrets (t * testing.T ) {
112+ // Load the model into the policy object
113+ var m model.Policy
114+ var d model.PolicyData
115+ err := json .Unmarshal ([]byte (policyWithSecrets ), & d )
116+ require .NoError (t , err )
117+
118+ m .Data = & d
119+
120+ bulker := ftesting .NewMockBulk ()
121+ pp , err := NewParsedPolicy (context .TODO (), bulker , m )
122+ require .NoError (t , err )
123+
124+ // Validate that secrets where identified
125+ require .Len (t , pp .SecretKeys , 4 )
126+ require .Contains (t , pp .SecretKeys , "outputs.fs-output.ssl.key" )
127+ require .Contains (t , pp .SecretKeys , "agent.download.ssl.key" )
128+ require .Contains (t , pp .SecretKeys , "inputs.0.streams.0.auth.basic.password" )
129+ require .Contains (t , pp .SecretKeys , "inputs.0.streams.1.auth.basic.password" )
130+ }
0 commit comments