Skip to content
Open
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
4 changes: 4 additions & 0 deletions sdk/identity/azure-identity/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

### Breaking Changes

> These changes do not impact the API of stable versions such as 1.25.1.
> Only code written against beta version 1.26.0b1 is affected.
- Renamed `use_token_proxy` keyword argument to `enable_azure_proxy` in `WorkloadIdentityCredential` to better reflect its purpose. ([#44147](https://github.com/Azure/azure-sdk-for-python/pull/44147))

### Bugs Fixed

### Other Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def __init__(

self._token_file_path = token_file_path

if kwargs.pop("use_token_proxy", False) and not within_credential_chain.get():
if kwargs.pop("enable_azure_proxy", False) and not within_credential_chain.get():
token_proxy_endpoint = os.environ.get(EnvironmentVariables.AZURE_KUBERNETES_TOKEN_PROXY)
sni = os.environ.get(EnvironmentVariables.AZURE_KUBERNETES_SNI_NAME)
ca_file = os.environ.get(EnvironmentVariables.AZURE_KUBERNETES_CA_FILE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(

self._token_file_path = token_file_path

if kwargs.pop("use_token_proxy", False) and not within_credential_chain.get():
if kwargs.pop("enable_azure_proxy", False) and not within_credential_chain.get():
token_proxy_endpoint = os.environ.get(EnvironmentVariables.AZURE_KUBERNETES_TOKEN_PROXY)
sni = os.environ.get(EnvironmentVariables.AZURE_KUBERNETES_SNI_NAME)
ca_file = os.environ.get(EnvironmentVariables.AZURE_KUBERNETES_CA_FILE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ def send(request, **kwargs):


class TestWorkloadIdentityCredentialTokenProxy:
"""Test cases for WorkloadIdentityCredential with use_token_proxy=True."""
"""Test cases for WorkloadIdentityCredential with enable_azure_proxy=True."""

def test_use_token_proxy_creates_custom_transport(self):
"""Test that use_token_proxy=True creates a custom transport with correct parameters."""
def test_enable_azure_proxy_creates_custom_transport(self):
"""Test that enable_azure_proxy=True creates a custom transport with correct parameters."""
tenant_id = "tenant-id"
client_id = "client-id"
token_file_path = "foo-path"
Expand All @@ -91,7 +91,7 @@ def test_use_token_proxy_creates_custom_transport(self):
tenant_id=tenant_id,
client_id=client_id,
token_file_path=token_file_path,
use_token_proxy=True,
enable_azure_proxy=True,
)

mock_get_transport.assert_called_once_with(
Expand All @@ -101,8 +101,8 @@ def test_use_token_proxy_creates_custom_transport(self):
ca_data=None,
)

def test_use_token_proxy_with_ca_data(self):
"""Test use_token_proxy with CA data instead of CA file."""
def test_enable_azure_proxy_with_ca_data(self):
"""Test enable_azure_proxy with CA data instead of CA file."""
tenant_id = "tenant-id"
client_id = "client-id"
token_file_path = "foo-path"
Expand All @@ -123,7 +123,7 @@ def test_use_token_proxy_with_ca_data(self):
tenant_id=tenant_id,
client_id=client_id,
token_file_path=token_file_path,
use_token_proxy=True,
enable_azure_proxy=True,
)

mock_get_transport.assert_called_once_with(
Expand All @@ -133,8 +133,8 @@ def test_use_token_proxy_with_ca_data(self):
ca_data=ca_data,
)

def test_use_token_proxy_minimal_config(self):
"""Test use_token_proxy with minimal configuration (only proxy endpoint)."""
def test_enable_azure_proxy_minimal_config(self):
"""Test enable_azure_proxy with minimal configuration (only proxy endpoint)."""
tenant_id = "tenant-id"
client_id = "client-id"
token_file_path = "foo-path"
Expand All @@ -153,7 +153,7 @@ def test_use_token_proxy_minimal_config(self):
tenant_id=tenant_id,
client_id=client_id,
token_file_path=token_file_path,
use_token_proxy=True,
enable_azure_proxy=True,
)

mock_get_transport.assert_called_once_with(
Expand All @@ -163,8 +163,8 @@ def test_use_token_proxy_minimal_config(self):
ca_data=None,
)

def test_use_token_proxy_missing_proxy_endpoint(self):
"""Test that use_token_proxy=True without proxy endpoint uses the normal transport."""
def test_enable_azure_proxy_missing_proxy_endpoint(self):
"""Test that enable_azure_proxy=True without proxy endpoint uses the normal transport."""
tenant_id = "tenant-id"
client_id = "client-id"
token_file_path = "foo-path"
Expand All @@ -179,11 +179,11 @@ def test_use_token_proxy_missing_proxy_endpoint(self):
tenant_id=tenant_id,
client_id=client_id,
token_file_path=token_file_path,
use_token_proxy=True,
enable_azure_proxy=True,
)
mock_get_transport.assert_not_called()

def test_use_token_proxy_both_ca_file_and_data_raises_error(self):
def test_enable_azure_proxy_both_ca_file_and_data_raises_error(self):
"""Test that setting both CA file and CA data raises ValueError."""
tenant_id = "tenant-id"
client_id = "client-id"
Expand All @@ -204,11 +204,11 @@ def test_use_token_proxy_both_ca_file_and_data_raises_error(self):
tenant_id=tenant_id,
client_id=client_id,
token_file_path=token_file_path,
use_token_proxy=True,
enable_azure_proxy=True,
)

