Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions doc/dev/tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,12 @@ Both pure ARM templates (`test-resources.json`) and BICEP files (`test-resources

User-based authentication is preferred when using test resources. To enable this:
- Use the [`-UserAuth` command flag][user_auth_flag] when running the `New-TestResources` script.
- Set the environment variable `AZURE_TEST_USE_PWSH_AUTH` to "true" to authenticate with Azure PowerShell, or
`AZURE_TEST_USE_CLI_AUTH` to "true" to authenticate with Azure CLI.
- Ensure you're logged into the tool you choose -- if
- Choose a development tool to authenticate with by setting an `AZURE_TEST_USE_*_AUTH` environment variable to "true" (tests will authenticate as the tool's logged-in user). The following tools are supported, listed in the order that authentication will be attempted in if requested:
1. Azure PowerShell: set `AZURE_TEST_USE_PWSH_AUTH`.
2. Azure CLI (`az`): set `AZURE_TEST_USE_CLI_AUTH`.
3. Visual Studio Code: set `AZURE_TEST_USE_VSCODE_AUTH`.
4. Azure Developer CLI (`azd`): set `AZURE_TEST_USE_AZD_AUTH`.
- Ensure you're logged into the tool you choose -- if
you used `New-TestResources.ps1` to deploy resources, you'll already have logged in with Azure PowerShell.

If you haven't yet set up a `test-resources` file for test resource deployment and/or want to use test resources of
Expand Down Expand Up @@ -216,13 +219,15 @@ environment variables necessary to run live tests for the service. After storing
-- formatted as `VARIABLE=value` on separate lines -- your credentials and test configuration variables will be set in
our environment when running tests.

If you used the [`-UserAuth` command flag][user_auth_flag] to deploy test resources, set either
`AZURE_TEST_USE_PWSH_AUTH` or `AZURE_TEST_USE_CLI_AUTH` to "true" to authenticate with Azure PowerShell or Azure CLI,
respectively. If both are set to true, Azure PowerShell will be used.
If you used the [`-UserAuth` command flag][user_auth_flag] to deploy test resources, choose a development tool to
authenticate with by setting an `AZURE_TEST_USE_*_AUTH` environment variable to "true". The following tools are supported, listed in the order that authentication will be attempted in if requested:
1. Azure PowerShell: set `AZURE_TEST_USE_PWSH_AUTH`.
2. Azure CLI (`az`): set `AZURE_TEST_USE_CLI_AUTH`.
3. Visual Studio Code: set `AZURE_TEST_USE_VSCODE_AUTH`.
4. Azure Developer CLI (`azd`): set `AZURE_TEST_USE_AZD_AUTH`.

If your service doesn't have a `test-resources` file for test deployment, you'll need to set environment variables
for authentication at minimum. For user-based authentication, use `AZURE_TEST_USE_PWSH_AUTH` or
`AZURE_TEST_USE_CLI_AUTH` as described above.
for authentication at minimum. For user-based authentication, use `AZURE_TEST_USE_*_AUTH` as described above.

For service principal authentication:
1. Set the `AZURE_SUBSCRIPTION_ID` variable to your organization's subscription ID. You can find it in the "Overview"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ def get_credential(self, client_class, **kwargs):

use_pwsh = os.environ.get("AZURE_TEST_USE_PWSH_AUTH", "false")
use_cli = os.environ.get("AZURE_TEST_USE_CLI_AUTH", "false")
use_vscode = os.environ.get("AZURE_TEST_USE_VSCODE_AUTH", "false")
use_azd = os.environ.get("AZURE_TEST_USE_AZD_AUTH", "false")
is_async = kwargs.pop("is_async", False)

# Return live credentials only in live mode
Expand All @@ -107,14 +109,34 @@ def get_credential(self, client_class, **kwargs):
if is_async:
from azure.identity.aio import AzurePowerShellCredential
return AzurePowerShellCredential()
# User-based authentication through Azure CLI, if requested
# User-based authentication through Azure CLI (az), if requested
if use_cli.lower() == "true":
_LOGGER.info("Environment variable AZURE_TEST_USE_CLI_AUTH set to 'true'. Using AzureCliCredential.")
from azure.identity import AzureCliCredential

if is_async:
from azure.identity.aio import AzureCliCredential
return AzureCliCredential()
# User-based authentication through Visual Studio Code, if requested
if use_vscode.lower() == "true":
_LOGGER.info(
"Environment variable AZURE_TEST_USE_VSCODE_AUTH set to 'true'. Using VisualStudioCodeCredential."
)
from azure.identity import VisualStudioCodeCredential

if is_async:
from azure.identity.aio import VisualStudioCodeCredential
return VisualStudioCodeCredential()
# User-based authentication through Azure Developer CLI (azd), if requested
if use_azd.lower() == "true":
_LOGGER.info(
"Environment variable AZURE_TEST_USE_AZD_AUTH set to 'true'. Using AzureDeveloperCliCredential."
)
from azure.identity import AzureDeveloperCliCredential

if is_async:
from azure.identity.aio import AzureDeveloperCliCredential
return AzureDeveloperCliCredential()

# Service principal authentication
if tenant_id and client_id and secret:
Expand Down