@@ -11,6 +11,7 @@ import (
1111	"golang.stackrox.io/kube-linter/pkg/templates" 
1212	"golang.stackrox.io/kube-linter/pkg/templates/envvarvaluefrom/internal/params" 
1313	coreV1 "k8s.io/api/core/v1" 
14+ 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 
1415)
1516
1617const  (
@@ -266,3 +267,78 @@ func (s *EnVarValueFromTestSuite) TestDeploymentWithNoOptionalConfigMap() {
266267		},
267268	})
268269}
270+ 
271+ func  (s  * EnVarValueFromTestSuite ) TestExtractRegexListInvalidPattern () {
272+ 	p  :=  params.Params {IgnoredSecrets : []string {"[invalid(" }} // Invalid regex 
273+ 	_ , err  :=  extractRegexList (p .IgnoredSecrets )
274+ 	s .Error (err )
275+ 	s .Contains (err .Error (), "invalid regex [invalid(" )
276+ }
277+ 
278+ func  (s  * EnVarValueFromTestSuite ) TestExtractRegexListEmpty () {
279+ 	regexList , err  :=  extractRegexList ([]string {})
280+ 	s .NoError (err )
281+ 	s .Empty (regexList )
282+ }
283+ 
284+ func  (s  * EnVarValueFromTestSuite ) TestUnknownKeyInSecret () {
285+ 	s .ctx .AddMockDeployment (s .T (), targetDeploymentName )
286+ 	secret  :=  & coreV1.Secret {
287+ 		ObjectMeta : metav1.ObjectMeta {Name : "test-secret" },
288+ 		Data :       map [string ][]byte {"key" : []byte ("value" )},
289+ 	}
290+ 	s .ctx .AddObject ("test-secret" , secret ) // Fixed: Use object name as key, not s.T() 
291+ 	s .addContainerWithEnvFromSecret (envReference {
292+ 		Name : "my-secret" ,
293+ 		Kind : "secret" ,
294+ 		Source : sourceReference {
295+ 			Name :     "test-secret" ,
296+ 			Key :      "unknown-key" ,
297+ 			Optional : pointers .Bool (false ),
298+ 		},
299+ 	})
300+ 	s .Validate (s .ctx , []templates.TestCase {
301+ 		{
302+ 			Param : params.Params {},
303+ 			Diagnostics : map [string ][]diagnostic.Diagnostic {
304+ 				targetDeploymentName : {{
305+ 					Message : "The container \" container\"  is referring to an unknown key \" unknown-key\"  in secret \" test-secret\" " ,
306+ 				}},
307+ 			},
308+ 			ExpectInstantiationError : false ,
309+ 		},
310+ 	})
311+ }
312+ 
313+ func  (s  * EnVarValueFromTestSuite ) TestIgnoredSecretWithRegex () {
314+ 	s .ctx .AddMockDeployment (s .T (), targetDeploymentName )
315+ 	secret  :=  & coreV1.Secret {
316+ 		ObjectMeta : metav1.ObjectMeta {Name : "ignored-secret" },
317+ 		Data :       map [string ][]byte {"key" : []byte ("value" )},
318+ 	}
319+ 	s .ctx .AddObject ("ignored-secret" , secret ) // Fixed: Use object name as key, not s.T() 
320+ 	s .addContainerWithEnvFromSecret (envReference {
321+ 		Name : "my-secret" ,
322+ 		Kind : "secret" ,
323+ 		Source : sourceReference {
324+ 			Name :     "ignored-secret" ,
325+ 			Key :      "key" ,
326+ 			Optional : pointers .Bool (false ),
327+ 		},
328+ 	})
329+ 	s .Validate (s .ctx , []templates.TestCase {
330+ 		{
331+ 			Param : params.Params {IgnoredSecrets : []string {"^ignored-secret$" }},
332+ 			Diagnostics : map [string ][]diagnostic.Diagnostic {
333+ 				targetDeploymentName : {},
334+ 			},
335+ 			ExpectInstantiationError : false ,
336+ 		},
337+ 	})
338+ }
339+ 
340+ func  (s  * EnVarValueFromTestSuite ) TestKeysEmptyMap () {
341+ 	emptyMap  :=  map [string ]string {}
342+ 	keys  :=  Keys (emptyMap )
343+ 	s .Empty (keys )
344+ }
0 commit comments