@@ -36,6 +36,7 @@ cscli hubtest create my-scenario-test --parsers crowdsecurity/nginx --scenarios
3636 RunE : func (_ * cobra.Command , args []string ) error {
3737 testName := args [0 ]
3838 testPath := filepath .Join (hubPtr .HubTestPath , testName )
39+
3940 if _ , err := os .Stat (testPath ); os .IsExist (err ) {
4041 return fmt .Errorf ("test '%s' already exists in '%s', exiting" , testName , testPath )
4142 }
@@ -53,8 +54,8 @@ cscli hubtest create my-scenario-test --parsers crowdsecurity/nginx --scenarios
5354 }
5455
5556 configFilePath := filepath .Join (testPath , "config.yaml" )
56-
5757 configFileData := & hubtest.HubTestItemConfig {}
58+
5859 if logType == "appsec" {
5960 // create empty nuclei template file
6061 nucleiFileName := testName + ".yaml"
@@ -69,12 +70,16 @@ cscli hubtest create my-scenario-test --parsers crowdsecurity/nginx --scenarios
6970 if ntpl == nil {
7071 return errors .New ("unable to parse nuclei template" )
7172 }
73+
7274 if err := ntpl .ExecuteTemplate (nucleiFile , "nuclei" , struct { TestName string }{TestName : testName }); err != nil {
7375 return fmt .Errorf ("executing nuclei template %s: %w" , nucleiFile .Name (), err )
7476 }
77+
7578 nucleiFile .Close ()
79+
7680 configFileData .AppsecRules = []string {"./appsec-rules/<author>/your_rule_here.yaml" }
7781 configFileData .NucleiTemplate = nucleiFileName
82+
7883 fmt .Fprintln (os .Stdout )
7984 fmt .Fprintf (os .Stdout , " Test name : %s\n " , testName )
8085 fmt .Fprintf (os .Stdout , " Test path : %s\n " , testPath )
@@ -84,25 +89,32 @@ cscli hubtest create my-scenario-test --parsers crowdsecurity/nginx --scenarios
8489 // create empty log file
8590 logFileName := testName + ".log"
8691 logFilePath := filepath .Join (testPath , logFileName )
92+
8793 logFile , err := os .Create (logFilePath )
8894 if err != nil {
8995 return err
9096 }
97+
9198 logFile .Close ()
9299
93100 // create empty parser assertion file
94101 parserAssertFilePath := filepath .Join (testPath , hubtest .ParserAssertFileName )
102+
95103 parserAssertFile , err := os .Create (parserAssertFilePath )
96104 if err != nil {
97105 return err
98106 }
107+
99108 parserAssertFile .Close ()
109+
100110 // create empty scenario assertion file
101111 scenarioAssertFilePath := filepath .Join (testPath , hubtest .ScenarioAssertFileName )
112+
102113 scenarioAssertFile , err := os .Create (scenarioAssertFilePath )
103114 if err != nil {
104115 return err
105116 }
117+
106118 scenarioAssertFile .Close ()
107119
108120 parsers = append (parsers , "crowdsecurity/syslog-logs" )
@@ -115,13 +127,15 @@ cscli hubtest create my-scenario-test --parsers crowdsecurity/nginx --scenarios
115127 if len (postoverflows ) == 0 {
116128 postoverflows = append (postoverflows , "" )
117129 }
130+
118131 configFileData .Parsers = parsers
119132 configFileData .Scenarios = scenarios
120133 configFileData .PostOverflows = postoverflows
121134 configFileData .LogFile = logFileName
122135 configFileData .LogType = logType
123136 configFileData .IgnoreParsers = ignoreParsers
124137 configFileData .Labels = labels
138+
125139 fmt .Fprintln (os .Stdout )
126140 fmt .Fprintf (os .Stdout , " Test name : %s\n " , testName )
127141 fmt .Fprintf (os .Stdout , " Test path : %s\n " , testPath )
@@ -135,14 +149,17 @@ cscli hubtest create my-scenario-test --parsers crowdsecurity/nginx --scenarios
135149 if err != nil {
136150 return fmt .Errorf ("open: %w" , err )
137151 }
152+
138153 data , err := yaml .Marshal (configFileData )
139154 if err != nil {
140155 return fmt .Errorf ("serialize: %w" , err )
141156 }
157+
142158 _ , err = fd .Write (data )
143159 if err != nil {
144160 return fmt .Errorf ("write: %w" , err )
145161 }
162+
146163 if err := fd .Close (); err != nil {
147164 return fmt .Errorf ("close: %w" , err )
148165 }
0 commit comments