Skip to content

Commit 58cf073

Browse files
authored
Separate manual tests and remove unused settings from E2E (#874)
* Separate manual tests and remove unused settings from E2E * Remove non sn/i test case * Remove unused test * Improve ADO logs * Skip some tests on ADO
1 parent c096335 commit 58cf073

File tree

6 files changed

+261
-107
lines changed

6 files changed

+261
-107
lines changed

.github/workflows/python-package.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@ jobs:
1717
# Fake a TRAVIS env so that the pre-existing test cases would behave like before
1818
TRAVIS: true
1919
LAB_APP_CLIENT_ID: ${{ secrets.LAB_APP_CLIENT_ID }}
20-
LAB_APP_CLIENT_SECRET: ${{ secrets.LAB_APP_CLIENT_SECRET }}
2120
LAB_APP_CLIENT_CERT_BASE64: ${{ secrets.LAB_APP_CLIENT_CERT_BASE64 }}
2221
LAB_APP_CLIENT_CERT_PFX_PATH: lab_cert.pfx
23-
LAB_OBO_CLIENT_SECRET: ${{ secrets.LAB_OBO_CLIENT_SECRET }}
24-
LAB_OBO_CONFIDENTIAL_CLIENT_ID: ${{ secrets.LAB_OBO_CONFIDENTIAL_CLIENT_ID }}
25-
LAB_OBO_PUBLIC_CLIENT_ID: ${{ secrets.LAB_OBO_PUBLIC_CLIENT_ID }}
2622

2723
# Derived from https://docs.github.com/en/actions/guides/building-and-testing-python#starting-with-the-python-workflow-template
2824
runs-on: ubuntu-22.04

azure-pipelines.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,23 @@ steps:
3737

3838
- script: |
3939
pip install pytest pytest-azurepipelines
40-
pytest
41-
displayName: 'pytest'
40+
mkdir -p test-results
41+
set -o pipefail
42+
pytest -vv --junitxml=test-results/junit.xml 2>&1 | tee test-results/pytest.log
43+
displayName: 'pytest (verbose + junit + log)'
44+
45+
- task: PublishTestResults@2
46+
displayName: 'Publish test results'
47+
condition: succeededOrFailed()
48+
inputs:
49+
testResultsFormat: 'JUnit'
50+
testResultsFiles: 'test-results/junit.xml'
51+
failTaskOnFailedTests: true
52+
testRunTitle: 'Python $(python.version) pytest'
53+
54+
- task: PublishPipelineArtifact@1
55+
displayName: 'Publish pytest log artifact'
56+
condition: succeededOrFailed()
57+
inputs:
58+
targetPath: 'test-results'
59+
artifact: 'pytest-logs-$(python.version)'

tests/README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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`.

tests/lab_config.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
2222
Environment Variables:
2323
LAB_APP_CLIENT_ID: Client ID for Key Vault authentication (required)
24-
LAB_APP_CLIENT_CERT_PFX_PATH: Path to .pfx certificate file (preferred)
25-
LAB_APP_CLIENT_SECRET: Client secret (alternative to certificate)
24+
LAB_APP_CLIENT_CERT_PFX_PATH: Path to .pfx certificate file (required)
2625
"""
2726

2827
import json
@@ -31,7 +30,7 @@
3130
from dataclasses import dataclass
3231
from typing import Dict, Optional
3332

34-
from azure.identity import CertificateCredential, ClientSecretCredential
33+
from azure.identity import CertificateCredential
3534
from azure.keyvault.secrets import SecretClient
3635

3736
logger = logging.getLogger(__name__)
@@ -169,9 +168,8 @@ def _get_credential():
169168
"""
170169
Create an Azure credential for Key Vault access.
171170
172-
Reads authentication details from environment variables. Prefers
173-
certificate-based authentication if LAB_APP_CLIENT_CERT_PFX_PATH is set,
174-
otherwise falls back to client secret.
171+
Reads authentication details from environment variables and uses
172+
certificate-based authentication via LAB_APP_CLIENT_CERT_PFX_PATH.
175173
176174
Returns:
177175
A credential object suitable for Azure SDK clients.
@@ -180,7 +178,6 @@ def _get_credential():
180178
EnvironmentError: If required environment variables are not set.
181179
"""
182180
client_id = os.getenv("LAB_APP_CLIENT_ID")
183-
client_secret = os.getenv("LAB_APP_CLIENT_SECRET")
184181
cert_path = os.getenv("LAB_APP_CLIENT_CERT_PFX_PATH")
185182
tenant_id = "72f988bf-86f1-41af-91ab-2d7cd011db47" # Microsoft tenant
186183

@@ -196,16 +193,9 @@ def _get_credential():
196193
certificate_path=cert_path,
197194
send_certificate_chain=True,
198195
)
199-
elif client_secret:
200-
logger.debug("Using client secret credential for Key Vault access")
201-
return ClientSecretCredential(
202-
tenant_id=tenant_id,
203-
client_id=client_id,
204-
client_secret=client_secret,
205-
)
206196
else:
207197
raise EnvironmentError(
208-
"Either LAB_APP_CLIENT_SECRET or LAB_APP_CLIENT_CERT_PFX_PATH is required")
198+
"LAB_APP_CLIENT_CERT_PFX_PATH is required")
209199

210200

211201
def _get_msid_lab_client() -> SecretClient:

0 commit comments

Comments
 (0)