@@ -400,6 +400,145 @@ jobs:
400400 find tests -type d -maxdepth 1 -mindepth 1 | sed 's|^tests/||g' | while read -r TESTSET; do echo "$TESTSET=true" >> "$GITHUB_OUTPUT"; echo "$TESTSET::true"; done
401401 find package/default/data -type d -name "spl2" -maxdepth 1 -mindepth 1 | sed 's|^package/default/data/||g' | while read -r TESTSET; do echo "$TESTSET=true" >> "$GITHUB_OUTPUT"; echo "$TESTSET::true"; done
402402
403+ run-escu-tests :
404+ if : ${{ !cancelled() && needs.setup-workflow.outputs.execute-escu-labeled == 'true' }}
405+ needs :
406+ - build
407+ - setup-workflow
408+ - setup
409+
410+ runs-on : ubuntu-latest
411+ strategy :
412+ fail-fast : false
413+ matrix :
414+ python-version :
415+ - " 3.11"
416+ permissions :
417+ actions : read
418+ deployments : read
419+ contents : read
420+ packages : read
421+ statuses : read
422+ checks : write
423+ steps :
424+ - uses : actions/checkout@v4
425+ - uses : actions/setup-python@v5
426+ with :
427+ python-version : ${{ matrix.python-version }}
428+
429+ - name : Install Python Dependencies and ContentCTL
430+ run : |
431+ pip install contentctl
432+ git clone https://github.com/splunk/security_content.git
433+
434+
435+ - name : Download TA Build Artifact
436+ uses : actions/download-artifact@v4
437+ with :
438+ name : package-splunkbase
439+ path : ta_build
440+
441+ - name : Get the build path
442+ run : |
443+ TA_BUILD=$(ls ta_build)
444+ TA_BUILD_PATH="${{ github.workspace }}/ta_build/$TA_BUILD"
445+ echo "TA_BUILD_PATH=$TA_BUILD_PATH" >> $GITHUB_ENV
446+
447+ - name : Run Python Script
448+ id : filter-detection-files
449+ shell : python
450+ run : |
451+ import yaml
452+ import os
453+ import configparser
454+ import re
455+
456+ GITHUB_REPOSITORY = os.environ.get("GITHUB_REPOSITORY", "")
457+
458+ # Parse app.conf get the appid of the TA.
459+ config = configparser.ConfigParser(strict=False)
460+ config.read("package/default/app.conf")
461+ APP_ID = config.get("id", "name")
462+ APP_LABEL = config.get("ui", "label")
463+
464+ # Read the file and remove trailing backslashes
465+ with open("package/default/props.conf", "r") as f:
466+ content = f.read()
467+
468+ # Remove trailing backslashes followed by a newline
469+ updated_content = re.sub(r"\\\n", "", content)
470+
471+ # Write the cleaned content to a new file
472+ with open("package/default/props.conf", "w") as f:
473+ f.write(updated_content)
474+
475+ # Parse props.conf and collect all the sourcetypes in a list.
476+ config = configparser.ConfigParser(strict=False)
477+ config.read("package/default/props.conf")
478+ sourcetypes = config.sections()
479+
480+ # Load the YAML content
481+ with open("security_content/contentctl.yml", "r") as file:
482+ data = yaml.safe_load(file)
483+
484+ found = False
485+
486+ for app in data["apps"]:
487+ if app['appid'] == APP_ID or GITHUB_REPOSITORY in app['hardcoded_path'] or app["title"] == APP_LABEL:
488+ app['hardcoded_path'] = "${{ env.TA_BUILD_PATH }}"
489+ found = True
490+ elif app['appid'] == "PALO_ALTO_NETWORKS_ADD_ON_FOR_SPLUNK" and APP_ID == "Splunk_TA_paloalto_networks":
491+ app['hardcoded_path'] = "${{ env.TA_BUILD_PATH }}"
492+ found = True
493+
494+ if not found:
495+ exit(127)
496+
497+
498+ # Write the modified data to the contentctl.yml file
499+ with open("security_content/contentctl.yml", "w") as file:
500+ yaml.dump(data,file,sort_keys=False)
501+
502+ # Filter out the detections based on the collected sourcetypes
503+ base_dir = "security_content/detections"
504+ detection_files = ""
505+
506+ for root, dirs, files in os.walk(base_dir):
507+ for file in files:
508+ file_path = os.path.join(root, file)
509+
510+ try:
511+ with open(file_path, "r") as file:
512+ file_content = yaml.safe_load(file)
513+ if "deprecated" not in file_path and (file_content["tests"][0]["attack_data"][0]["sourcetype"] in sourcetypes or file_content["tests"][0]["attack_data"][0]["source"] in sourcetypes):
514+ detection_files += file_path.replace("security_content/", "") + " "
515+
516+
517+ except Exception as e:
518+ continue
519+
520+ # Save detection_files as an output variable
521+ with open(os.getenv('GITHUB_OUTPUT'), 'w') as output_file:
522+ output_file.write(f"DETECTION_FILES={detection_files}")
523+
524+ print(f"Filtered Detection files = {detection_files}")
525+
526+ - name : Run ESCU Tests
527+ run : |
528+
529+ cd security_content
530+ echo "Content of contentctl.yml file"
531+ cat contentctl.yml
532+
533+ contentctl test --container-settings.num-containers 8 --post-test-behavior never_pause --disable-tqdm mode:selected --mode.files ${{ steps.filter-detection-files.outputs.DETECTION_FILES }}
534+
535+ - uses : actions/upload-artifact@v4
536+ if : always()
537+ with :
538+ name : escu_test_summary_results
539+ path : |
540+ security_content/test_results/summary.yml
541+
403542 run-unit-tests :
404543 name : test-unit-python3-${{ matrix.python-version }}
405544 if : ${{ needs.test-inventory.outputs.unit == 'true' }}
0 commit comments