def test_use_token_proxy_missing_endpoint_with_custom_env_vars_raises_error(self):
"""Test that use_token_proxy=True without proxy endpoint but with other custom env vars raises ValueError."""
def test_enable_azure_proxy_missing_endpoint_with_custom_env_vars_raises_error(self):
"""Test that enable_azure_proxy=True without proxy endpoint but with other custom env vars raises ValueError."""
tenant_id = "tenant-id"
client_id = "client-id"
token_file_path = "foo-path"
Expand All @@ -230,7 +230,7 @@ def test_use_token_proxy_missing_endpoint_with_custom_env_vars_raises_error(self
tenant_id=tenant_id,
client_id=client_id,
token_file_path=token_file_path,
use_token_proxy=True,
enable_azure_proxy=True,
)

# Test with CA file set but no proxy endpoint
Expand All @@ -243,7 +243,7 @@ def test_use_token_proxy_missing_endpoint_with_custom_env_vars_raises_error(self
tenant_id=tenant_id,
client_id=client_id,
token_file_path=token_file_path,
use_token_proxy=True,
enable_azure_proxy=True,
)

# Test with CA data set but no proxy endpoint
Expand All @@ -256,11 +256,11 @@ def test_use_token_proxy_missing_endpoint_with_custom_env_vars_raises_error(self
tenant_id=tenant_id,
client_id=client_id,
token_file_path=token_file_path,
use_token_proxy=True,
enable_azure_proxy=True,
)

def test_use_token_proxy_false_does_not_create_transport(self):
"""Test that use_token_proxy=False (default) does not create a custom transport."""
def test_enable_azure_proxy_false_does_not_create_transport(self):
"""Test that enable_azure_proxy=False (default) does not create a custom transport."""
tenant_id = "tenant-id"
client_id = "client-id"
token_file_path = "foo-path"
Expand All @@ -270,7 +270,7 @@ def test_use_token_proxy_false_does_not_create_transport(self):
tenant_id=tenant_id,
client_id=client_id,
token_file_path=token_file_path,
use_token_proxy=False,
enable_azure_proxy=False,
)
mock_get_transport.assert_not_called()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ async def send(request, **kwargs):


class TestWorkloadIdentityCredentialTokenProxyAsync:
"""Async test cases for WorkloadIdentityCredential with use_token_proxy=True."""
"""Async test cases for WorkloadIdentityCredential with enable_azure_proxy=True."""

def test_use_token_proxy_creates_custom_aiohttp_transport(self):
"""Test that use_token_proxy=True creates a custom aiohttp transport with correct parameters."""
def test_enable_azure_proxy_creates_custom_aiohttp_transport(self):
"""Test that enable_azure_proxy=True creates a custom aiohttp transport with correct parameters."""
tenant_id = "tenant-id"
client_id = "client-id"
token_file_path = "foo-path"
Expand All @@ -96,7 +96,7 @@ def test_use_token_proxy_creates_custom_aiohttp_transport(self):
tenant_id=tenant_id,
client_id=client_id,
token_file_path=token_file_path,
use_token_proxy=True,
enable_azure_proxy=True,
)

mock_get_transport.assert_called_once_with(
Expand All @@ -106,8 +106,8 @@ def test_use_token_proxy_creates_custom_aiohttp_transport(self):
ca_data=None,
)

def test_use_token_proxy_with_ca_data(self):
"""Test use_token_proxy with CA data instead of CA file."""
def test_enable_azure_proxy_with_ca_data(self):
"""Test enable_azure_proxy with CA data instead of CA file."""
tenant_id = "tenant-id"
client_id = "client-id"
token_file_path = "foo-path"
Expand All @@ -128,7 +128,7 @@ def test_use_token_proxy_with_ca_data(self):
tenant_id=tenant_id,
client_id=client_id,
token_file_path=token_file_path,
use_token_proxy=True,
enable_azure_proxy=True,
)
mock_get_transport.assert_called_once_with(
sni=None,
Expand All @@ -137,8 +137,8 @@ def test_use_token_proxy_with_ca_data(self):
ca_data=ca_data,
)

