|
| 1 | +# Runs end-to-end scenario tests using pyrit_scan CLI |
| 2 | + |
| 3 | +trigger: none # Disable automatic CI triggers |
| 4 | + |
| 5 | +schedules: |
| 6 | +- cron: "0 7 * * *" # 7 AM UTC = 11 PM PST (UTC-8) / Midnight PDT (UTC-7) |
| 7 | + displayName: Nightly E2E Tests at 11 PM PST |
| 8 | + branches: |
| 9 | + include: |
| 10 | + - main |
| 11 | + always: true # Run even if there are no code changes |
| 12 | + |
| 13 | +jobs: |
| 14 | +- job: EndToEndTests |
| 15 | + displayName: "Run end-to-end scenario tests" |
| 16 | + timeoutInMinutes: 360 # Allows the job to run up to 6 hours |
| 17 | + pool: |
| 18 | + vmImage: ubuntu-latest |
| 19 | + steps: |
| 20 | + - checkout: self |
| 21 | + fetchDepth: 1 |
| 22 | + - task: UsePythonVersion@0 |
| 23 | + inputs: |
| 24 | + versionSpec: '3.12' |
| 25 | + addToPath: true |
| 26 | + - task: AzureKeyVault@2 |
| 27 | + displayName: Azure Key Vault - retrieve .env file secret |
| 28 | + inputs: |
| 29 | + azureSubscription: 'integration-test-service-connection' |
| 30 | + KeyVaultName: 'pyrit-environment' |
| 31 | + SecretsFilter: 'env-global' |
| 32 | + RunAsPreJob: false |
| 33 | + - bash: | |
| 34 | + python -c " |
| 35 | + import os; |
| 36 | + secret = os.environ.get('PYRIT_TEST_SECRET'); |
| 37 | + if not secret: |
| 38 | + raise ValueError('PYRIT_TEST_SECRET is not set'); |
| 39 | + with open('.env', 'w') as file: |
| 40 | + file.write(secret)" |
| 41 | + env: |
| 42 | + PYRIT_TEST_SECRET: $(env-global) |
| 43 | + name: create_env_file |
| 44 | + - bash: | |
| 45 | + cp build_scripts/env_local_integration_test .env.local |
| 46 | + displayName: "Create .env.local from example" |
| 47 | + - bash: pip install --upgrade setuptools pip packaging |
| 48 | + name: upgrade_pip_and_setuptools_before_installing_PyRIT |
| 49 | + - bash: sudo apt-get install python3-tk |
| 50 | + name: install_tkinter |
| 51 | + - bash: | |
| 52 | + set -e |
| 53 | + # Detect Ubuntu version |
| 54 | + UBUNTU_VERSION=$(grep VERSION_ID /etc/os-release | cut -d '"' -f 2) |
| 55 | + SUPPORTED_VERSIONS="18.04 20.04 22.04 24.04 24.10" |
| 56 | +
|
| 57 | + if ! [[ "$SUPPORTED_VERSIONS" == *"$UBUNTU_VERSION"* ]]; then |
| 58 | + echo "Ubuntu $UBUNTU_VERSION is not currently supported." |
| 59 | + exit 1 |
| 60 | + fi |
| 61 | +
|
| 62 | + # Download the package to configure the Microsoft repo |
| 63 | + curl -sSL -O https://packages.microsoft.com/config/ubuntu/$(grep VERSION_ID /etc/os-release | cut -d '"' -f 2)/packages-microsoft-prod.deb |
| 64 | + # Install the package |
| 65 | + sudo dpkg -i packages-microsoft-prod.deb |
| 66 | + # Delete the file |
| 67 | + rm packages-microsoft-prod.deb |
| 68 | +
|
| 69 | + # Install the driver |
| 70 | + sudo apt-get update |
| 71 | + sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18 |
| 72 | +
|
| 73 | + echo "Microsoft ODBC Driver 18 installed successfully." |
| 74 | + displayName: 'Install ODBC Driver 18 for SQL Server' |
| 75 | + - bash: pip install .[dev,all] -v --no-cache-dir |
| 76 | + name: install_PyRIT |
| 77 | + - bash: df -all -h |
| 78 | + name: disk_space_check |
| 79 | +# This step ensures that end-to-end tests are run outside of the PyRIT repository to test that .env files are accessed correctly. |
| 80 | + - bash: | |
| 81 | + PyRIT_DIR=$(pwd) |
| 82 | + NEW_DIR="e2e_test_directory" |
| 83 | + cd .. |
| 84 | + mkdir -p $NEW_DIR/tests |
| 85 | + cp $PyRIT_DIR/.env $NEW_DIR |
| 86 | + cp $PyRIT_DIR/.env.local $NEW_DIR |
| 87 | + cp -r $PyRIT_DIR/doc $NEW_DIR |
| 88 | + cp -r $PyRIT_DIR/assets $NEW_DIR |
| 89 | + cp -r $PyRIT_DIR/tests/end_to_end $NEW_DIR/tests |
| 90 | + cd $NEW_DIR |
| 91 | + displayName: "Create and switch to E2E test directory" |
| 92 | + - task: AzureCLI@2 |
| 93 | + displayName: "Authenticate with service principal, cache access tokens, and run E2E tests" |
| 94 | + inputs: |
| 95 | + azureSubscription: 'integration-test-service-connection' |
| 96 | + scriptType: 'bash' |
| 97 | + scriptLocation: 'inlineScript' |
| 98 | + inlineScript: | |
| 99 | + # Prefetch token for Cognitive Services before ID token expires (60-90 minute validity) |
| 100 | + az account get-access-token --scope https://cognitiveservices.azure.com/.default --output none |
| 101 | + echo "Cognitive Services access token cached successfully." |
| 102 | +
|
| 103 | + # Prefetch token for Azure ML / Foundry model endpoints |
| 104 | + az account get-access-token --scope https://ml.azure.com/.default --output none |
| 105 | + echo "Azure ML/Foundry access token cached successfully." |
| 106 | +
|
| 107 | + # Prefetch token for Azure SQL Database |
| 108 | + az account get-access-token --scope https://database.windows.net/.default --output none |
| 109 | + echo "Azure SQL Database access token cached successfully." |
| 110 | +
|
| 111 | + # Run end-to-end tests |
| 112 | + make end-to-end-test |
| 113 | + - bash: | |
| 114 | + rm -f .env |
| 115 | + name: clean_up_env_files |
| 116 | + condition: always() |
| 117 | + - task: PublishTestResults@2 |
| 118 | + condition: always() |
| 119 | + inputs: |
| 120 | + testResultsFormat: 'JUnit' |
| 121 | + testResultsFiles: 'junit/test-results.xml' |
0 commit comments