Skip to content

Commit 76d1091

Browse files
chore: Add job for ESCU Tests
1 parent c2d398c commit 76d1091

File tree

1 file changed

+105
-1
lines changed

1 file changed

+105
-1
lines changed

.github/workflows/reusable-build-test-release.yml

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ jobs:
122122
runs-on: ubuntu-latest
123123
outputs:
124124
execute-knowledge-labeled: ${{ steps.configure-tests-on-labels.outputs.execute_knowledge_labeled }}
125+
execute-escu-labeled: ${{ steps.configure-tests-on-labels.outputs.execute_escu_labeled }}
125126
execute-ui-labeled: ${{ steps.configure-tests-on-labels.outputs.execute_ui_labeled }}
126127
execute-modinput-labeled: ${{ steps.configure-tests-on-labels.outputs.execute_modinput_functional_labeled }}
127128
execute-ucc-modinput-labeled: ${{ steps.configure-tests-on-labels.outputs.execute_ucc_modinput_functional_labeled }}
@@ -156,7 +157,7 @@ jobs:
156157
run: |
157158
set +e
158159
declare -A EXECUTE_LABELED
159-
TESTSET=("execute_knowledge" "execute_ui" "execute_modinput_functional" "execute_ucc_modinput_functional" "execute_scripted_inputs" "execute_requirement_test" "execute_upgrade")
160+
TESTSET=("execute_knowledge" "execute_escu" "execute_ui" "execute_modinput_functional" "execute_ucc_modinput_functional" "execute_scripted_inputs" "execute_requirement_test" "execute_upgrade")
160161
for test_type in "${TESTSET[@]}"; do
161162
EXECUTE_LABELED["$test_type"]="false"
162163
done
@@ -373,6 +374,109 @@ jobs:
373374
run: |
374375
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
375376
377+
run-escu-tests:
378+
if: ${{ !cancelled() && needs.setup-workflow.outputs.execute-escu-labeled == 'true' }}
379+
needs:
380+
- build
381+
- setup-workflow
382+
- setup
383+
384+
runs-on: ubuntu-latest
385+
strategy:
386+
fail-fast: false
387+
matrix:
388+
python-version:
389+
- "3.11"
390+
permissions:
391+
actions: read
392+
deployments: read
393+
contents: read
394+
packages: read
395+
statuses: read
396+
checks: write
397+
steps:
398+
- uses: actions/checkout@v4
399+
- uses: actions/setup-python@v5
400+
with:
401+
python-version: ${{ matrix.python-version }}
402+
403+
- name: Install Python Dependencies and ContentCTL
404+
run: |
405+
python -m pip install --upgrade pip
406+
pip install contentctl==5.0.0
407+
git clone https://github.com/splunk/security_content.git
408+
409+
410+
- name: Download TA Build Artifact
411+
uses: actions/download-artifact@v4
412+
with:
413+
name: package-splunkbase
414+
path: ta_build
415+
416+
- name: Get the build path
417+
run: |
418+
TA_BUILD=$(ls ta_build)
419+
TA_BUILD_PATH="${{ github.workspace }}/ta_build/$TA_BUILD"
420+
echo "TA_BUILD_PATH=$TA_BUILD_PATH" >> $GITHUB_ENV
421+
422+
- name: Run Python Script
423+
id: filter-detection-files
424+
shell: python
425+
run: |
426+
import yaml
427+
import os
428+
import configparser
429+
430+
# Parse props.conf and collect all the sourcetypes in a list.
431+
config = configparser.ConfigParser(strict=False)
432+
config.read("package/default/props.conf")
433+
sourcetypes = config.sections()
434+
435+
# Load the YAML content
436+
with open("security_content/contentctl.yml", "r") as file:
437+
data = yaml.safe_load(file)
438+
439+
data["apps"] = [{'uid': 1621, 'title': "Splunk Common Information Model (CIM)", 'version': "6.0.1", 'appid': "Splunk_SA_CIM", 'hardcoded_path': "https://attack-range-appbinaries.s3.us-west-2.amazonaws.com/splunk-common-information-model-cim_601.tgz"}, {'title': ${{ needs.setup.outputs.addon-name }}, 'version': "default", 'appid': ${{ needs.setup.outputs.addon-name }}, 'hardcoded_path': "${{ env.TA_BUILD_PATH }}"}]
440+
441+
# Write the modified data to the contentctl.yml file
442+
with open("security_content/contentctl.yml", "w") as file:
443+
yaml.dump(data,file,sort_keys=False)
444+
445+
# Filter out the detections based on the collected sourcetypes
446+
base_dir = "security_content/detections"
447+
detection_files = ""
448+
449+
for root, dirs, files in os.walk(base_dir):
450+
for file in files:
451+
file_path = os.path.join(root, file)
452+
453+
try:
454+
with open(file_path, "r") as file:
455+
file_content = yaml.safe_load(file)
456+
if file_content["tests"][0]["attack_data"][0]["sourcetype"] in sourcetypes or file_content["tests"][0]["attack_data"][0]["source"] in sourcetypes:
457+
detection_files += file_path.replace("security_content/", "") + " "
458+
459+
460+
except Exception as e:
461+
continue
462+
463+
# Save detection_files as an output variable
464+
with open(os.getenv('GITHUB_OUTPUT'), 'w') as output_file:
465+
output_file.write(f"DETECTION_FILES={detection_files}")
466+
467+
print(f"Filtered Detection files = {detection_files}")
468+
469+
- name: Run ESCU Tests
470+
run: |
471+
472+
cd security_content
473+
echo "Content of contentctl.yml file"
474+
cat contentctl.yml
475+
476+
echo "contentctl test --post-test-behavior never_pause --verbose --container-settings.no-leave-running mode:selected --mode.files ${{ steps.filter-detection-files.outputs.DETECTION_FILES }}"
477+
478+
contentctl test --post-test-behavior never_pause --verbose --container-settings.no-leave-running mode:selected --mode.files ${{ steps.filter-detection-files.outputs.DETECTION_FILES }}
479+
376480
run-unit-tests:
377481
name: test-unit-python3-${{ matrix.python-version }}
378482
if: ${{ needs.test-inventory.outputs.unit == 'true' }}

0 commit comments

Comments
 (0)