def test_use_token_proxy_minimal_config(self):
"""Test use_token_proxy with minimal configuration (only proxy endpoint)."""
def test_enable_azure_proxy_minimal_config(self):
"""Test enable_azure_proxy with minimal configuration (only proxy endpoint)."""
tenant_id = "tenant-id"
client_id = "client-id"
token_file_path = "foo-path"
Expand All @@ -157,7 +157,7 @@ def test_use_token_proxy_minimal_config(self):
tenant_id=tenant_id,
client_id=client_id,
token_file_path=token_file_path,
use_token_proxy=True,
enable_azure_proxy=True,
)

mock_get_transport.assert_called_once_with(
Expand All @@ -167,8 +167,8 @@ def test_use_token_proxy_minimal_config(self):
ca_data=None,
)

def test_use_token_proxy_missing_proxy_endpoint(self):
"""Test that use_token_proxy=True without proxy endpoint uses the normal transport."""
def test_enable_azure_proxy_missing_proxy_endpoint(self):
"""Test that enable_azure_proxy=True without proxy endpoint uses the normal transport."""
tenant_id = "tenant-id"
client_id = "client-id"
token_file_path = "foo-path"
Expand All @@ -183,11 +183,11 @@ def test_use_token_proxy_missing_proxy_endpoint(self):
tenant_id=tenant_id,
client_id=client_id,
token_file_path=token_file_path,
use_token_proxy=True,
enable_azure_proxy=True,
)
mock_get_transport.assert_not_called()

def test_use_token_proxy_both_ca_file_and_data_raises_error(self):
def test_enable_azure_proxy_both_ca_file_and_data_raises_error(self):
"""Test that setting both CA file and CA data raises ValueError."""
tenant_id = "tenant-id"
client_id = "client-id"
Expand All @@ -208,11 +208,11 @@ def test_use_token_proxy_both_ca_file_and_data_raises_error(self):
tenant_id=tenant_id,
client_id=client_id,
token_file_path=token_file_path,
use_token_proxy=True,
enable_azure_proxy=True,
)

def test_use_token_proxy_missing_endpoint_with_custom_env_vars_raises_error(self):
"""Test that use_token_proxy=True without proxy endpoint but with other custom env vars raises ValueError."""
def test_enable_azure_proxy_missing_endpoint_with_custom_env_vars_raises_error(self):
"""Test that enable_azure_proxy=True without proxy endpoint but with other custom env vars raises ValueError."""
tenant_id = "tenant-id"
client_id = "client-id"
token_file_path = "foo-path"
Expand All @@ -234,7 +234,7 @@ def test_use_token_proxy_missing_endpoint_with_custom_env_vars_raises_error(self
tenant_id=tenant_id,
client_id=client_id,
token_file_path=token_file_path,
use_token_proxy=True,
enable_azure_proxy=True,
)

# Test with CA file set but no proxy endpoint
Expand All @@ -247,7 +247,7 @@ def test_use_token_proxy_missing_endpoint_with_custom_env_vars_raises_error(self
tenant_id=tenant_id,
client_id=client_id,
token_file_path=token_file_path,
use_token_proxy=True,
enable_azure_proxy=True,
)

# Test with CA data set but no proxy endpoint
Expand All @@ -260,12 +260,12 @@ def test_use_token_proxy_missing_endpoint_with_custom_env_vars_raises_error(self
tenant_id=tenant_id,
client_id=client_id,
token_file_path=token_file_path,
use_token_proxy=True,
enable_azure_proxy=True,
)

@pytest.mark.asyncio
@pytest.mark.parametrize("get_token_method", GET_TOKEN_METHODS)
async def test_use_token_proxy_get_token_success(self, get_token_method):
async def test_enable_azure_proxy_get_token_success(self, get_token_method):
"""Test successful token acquisition when using token proxy."""
tenant_id = "tenant-id"
client_id = "client-id"
Expand Down Expand Up @@ -294,7 +294,7 @@ async def send(request, **kwargs):
tenant_id=tenant_id,
client_id=client_id,
token_file_path=token_file_path,
use_token_proxy=True,
enable_azure_proxy=True,
)

open_mock = mock_open(read_data=assertion)
Expand All @@ -304,8 +304,8 @@ async def send(request, **kwargs):

open_mock.assert_called_once_with(token_file_path, encoding="utf-8")

def test_use_token_proxy_false_does_not_create_transport(self):
"""Test that use_token_proxy=False (default) does not create a custom transport."""
def test_enable_azure_proxy_false_does_not_create_transport(self):
"""Test that enable_azure_proxy=False (default) does not create a custom transport."""
tenant_id = "tenant-id"
client_id = "client-id"
token_file_path = "foo-path"
Expand All @@ -315,7 +315,7 @@ def test_use_token_proxy_false_does_not_create_transport(self):
tenant_id=tenant_id,
client_id=client_id,
token_file_path=token_file_path,
use_token_proxy=False,
enable_azure_proxy=False,
)
mock_get_transport.assert_not_called()

Expand Down
Loading