|
| 1 | +# Local test setup |
| 2 | + |
| 3 | +This document explains how to set up a local development environment to run tests in this repo, including E2E tests. |
| 4 | + |
| 5 | +## 1) Prerequisites |
| 6 | + |
| 7 | +- Windows, macOS, or Linux |
| 8 | +- Python 3.9+ |
| 9 | +- Access to the MSAL lab secrets (Key Vault) for E2E tests |
| 10 | +- A registered lab app credential: i.e. certificate `.pfx` file path |
| 11 | + |
| 12 | +## 2) Create and activate a virtual environment |
| 13 | + |
| 14 | +From repo root: |
| 15 | + |
| 16 | +```powershell |
| 17 | +python -m venv .venv |
| 18 | +.\.venv\Scripts\Activate.ps1 |
| 19 | +python -m pip install --upgrade pip |
| 20 | +python -m pip install -r requirements.txt |
| 21 | +``` |
| 22 | + |
| 23 | +## 3) Configure environment variables |
| 24 | + |
| 25 | +Create a local `.env` file in repo root (same folder as `setup.py`): |
| 26 | + |
| 27 | +```dotenv |
| 28 | +LAB_APP_CLIENT_ID=<your-lab-app-client-id> |
| 29 | +LAB_APP_CLIENT_CERT_PFX_PATH=C:/path/to/your/cert.pfx |
| 30 | +
|
| 31 | +``` |
| 32 | + |
| 33 | +Notes: |
| 34 | +- `tests/test_e2e.py` loads `.env` automatically when `python-dotenv` is installed. |
| 35 | +- For certificate auth, `LAB_APP_CLIENT_CERT_PFX_PATH` should be an absolute path. |
| 36 | + |
| 37 | +## 4) Run unit/integration tests |
| 38 | + |
| 39 | +Run all non-E2E tests quickly: |
| 40 | + |
| 41 | +```powershell |
| 42 | +python -m pytest -q tests -k "not e2e" |
| 43 | +``` |
| 44 | + |
| 45 | +Run full E2E unattended suite: |
| 46 | + |
| 47 | +```powershell |
| 48 | +python -m pytest -q tests/test_e2e.py |
| 49 | +``` |
| 50 | + |
| 51 | +## 5) Manual-intervention E2E tests |
| 52 | + |
| 53 | +Manual tests (interactive browser/device-flow/POP manual scenarios) are separated into: |
| 54 | + |
| 55 | +- `tests/test_e2e_manual.py` |
| 56 | + |
| 57 | +By default they are skipped. To enable: |
| 58 | + |
| 59 | +```powershell |
| 60 | +$env:RUN_MANUAL_E2E = "1" |
| 61 | +python -m pytest -q tests/test_e2e_manual.py |
| 62 | +``` |
| 63 | + |
| 64 | +To disable again in the current shell: |
| 65 | + |
| 66 | +```powershell |
| 67 | +Remove-Item Env:RUN_MANUAL_E2E |
| 68 | +``` |
| 69 | + |
| 70 | +## 6) Common troubleshooting |
| 71 | + |
| 72 | +### AADSTS700027 / invalid_client for certificate flow |
| 73 | + |
| 74 | +If you see errors indicating SNI/x5c is required, your app registration may only accept certificate auth with x5c chain. In this repo, that path is covered by SNI-oriented cert tests. |
| 75 | + |
| 76 | +### Key Vault access failures |
| 77 | + |
| 78 | +Verify: |
| 79 | +- `LAB_APP_CLIENT_ID` is correct |
| 80 | +- `LAB_APP_CLIENT_CERT_PFX_PATH` points to a valid `.pfx` file |
| 81 | +- Your principal has access to: |
| 82 | + - `https://msidlabs.vault.azure.net` |
| 83 | + - `https://id4skeyvault.vault.azure.net` |
| 84 | + |
| 85 | +### Interactive tests unexpectedly skipped |
| 86 | + |
| 87 | +Interactive/manual tests are intentionally gated. Set `RUN_MANUAL_E2E=1` and run `tests/test_e2e_manual.py`. |
0 commit comments