@@ -123,10 +123,10 @@ func NewTest(name string, hubTest *HubTest, dataDir string) (*HubTestItem, error
123
123
}
124
124
125
125
parserAssertFilePath := filepath .Join (testPath , ParserAssertFileName )
126
- ParserAssert := NewParserAssert (parserAssertFilePath )
126
+ parserAssert := NewParserAssert (parserAssertFilePath )
127
127
128
128
scenarioAssertFilePath := filepath .Join (testPath , ScenarioAssertFileName )
129
- ScenarioAssert := NewScenarioAssert (scenarioAssertFilePath )
129
+ scenarioAssert := NewScenarioAssert (scenarioAssertFilePath )
130
130
131
131
// force own_data_dir for backard compatibility
132
132
if name == "magento-ccs-by-as" || name == "magento-ccs-by-country" || name == "geoip-enrich" {
@@ -170,8 +170,8 @@ func NewTest(name string, hubTest *HubTest, dataDir string) (*HubTestItem, error
170
170
TemplateAcquisPath : hubTest .TemplateAcquisPath ,
171
171
TemplateAppsecProfilePath : hubTest .TemplateAppsecProfilePath ,
172
172
HubIndex : hubTest .HubIndex ,
173
- ScenarioAssert : ScenarioAssert ,
174
- ParserAssert : ParserAssert ,
173
+ ScenarioAssert : scenarioAssert ,
174
+ ParserAssert : parserAssert ,
175
175
CustomItemsLocation : []string {hubTest .HubPath , testPath },
176
176
NucleiTargetHost : hubTest .NucleiTargetHost ,
177
177
AppSecHost : hubTest .AppSecHost ,
@@ -318,7 +318,7 @@ func (t *HubTestItem) ImprovedLogDisplay(crowdsecLogFile string) error {
318
318
return nil
319
319
}
320
320
321
- func (t * HubTestItem ) RunWithNucleiTemplate () error {
321
+ func (t * HubTestItem ) RunWithNucleiTemplate (ctx context. Context ) error {
322
322
testPath := filepath .Join (t .HubTestPath , t .Name )
323
323
if _ , err := os .Stat (testPath ); os .IsNotExist (err ) {
324
324
return fmt .Errorf ("test '%s' doesn't exist in '%s', exiting" , t .Name , t .HubTestPath )
@@ -328,7 +328,7 @@ func (t *HubTestItem) RunWithNucleiTemplate() error {
328
328
329
329
// machine add
330
330
cmdArgs := []string {"-c" , t .RuntimeConfigFilePath , "machines" , "add" , "testMachine" , "--force" , "--auto" }
331
- cscliRegisterCmd := exec .Command ( t .CscliPath , cmdArgs ... )
331
+ cscliRegisterCmd := exec .CommandContext ( ctx , t .CscliPath , cmdArgs ... )
332
332
cscliRegisterCmd .Dir = testPath
333
333
cscliRegisterCmd .Env = []string {"TESTDIR=" + testPath , "DATADIR=" + t .RuntimeHubConfig .InstallDataDir , "TZ=UTC" }
334
334
@@ -342,7 +342,7 @@ func (t *HubTestItem) RunWithNucleiTemplate() error {
342
342
343
343
// hardcode bouncer key
344
344
cmdArgs = []string {"-c" , t .RuntimeConfigFilePath , "bouncers" , "add" , "appsectests" , "-k" , TestBouncerApiKey }
345
- cscliBouncerCmd := exec .Command ( t .CscliPath , cmdArgs ... )
345
+ cscliBouncerCmd := exec .CommandContext ( ctx , t .CscliPath , cmdArgs ... )
346
346
cscliBouncerCmd .Dir = testPath
347
347
cscliBouncerCmd .Env = []string {"TESTDIR=" + testPath , "DATADIR=" + t .RuntimeHubConfig .InstallDataDir , "TZ=UTC" }
348
348
@@ -356,7 +356,7 @@ func (t *HubTestItem) RunWithNucleiTemplate() error {
356
356
357
357
// start crowdsec service
358
358
cmdArgs = []string {"-c" , t .RuntimeConfigFilePath }
359
- crowdsecDaemon := exec .Command ( t .CrowdSecPath , cmdArgs ... )
359
+ crowdsecDaemon := exec .CommandContext ( ctx , t .CrowdSecPath , cmdArgs ... )
360
360
crowdsecDaemon .Dir = testPath
361
361
crowdsecDaemon .Env = []string {"TESTDIR=" + testPath , "DATADIR=" + t .RuntimeHubConfig .InstallDataDir , "TZ=UTC" }
362
362
@@ -400,7 +400,7 @@ func (t *HubTestItem) RunWithNucleiTemplate() error {
400
400
// the value in config is relative
401
401
nucleiTemplate := filepath .Join (t .Path , t .Config .NucleiTemplate )
402
402
403
- err = nucleiConfig .RunNucleiTemplate (t .Name , nucleiTemplate , t .NucleiTargetHost )
403
+ err = nucleiConfig .RunNucleiTemplate (ctx , t .Name , nucleiTemplate , t .NucleiTargetHost )
404
404
if t .Config .ExpectedNucleiFailure {
405
405
if err != nil && errors .Is (err , ErrNucleiTemplateFail ) {
406
406
log .Infof ("Appsec test %s failed as expected" , t .Name )
@@ -441,7 +441,7 @@ func createDirs(dirs []string) error {
441
441
return nil
442
442
}
443
443
444
- func (t * HubTestItem ) RunWithLogFile () error {
444
+ func (t * HubTestItem ) RunWithLogFile (ctx context. Context ) error {
445
445
testPath := filepath .Join (t .HubTestPath , t .Name )
446
446
if _ , err := os .Stat (testPath ); os .IsNotExist (err ) {
447
447
return fmt .Errorf ("test '%s' doesn't exist in '%s', exiting" , t .Name , t .HubTestPath )
@@ -461,7 +461,7 @@ func (t *HubTestItem) RunWithLogFile() error {
461
461
}
462
462
463
463
cmdArgs := []string {"-c" , t .RuntimeConfigFilePath , "machines" , "add" , "testMachine" , "--force" , "--auto" }
464
- cscliRegisterCmd := exec .Command ( t .CscliPath , cmdArgs ... )
464
+ cscliRegisterCmd := exec .CommandContext ( ctx , t .CscliPath , cmdArgs ... )
465
465
cscliRegisterCmd .Dir = testPath
466
466
cscliRegisterCmd .Env = []string {"TESTDIR=" + testPath , "DATADIR=" + t .RuntimeHubConfig .InstallDataDir , "TZ=UTC" }
467
467
@@ -482,7 +482,7 @@ func (t *HubTestItem) RunWithLogFile() error {
482
482
cmdArgs = append (cmdArgs , "-label" , arg )
483
483
}
484
484
485
- crowdsecCmd := exec .Command ( t .CrowdSecPath , cmdArgs ... )
485
+ crowdsecCmd := exec .CommandContext ( ctx , t .CrowdSecPath , cmdArgs ... )
486
486
crowdsecCmd .Dir = testPath
487
487
crowdsecCmd .Env = []string {"TESTDIR=" + testPath , "DATADIR=" + t .RuntimeHubConfig .InstallDataDir , "TZ=UTC" }
488
488
@@ -649,11 +649,11 @@ func (t *HubTestItem) Run(ctx context.Context, patternDir string) error {
649
649
}
650
650
651
651
if t .Config .LogFile != "" {
652
- return t .RunWithLogFile ()
652
+ return t .RunWithLogFile (ctx )
653
653
}
654
654
655
655
if t .Config .NucleiTemplate != "" {
656
- return t .RunWithNucleiTemplate ()
656
+ return t .RunWithNucleiTemplate (ctx )
657
657
}
658
658
659
659
return fmt .Errorf ("log file or nuclei template must be set in '%s'" , t .Name )
0 commit comments