@@ -352,6 +352,82 @@ func TestRunExitCodes(t *testing.T) {
352352 wantExitCode : exitUnencryptedValue ,
353353 wantErrSubstr : "secrets/bad.yaml" ,
354354 },
355+ {
356+ name : "multiple creation rules apply different encryption to different paths" ,
357+ setup : func (t * testing.T ) string {
358+ tempDir := t .TempDir ()
359+ // Rule 1: secrets/ files must encrypt everything
360+ // Rule 2: configs/ files only encrypt keys matching "password"
361+ sopsConfig := `creation_rules:
362+ - path_regex: "^secrets/.*\\.yaml$"
363+ encrypted_regex: ""
364+ - path_regex: "^configs/.*\\.yaml$"
365+ encrypted_regex: "^password$"
366+ `
367+ if err := os .WriteFile (filepath .Join (tempDir , ".sops.yaml" ), []byte (sopsConfig ), 0o600 ); err != nil {
368+ t .Fatalf ("write .sops.yaml: %v" , err )
369+ }
370+
371+ if err := os .MkdirAll (filepath .Join (tempDir , "secrets" ), 0o755 ); err != nil {
372+ t .Fatalf ("mkdir secrets: %v" , err )
373+ }
374+ if err := os .MkdirAll (filepath .Join (tempDir , "configs" ), 0o755 ); err != nil {
375+ t .Fatalf ("mkdir configs: %v" , err )
376+ }
377+
378+ // secrets/creds.yaml: fully encrypted — should pass
379+ if err := os .WriteFile (filepath .Join (tempDir , "secrets" , "creds.yaml" ),
380+ []byte ("token: ENC[AES256_GCM,data:abc]\n " ), 0o600 ); err != nil {
381+ t .Fatalf ("write secrets creds.yaml: %v" , err )
382+ }
383+
384+ // configs/db.yaml: host is plaintext (allowed), password is plaintext (violation)
385+ if err := os .WriteFile (filepath .Join (tempDir , "configs" , "db.yaml" ),
386+ []byte ("host: localhost\n password: plaintext\n " ), 0o600 ); err != nil {
387+ t .Fatalf ("write configs db.yaml: %v" , err )
388+ }
389+
390+ return tempDir
391+ },
392+ wantExitCode : exitUnencryptedValue ,
393+ wantErrSubstr : "configs/db.yaml" ,
394+ },
395+ {
396+ name : "multiple creation rules all passing" ,
397+ setup : func (t * testing.T ) string {
398+ tempDir := t .TempDir ()
399+ sopsConfig := `creation_rules:
400+ - path_regex: "^secrets/.*\\.yaml$"
401+ encrypted_regex: ""
402+ - path_regex: "^configs/.*\\.yaml$"
403+ encrypted_regex: "^password$"
404+ `
405+ if err := os .WriteFile (filepath .Join (tempDir , ".sops.yaml" ), []byte (sopsConfig ), 0o600 ); err != nil {
406+ t .Fatalf ("write .sops.yaml: %v" , err )
407+ }
408+
409+ if err := os .MkdirAll (filepath .Join (tempDir , "secrets" ), 0o755 ); err != nil {
410+ t .Fatalf ("mkdir secrets: %v" , err )
411+ }
412+ if err := os .MkdirAll (filepath .Join (tempDir , "configs" ), 0o755 ); err != nil {
413+ t .Fatalf ("mkdir configs: %v" , err )
414+ }
415+
416+ if err := os .WriteFile (filepath .Join (tempDir , "secrets" , "creds.yaml" ),
417+ []byte ("token: ENC[AES256_GCM,data:abc]\n " ), 0o600 ); err != nil {
418+ t .Fatalf ("write secrets creds.yaml: %v" , err )
419+ }
420+
421+ if err := os .WriteFile (filepath .Join (tempDir , "configs" , "db.yaml" ),
422+ []byte ("host: localhost\n password: ENC[AES256_GCM,data:xyz]\n " ), 0o600 ); err != nil {
423+ t .Fatalf ("write configs db.yaml: %v" , err )
424+ }
425+
426+ return tempDir
427+ },
428+ wantExitCode : exitSuccess ,
429+ wantErrSubstr : "All files compliant" ,
430+ },
355431 {
356432 name : "invalid rule when both encrypted_regex and unencrypted_regex are set" ,
357433 setup : func (t * testing.T ) string {
0 commit comments