Skip to content

Commit 83f2209

Browse files
authored
[Identity] Add integration tests (#33742)
Adds test automation for: - Azure Functions - Azure Web Apps - Azure Kuberentes Service Signed-off-by: Paul Van Eck <[email protected]>
1 parent 805f92b commit 83f2209

File tree

30 files changed

+935
-660
lines changed

30 files changed

+935
-660
lines changed

.vscode/cspell.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,13 @@
549549
"Jwcmlud"
550550
]
551551
},
552+
{
553+
"filename": "sdk/identity/test-resources*",
554+
"words": [
555+
"kubelet",
556+
"otsv"
557+
]
558+
},
552559
{
553560
"filename": "sdk/identity/azure-identity/TROUBLESHOOTING.md",
554561
"words": [

sdk/identity/azure-identity/tests/azure-functions/RunAsyncTest/__init__.py

Lines changed: 0 additions & 35 deletions
This file was deleted.

sdk/identity/azure-identity/tests/azure-functions/RunTest/__init__.py

Lines changed: 0 additions & 35 deletions
This file was deleted.

sdk/identity/azure-identity/tests/azure-functions/local.settings.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

sdk/identity/azure-identity/tests/azure-functions/readme.md

Lines changed: 0 additions & 183 deletions
This file was deleted.

sdk/identity/azure-identity/tests/azure-functions/Dockerfile renamed to sdk/identity/azure-identity/tests/integration/azure-functions/Dockerfile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@
88
# public OSS users should simply leave this argument blank or ignore its presence entirely
99
ARG REGISTRY=""
1010

11-
FROM ${REGISTRY}alpine:3.14 as repo
11+
FROM ${REGISTRY}alpine:3.19 as repo
1212
RUN apk --no-cache add git
1313
RUN git clone https://github.com/Azure/azure-sdk-for-python --single-branch --depth 1 /azure-sdk-for-python
1414

1515

16-
FROM mcr.microsoft.com/azure-functions/python:3.0
16+
FROM mcr.microsoft.com/azure-functions/python:4-python3.11
1717

1818
COPY --from=repo /azure-sdk-for-python/sdk/identity /sdk/identity
1919
COPY --from=repo /azure-sdk-for-python/sdk/core/azure-core /sdk/core/azure-core
20-
COPY --from=repo /azure-sdk-for-python/sdk/keyvault/azure-keyvault-secrets /sdk/keyvault/azure-keyvault-secrets
21-
WORKDIR /sdk/identity/azure-identity/tests/managed-identity-live
22-
RUN pip install --no-cache-dir -r ../managed-identity-live/requirements.txt azure-functions
20+
RUN pip install --no-cache-dir /sdk/identity/azure-identity /sdk/core/azure-core aiohttp azure-functions azure-storage-blob
21+
RUN pip freeze
2322

2423
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
2524
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# ------------------------------------
2+
# Copyright (c) Microsoft Corporation.
3+
# Licensed under the MIT License.
4+
# ------------------------------------
5+
import os
6+
7+
import azure.functions as func
8+
from azure.identity.aio import ManagedIdentityCredential
9+
from azure.storage.blob.aio import BlobServiceClient
10+
11+
12+
EXPECTED_VARIABLES = (
13+
"IDENTITY_USER_DEFINED_IDENTITY_CLIENT_ID",
14+
"IDENTITY_STORAGE_NAME_1",
15+
"IDENTITY_STORAGE_NAME_2",
16+
"MSI_ENDPOINT",
17+
)
18+
19+
20+
async def main(req: func.HttpRequest) -> func.HttpResponse:
21+
# capture interesting environment variables for debugging
22+
env = "\n".join(f"{var}: {os.environ.get(var)}" for var in EXPECTED_VARIABLES)
23+
24+
system_success_message = ""
25+
try:
26+
credential_system_assigned = ManagedIdentityCredential()
27+
credential_user_assigned = ManagedIdentityCredential(
28+
client_id=os.environ.get("IDENTITY_USER_DEFINED_IDENTITY_CLIENT_ID")
29+
)
30+
31+
client = BlobServiceClient(
32+
account_url=f"https://{os.environ['IDENTITY_STORAGE_NAME_1']}.blob.core.windows.net",
33+
credential=credential_system_assigned,
34+
)
35+
client2 = BlobServiceClient(
36+
account_url=f"https://{os.environ['IDENTITY_STORAGE_NAME_2']}.blob.core.windows.net",
37+
credential=credential_user_assigned,
38+
)
39+
async for container in client.list_containers():
40+
print(container["name"])
41+
42+
system_success_message = "Successfully acquired token with system-assigned ManagedIdentityCredential"
43+
async for container in client2.list_containers():
44+
print(container["name"])
45+
46+
await client.close()
47+
await client2.close()
48+
await credential_system_assigned.close()
49+
await credential_user_assigned.close()
50+
51+
return func.HttpResponse("Successfully acquired tokens with async ManagedIdentityCredential")
52+
except Exception as ex:
53+
return func.HttpResponse(f"Test Failed: {repr(ex)}\n\n{system_success_message}\n\n{env}", status_code=500)

sdk/identity/azure-identity/tests/azure-functions/RunTest/function.json renamed to sdk/identity/azure-identity/tests/integration/azure-functions/RunAsyncTest/function.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"scriptFile": "__init__.py",
33
"bindings": [
44
{
5-
"authLevel": "function",
5+
"authLevel": "anonymous",
66
"type": "httpTrigger",
77
"direction": "in",
88
"name": "req",
@@ -14,4 +14,4 @@
1414
"name": "$return"
1515
}
1616
]
17-
}
17+
}

0 commit comments

Comments
 (0)