|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +# CSPM Agentless Scout E2E Tests |
| 6 | +# Runs Scout tests with custom server configuration for Cloud Security Posture Management (CSPM) agentless integrations |
| 7 | + |
| 8 | +source .buildkite/scripts/steps/functional/common.sh |
| 9 | + |
| 10 | +CONFIG_PATH="x-pack/solutions/security/plugins/cloud_security_posture/test/scout_cspm_agentless/ui/parallel.playwright.config.ts" |
| 11 | + |
| 12 | +# Run modes for CSPM Agentless tests |
| 13 | +RUN_MODES="--stateful --serverless=security" |
| 14 | + |
| 15 | +results=() |
| 16 | +failedConfigs=() |
| 17 | + |
| 18 | +FINAL_EXIT_CODE=0 |
| 19 | + |
| 20 | +# Function to upload Scout events if available and clean up |
| 21 | +upload_events_if_available() { |
| 22 | + local mode="$1" |
| 23 | + |
| 24 | + if [[ "${SCOUT_REPORTER_ENABLED:-}" =~ ^(1|true)$ ]]; then |
| 25 | + if [ -d ".scout/reports" ] && [ "$(ls -A .scout/reports 2>/dev/null)" ]; then |
| 26 | + echo "--- Upload Scout reporter events for CSPM Agentless ($mode)" |
| 27 | + set +e |
| 28 | + node scripts/scout upload-events --dontFailOnError |
| 29 | + UPLOAD_EXIT_CODE=$? |
| 30 | + set -e |
| 31 | + |
| 32 | + if [[ $UPLOAD_EXIT_CODE -eq 0 ]]; then |
| 33 | + echo "Upload completed for CSPM Agentless ($mode)" |
| 34 | + else |
| 35 | + echo "Upload failed for CSPM Agentless ($mode) with exit code $UPLOAD_EXIT_CODE" |
| 36 | + fi |
| 37 | + |
| 38 | + # Clean up events reports to avoid double ingestion, but preserve failure reports |
| 39 | + echo "Cleaning up Scout events reports (preserving failure reports for annotations)" |
| 40 | + if [ -d ".scout/reports" ]; then |
| 41 | + for dir in .scout/reports/scout-playwright-*; do |
| 42 | + if [ -d "$dir" ] && [[ "$dir" != *"scout-playwright-test-failures-"* ]]; then |
| 43 | + rm -rf "$dir" |
| 44 | + fi |
| 45 | + done |
| 46 | + fi |
| 47 | + else |
| 48 | + echo "No Scout reports found for CSPM Agentless ($mode)" |
| 49 | + fi |
| 50 | + fi |
| 51 | +} |
| 52 | + |
| 53 | +echo "--- CSPM Agentless Scout Tests" |
| 54 | +echo "Config: $CONFIG_PATH" |
| 55 | +echo "Run modes: $RUN_MODES" |
| 56 | + |
| 57 | +for mode in $RUN_MODES; do |
| 58 | + echo "--- Running CSPM Agentless tests: $mode" |
| 59 | + |
| 60 | + start=$(date +%s) |
| 61 | + |
| 62 | + # Prevent non-zero exit code from breaking the loop |
| 63 | + set +e |
| 64 | + node scripts/scout.js run-tests "$mode" --config "$CONFIG_PATH" --kibana-install-dir "$KIBANA_BUILD_LOCATION" |
| 65 | + EXIT_CODE=$? |
| 66 | + set -e |
| 67 | + |
| 68 | + timeSec=$(($(date +%s)-start)) |
| 69 | + if [[ $timeSec -gt 60 ]]; then |
| 70 | + min=$((timeSec/60)) |
| 71 | + sec=$((timeSec-(min*60))) |
| 72 | + duration="${min}m ${sec}s" |
| 73 | + else |
| 74 | + duration="${timeSec}s" |
| 75 | + fi |
| 76 | + |
| 77 | + if [[ $EXIT_CODE -eq 2 ]]; then |
| 78 | + # No tests found |
| 79 | + echo "No tests found for CSPM Agentless ($mode)" |
| 80 | + elif [[ $EXIT_CODE -ne 0 ]]; then |
| 81 | + # Test run failed |
| 82 | + upload_events_if_available "$mode" |
| 83 | + failedConfigs+=("CSPM Agentless ($mode)") |
| 84 | + FINAL_EXIT_CODE=10 |
| 85 | + echo "Scout test exited with code $EXIT_CODE for CSPM Agentless ($mode)" |
| 86 | + echo "^^^ +++" |
| 87 | + else |
| 88 | + # Test run was successful |
| 89 | + upload_events_if_available "$mode" |
| 90 | + results+=("CSPM Agentless ($mode) (${duration})") |
| 91 | + fi |
| 92 | +done |
| 93 | + |
| 94 | +echo "--- CSPM Agentless Scout Tests: Summary" |
| 95 | +echo "Passed: ${#results[@]}" |
| 96 | +echo "Failed: ${#failedConfigs[@]}" |
| 97 | + |
| 98 | +if [[ ${#results[@]} -gt 0 ]]; then |
| 99 | + echo "Successful tests:" |
| 100 | + printf '%s\n' "${results[@]}" |
| 101 | +fi |
| 102 | + |
| 103 | +if [[ ${#failedConfigs[@]} -gt 0 ]]; then |
| 104 | + echo "Failed tests:" |
| 105 | + for config in "${failedConfigs[@]}"; do |
| 106 | + echo " $config" |
| 107 | + done |
| 108 | +fi |
| 109 | + |
| 110 | +exit $FINAL_EXIT_CODE |
| 111 | + |
0 commit comments