@@ -78,6 +78,54 @@ func TestOnlyEnvConfig(t *testing.T) {
7878 os .Setenv ("DD_API_KEY" , "" )
7979}
8080
81+ func TestOnlyEnvConfigArgsScrubbingEnabled (t * testing.T ) {
82+ os .Setenv ("DD_SCRUB_ARGS" , "true" )
83+ os .Setenv ("DD_CUSTOM_SENSITIVE_WORDS" , "*password*,consul_token,*api_key" )
84+
85+ agentConfig , _ := NewAgentConfig (nil , nil )
86+ assert .Equal (t , true , agentConfig .Scrubber .Enabled )
87+
88+ cases := []struct {
89+ cmdline []string
90+ parsedCmdline []string
91+ }{
92+ {[]string {"spidly" , "--mypasswords=123,456" , "consul_token" , "1234" , "--dd_api_key=1234" },
93+ []string {"spidly" , "--mypasswords=********" , "consul_token" , "********" , "--dd_api_key=********" }},
94+ }
95+
96+ for i := range cases {
97+ cases [i ].cmdline = agentConfig .Scrubber .ScrubCmdline (cases [i ].cmdline )
98+ assert .Equal (t , cases [i ].parsedCmdline , cases [i ].cmdline )
99+ }
100+
101+ os .Setenv ("DD_SCRUB_ARGS" , "" )
102+ os .Setenv ("DD_CUSTOM_SENSITIVE_WORDS" , "" )
103+ }
104+
105+ func TestOnlyEnvConfigArgsScrubbingDisabled (t * testing.T ) {
106+ os .Setenv ("DD_SCRUB_ARGS" , "false" )
107+ os .Setenv ("DD_CUSTOM_SENSITIVE_WORDS" , "*password*,consul_token,*api_key" )
108+
109+ agentConfig , _ := NewAgentConfig (nil , nil )
110+ assert .Equal (t , false , agentConfig .Scrubber .Enabled )
111+
112+ cases := []struct {
113+ cmdline []string
114+ parsedCmdline []string
115+ }{
116+ {[]string {"spidly" , "--mypasswords=123,456" , "consul_token" , "1234" , "--dd_api_key=1234" },
117+ []string {"spidly" , "--mypasswords=123,456" , "consul_token" , "1234" , "--dd_api_key=1234" }},
118+ }
119+
120+ for i := range cases {
121+ cases [i ].cmdline = agentConfig .Scrubber .ScrubCmdline (cases [i ].cmdline )
122+ assert .Equal (t , cases [i ].parsedCmdline , cases [i ].cmdline )
123+ }
124+
125+ os .Setenv ("DD_SCRUB_ARGS" , "" )
126+ os .Setenv ("DD_CUSTOM_SENSITIVE_WORDS" , "" )
127+ }
128+
81129func TestConfigNewIfExists (t * testing.T ) {
82130 // The file does not exist: no error returned
83131 conf , err := NewIfExists ("/does-not-exist" )
0 commit comments