-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Confidential Ledger SDK update SensitiveHeaderCleanupPolicy for CCF redirection change #44915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ryazhang-microsoft
merged 10 commits into
main
from
ryazhang/update_clien_for_redirection
Jan 29, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
18f5be8
update clinet and test script
ryazhang-microsoft 5e61ec9
remove test script
ryazhang-microsoft 56cc749
add comments
ryazhang-microsoft 94877a6
add change log
ryazhang-microsoft 44d00e6
update redirection policy
ryazhang-microsoft e58ab67
Merge branch 'main' into ryazhang/update_clien_for_redirection
ryazhang-microsoft 2659ac7
Update CHANGELOG for version 2.0.0b2 release
ryazhang-microsoft 6a0543c
add unit test
ryazhang-microsoft 72ac51d
Update version to 2.0.0b2
ryazhang-microsoft 7b88872
Trigger CI rebuild
ryazhang-microsoft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
sdk/confidentialledger/azure-confidentialledger/tests/test_client_configuration.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| # ------------------------------------ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
| # ------------------------------------ | ||
| """Unit tests for ConfidentialLedgerClient configuration.""" | ||
|
|
||
| import pytest | ||
| from unittest.mock import patch, MagicMock | ||
| from azure.core.pipeline import policies | ||
|
|
||
| # Import the generated client directly to test its policy configuration | ||
| from azure.confidentialledger._client import ConfidentialLedgerClient as GeneratedClient | ||
|
|
||
|
|
||
| class TestClientConfiguration: | ||
| """Tests for client configuration settings.""" | ||
|
|
||
| def test_sensitive_header_cleanup_policy_disable_redirect_cleanup_enabled(self): | ||
| """Test that SensitiveHeaderCleanupPolicy has disable_redirect_cleanup=True. | ||
|
|
||
| This ensures that authentication and ledger-specific headers are preserved | ||
| on service-managed redirects, which is required for correct authentication | ||
| behavior within the trusted Confidential Ledger endpoint. | ||
| """ | ||
| # Mock the PipelineClient to capture the policies passed to it | ||
| with patch("azure.confidentialledger._client.PipelineClient") as mock_pipeline_client: | ||
| mock_pipeline_client.return_value = MagicMock() | ||
|
|
||
| # Create the generated client directly - this will trigger policy creation | ||
| # The generated client only requires ledger_endpoint | ||
| client = GeneratedClient( | ||
| ledger_endpoint="https://test-ledger.confidentialledger.azure.com" | ||
| ) | ||
|
|
||
| # Get the policies argument passed to PipelineClient | ||
| call_args = mock_pipeline_client.call_args | ||
| policies_arg = call_args.kwargs.get("policies") or call_args[1].get("policies") | ||
|
|
||
| # Find the SensitiveHeaderCleanupPolicy in the policies list | ||
| sensitive_header_policy = None | ||
| for policy in policies_arg: | ||
| if isinstance(policy, policies.SensitiveHeaderCleanupPolicy): | ||
| sensitive_header_policy = policy | ||
| break | ||
|
|
||
| # Assert the policy exists and has disable_redirect_cleanup=True | ||
| assert sensitive_header_policy is not None, ( | ||
| "SensitiveHeaderCleanupPolicy should be present in the client's policies" | ||
| ) | ||
| assert sensitive_header_policy._disable_redirect_cleanup is True, ( | ||
| "SensitiveHeaderCleanupPolicy should have disable_redirect_cleanup=True " | ||
| "to preserve authentication headers on Confidential Ledger redirects" | ||
| ) | ||
|
|
||
| client.close() | ||
|
|
||
| def test_sensitive_header_cleanup_policy_is_in_correct_position(self): | ||
| """Test that SensitiveHeaderCleanupPolicy is positioned after authentication_policy. | ||
|
|
||
| The policy should be placed after the authentication policy so that it can | ||
| properly handle the redirect cleanup for authentication headers. | ||
| """ | ||
| with patch("azure.confidentialledger._client.PipelineClient") as mock_pipeline_client: | ||
| mock_pipeline_client.return_value = MagicMock() | ||
|
|
||
| client = GeneratedClient( | ||
| ledger_endpoint="https://test-ledger.confidentialledger.azure.com" | ||
| ) | ||
|
|
||
| # Get the policies argument passed to PipelineClient | ||
| call_args = mock_pipeline_client.call_args | ||
| policies_arg = call_args.kwargs.get("policies") or call_args[1].get("policies") | ||
|
|
||
| # Filter out None values | ||
| non_none_policies = [p for p in policies_arg if p is not None] | ||
|
|
||
| # Find positions of key policies | ||
| sensitive_header_idx = None | ||
| distributed_tracing_idx = None | ||
|
|
||
| for idx, policy in enumerate(non_none_policies): | ||
| if isinstance(policy, policies.SensitiveHeaderCleanupPolicy): | ||
| sensitive_header_idx = idx | ||
| elif isinstance(policy, policies.DistributedTracingPolicy): | ||
| distributed_tracing_idx = idx | ||
|
|
||
| # SensitiveHeaderCleanupPolicy should come after DistributedTracingPolicy | ||
| assert sensitive_header_idx is not None, ( | ||
| "SensitiveHeaderCleanupPolicy should be present in the policies" | ||
| ) | ||
| assert distributed_tracing_idx is not None, ( | ||
| "DistributedTracingPolicy should be present in the policies" | ||
| ) | ||
| assert sensitive_header_idx > distributed_tracing_idx, ( | ||
| "SensitiveHeaderCleanupPolicy should be positioned after DistributedTracingPolicy" | ||
| ) | ||
|
|
||
| client.close() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.