@@ -502,6 +502,7 @@ public void AdditionalFiles_WildcardPattern_BaseDir()
502502 [ DataTestMethod ]
503503 [ DataRow ( "sonar.docker.file.patterns" ) ]
504504 [ DataRow ( "sonar.java.jvmframeworkconfig.file.patterns" ) ]
505+ [ DataRow ( "sonar.text.inclusions" ) ]
505506 public void AdditionalFiles_WildcardPattern_RelativePattern ( string property )
506507 {
507508 var nestedFolder = new DirectoryInfo ( Path . Combine ( ProjectBaseDir . FullName , "nested" ) ) ;
@@ -626,4 +627,78 @@ public void AdditionalFiles_WildcardPatternJvmFrameworkConfig_DefaultPatterns()
626627 Path . Combine ( resources . FullName , "application.properties" ) ) ;
627628 files . Tests . Should ( ) . BeEmpty ( ) ;
628629 }
630+
631+ [ TestMethod ]
632+ public void AdditionalFiles_WildcardPatternTextInclusion_DefaultPatterns ( )
633+ {
634+ var src = new DirectoryInfo ( Path . Combine ( ProjectBaseDir . FullName , "src" ) ) ;
635+ var nested = new DirectoryInfo ( Path . Combine ( src . FullName , "nested" ) ) ;
636+ var aws = new DirectoryInfo ( Path . Combine ( ProjectBaseDir . FullName , ".aws" ) ) ;
637+ wrapper
638+ . EnumerateDirectories ( ProjectBaseDir , "*" , SearchOption . AllDirectories )
639+ . Returns ( [ src , nested , aws ] ) ;
640+ wrapper
641+ . EnumerateFiles ( ProjectBaseDir , "*" , SearchOption . TopDirectoryOnly )
642+ . Returns (
643+ [
644+ new ( Path . Combine ( ProjectBaseDir . FullName , "file.sh" ) ) ,
645+ new ( Path . Combine ( ProjectBaseDir . FullName , "file.bash" ) ) ,
646+ new ( Path . Combine ( ProjectBaseDir . FullName , "file.conf" ) ) ,
647+ new ( Path . Combine ( ProjectBaseDir . FullName , "file.cs" ) ) ,
648+ new ( Path . Combine ( ProjectBaseDir . FullName , ".env" ) ) ,
649+ ] ) ;
650+ wrapper
651+ . EnumerateFiles ( src , "*" , SearchOption . TopDirectoryOnly )
652+ . Returns (
653+ [
654+ new ( Path . Combine ( src . FullName , "file.zsh" ) ) ,
655+ new ( Path . Combine ( src . FullName , "file.ksh" ) ) ,
656+ new ( Path . Combine ( src . FullName , "file.pem" ) ) ,
657+ new ( Path . Combine ( src . FullName , "file.java" ) ) ,
658+ new ( Path . Combine ( src . FullName , ".env" ) ) ,
659+ ] ) ;
660+ wrapper
661+ . EnumerateFiles ( nested , "*" , SearchOption . TopDirectoryOnly )
662+ . Returns (
663+ [
664+ new ( Path . Combine ( nested . FullName , "file.ps1" ) ) ,
665+ new ( Path . Combine ( nested . FullName , "file.properties" ) ) ,
666+ new ( Path . Combine ( nested . FullName , "file.config" ) ) ,
667+ new ( Path . Combine ( nested . FullName , ".env" ) ) ,
668+ ] ) ;
669+ wrapper
670+ . EnumerateFiles ( aws , "*" , SearchOption . TopDirectoryOnly )
671+ . Returns (
672+ [
673+ new ( Path . Combine ( aws . FullName , "config" ) ) ,
674+ new ( Path . Combine ( aws . FullName , "workflow.yaml" ) ) ,
675+ new ( Path . Combine ( aws . FullName , ".env" ) ) ,
676+ ] ) ;
677+ var config = new AnalysisConfig
678+ {
679+ ScanAllAnalysis = true ,
680+ LocalSettings = [ ] ,
681+ ServerSettings =
682+ [
683+ // https://github.com/SonarSource/sonar-text-enterprise/blob/ab4f194bec799f6fdef294d46041be633747a822/sonar-text-plugin/src/main/java/org/sonar/plugins/common/TextAndSecretsSensor.java#L55
684+ new ( "sonar.text.inclusions" , "**/*.sh,**/*.bash,**/*.zsh,**/*.ksh,**/*.ps1,**/*.properties,**/*.conf,**/*.pem,**/*.config,.env,.aws/config" )
685+ ]
686+ } ;
687+
688+ var files = sut . AdditionalFiles ( config , ProjectBaseDir ) ;
689+
690+ files . Sources . Select ( x => x . FullName ) . Should ( ) . BeEquivalentTo (
691+ Path . Combine ( ProjectBaseDir . FullName , "file.sh" ) ,
692+ Path . Combine ( ProjectBaseDir . FullName , "file.bash" ) ,
693+ Path . Combine ( ProjectBaseDir . FullName , "file.conf" ) ,
694+ Path . Combine ( ProjectBaseDir . FullName , ".env" ) ,
695+ Path . Combine ( src . FullName , "file.zsh" ) ,
696+ Path . Combine ( src . FullName , "file.ksh" ) ,
697+ Path . Combine ( src . FullName , "file.pem" ) ,
698+ Path . Combine ( nested . FullName , "file.ps1" ) ,
699+ Path . Combine ( nested . FullName , "file.properties" ) ,
700+ Path . Combine ( nested . FullName , "file.config" ) ,
701+ Path . Combine ( aws . FullName , "config" ) ) ;
702+ files . Tests . Should ( ) . BeEmpty ( ) ;
703+ }
629704}
0 commit comments