Tests | Cleanup AAD Password auth from tests + code cleanup - #4390
Tests | Cleanup AAD Password auth from tests + code cleanup#4390cheenamalhotra wants to merge 22 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Removes the Entra ID “password auth” connection-string configuration from the test suite (and CI templates) following the pipeline change in #4288, replacing it with a single “bare” AzureSqlConnectionString that tests extend at runtime to exercise specific authentication modes.
Changes:
- Renamed
AADPasswordConnectionString→AzureSqlConnectionStringacross test config (Config.cs/config.default.jsonc), docs, and Azure DevOps pipeline templates; updated pipeline variables accordingly. - Added shared test helpers under
tests/Common/(CommonUtils,StringExtensions) to compose auth/credential keywords onto a base connection string. - Updated ManualTests + Azure extensions tests to remove
ActiveDirectoryPasswordcoverage and to use managed identity / token-based flows with the new helpers.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| TESTGUIDE.md | Updates documented test config property name/meaning for AAD/Azure SQL tests. |
| src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Microsoft.Data.SqlClient.TestUtilities.csproj | References the new shared test helper project. |
| src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.jsonc | Renames config field and clarifies Azure SQL base conn string expectation (no creds). |
| src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs | Renames the config field to AzureSqlConnectionString. |
| src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectivityTests/AADConnectionTest.cs | Removes AAD password tests and rewrites AAD scenarios to use helpers and AzureSqlConnectionString. |
| src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectionPoolTest/ConnectionPoolTest.cs | Updates pooled AAD/token tests to use AzureSqlConnectionString and async token retrieval. |
| src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/AADFedAuthTokenRefreshTest/AADFedAuthTokenRefreshTest.cs | Switches the fed-auth refresh scenario to managed identity-based auth/provider usage. |
| src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/ManagedIdentityProvider.cs | Renames the custom provider class to clarify it targets user-assigned MI. |
| src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs | Renames config fields, adds MI-based token retrieval APIs, and removes AAD password token generation. |
| src/Microsoft.Data.SqlClient/tests/Common/StringExtensions.cs | Adds fluent helpers for composing auth/credential keywords and for removing auth/credential keywords. |
| src/Microsoft.Data.SqlClient/tests/Common/CommonUtils.cs | Adds shared random/name helpers used by updated tests. |
| src/Microsoft.Data.SqlClient.Extensions/Azure/test/Config.cs | Renames the Azure test config field read from config.jsonc. |
| src/Microsoft.Data.SqlClient.Extensions/Azure/test/AADConnectionTest.cs | Updates Azure extension tests to build auth modes from the base Azure SQL conn string. |
| eng/pipelines/jobs/test-azure-package-ci-job.yml | Switches pipeline config-writing to AzureSqlConnectionString and updates secret scoping. |
| eng/pipelines/dotnet-sqlclient-ci-core.yml | Switches CI template config-writing to AzureSqlConnectionString (WestUS2/EastUS). |
| eng/pipelines/common/templates/steps/update-config-file-step.yml | Renames template parameter and output property to AzureSqlConnectionString. |
| eng/pipelines/common/templates/jobs/ci-run-tests-job.yml | Renames config pass-through property to AzureSqlConnectionString. |
| .github/instructions/testing.instructions.md | Updates the test-config docs to match the renamed Azure SQL config property. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4390 +/- ##
==========================================
- Coverage 65.32% 63.85% -1.48%
==========================================
Files 285 281 -4
Lines 43373 66638 +23265
==========================================
+ Hits 28335 42550 +14215
- Misses 15038 24088 +9050
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
benrr101
left a comment
There was a problem hiding this comment.
I think the scope of these changes are a bit too broad. Don't mind cleanup where sensible, but I'm concerned about the intentions behind the connection string changes being more sweeping than we really want right now.
… SQL The ConnectionPoolConnectionStringProvider classes now add Authentication=ActiveDirectoryDefault when running against Azure SQL, so pool tests authenticate via managed identity instead of failing with 'Login failed for user ''' after auth properties are stripped. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…oryDefault Convert ConnectionPoolTest and TransactionPoolTest to async, using DataTestUtility.GetAccessTokenAsync() to set connection.AccessToken before opening connections targeting Azure SQL. This ensures pool tests authenticate via managed identity without embedding auth in the connection string (which would conflict with tests that set AccessToken or AccessTokenCallback directly). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
857b56e to
7f62059
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 29 out of 30 changed files in this pull request and generated 4 comments.
Files not reviewed (1)
- src/Microsoft.Data.SqlClient/src/Resources/Strings.Designer.cs: Generated file
Suppressed comments (1)
src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs:850
- This setup probe checks system-assigned identity first, while
GetAccessTokenAsync()selects user-assigned identity first. If system identity works but the configured user identity does not, this returnstrue, then the test receives a null token fromGetAccessTokenAsync()and fails instead of being disabled. Probe the same token-selection path used by the tests.
public static async Task<bool> IsAccessTokenAsyncSetup() =>
!string.IsNullOrEmpty(await GetSystemIdentityAccessTokenAsync())
|| !string.IsNullOrEmpty(await GetUserIdentityAccessTokenAsync());
- Add IsUserManagedIdentitySupported condition to TestCustomProviderAuthentication and FedAuthTokenRefreshTest - Update RemoveAuthAndCredsProperties doc to list all 7 removed keys - Remove orphaned TcpConnectionString property from Azure.Test Config.cs - Update Azure.Test AADConnectionTest.cs to use Config.TCPConnectionString Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 556e4cc8-f9fd-46f1-aafa-1459e8659f99
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 29 out of 30 changed files in this pull request and generated no new comments.
Files not reviewed (1)
- src/Microsoft.Data.SqlClient/src/Resources/Strings.Designer.cs: Generated file
Suppressed comments (2)
src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs:305
- Removing authentication and credentials from the shared
TCPConnectionStringbreaks the general Azure SQL manual-test matrix, not just the AAD tests. The Azure jobs pass this value to hundreds of tests that open it directly (for example,TracingTests/EventSourceTest.cs:17-20), and those callers neither add an authentication mode nor set an access token, so a bare Azure SQL connection string cannot log in. Keep the authenticatedTCPConnectionStringfor the general suite and introduce/use a separate bare Azure SQL connection string for the AAD tests, as described by the PR.
if(IsAzureSqlConnectionString(TCPConnectionString))
{
// Remove legacy authentication/credential properties from the connection string.
// Tests should add their own auth method (e.g., AccessToken, Authentication keyword).
TCPConnectionString = TCPConnectionString.RemoveAuthAndCredsProperties();
src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs:850
- The setup probe and the token getter choose identities in opposite orders: this method can return
trueafter obtaining a system-assigned token, whileGetAccessTokenAsyncthen prefers a configured user-assigned identity and may returnnull. The conditional test consequently runs and fails even though its probe succeeded. Probe through the same getter and let that getter fall back to the system identity when user-assigned acquisition fails.
public static async Task<bool> IsAccessTokenAsyncSetup() =>
!string.IsNullOrEmpty(await GetSystemIdentityAccessTokenAsync())
|| !string.IsNullOrEmpty(await GetUserIdentityAccessTokenAsync());
Route Azure SQL manual-test connections through DataTestUtility so managed identity access tokens are applied without AAD Password authentication. Remove the unused username/password provider. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 556e4cc8-f9fd-46f1-aafa-1459e8659f99
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 75 out of 76 changed files in this pull request and generated 3 comments.
Files not reviewed (1)
- src/Microsoft.Data.SqlClient/src/Resources/Strings.Designer.cs: Generated file
Suppressed comments (2)
src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectionPoolTest/ConnectionPoolTest.cs:139
- This condition only verifies that the endpoint is Azure SQL, but the body unconditionally assigns the result of
GetAccessTokenAsync. When neither managed identity is available, that result is null and the test runs only to fail authentication. Gate this test with the same synchronous access-token availability predicate used byConnectivityTests/AADConnectionTest.cs.
src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs:305 - The Azure credential stripping is applied globally before all manual tests consume
TCPConnectionString, but the migration toCreateConnectionis incomplete. Azure-eligible tests such asBulkCopy/SqlGraphTables.cs(lines 19–30, 48–59, and 74–85) andProviderAgnostic/ReaderTest/ReaderTest.cs(lines 18–31) still open this now-bare string directly, so the Azure legs will attempt SQL authentication without credentials and fail. Convert every Azure-eligible direct connection/factory call to an access-token-aware path before stripping the shared string.
if(IsAzureSqlConnectionString(TCPConnectionString))
{
// Remove legacy authentication/credential properties from the connection string.
// Tests should add their own auth method (e.g., AccessToken, Authentication keyword).
TCPConnectionString = TCPConnectionString.RemoveAuthAndCredsProperties();
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 556e4cc8-f9fd-46f1-aafa-1459e8659f99
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 75 out of 76 changed files in this pull request and generated 1 comment.
Files not reviewed (1)
- src/Microsoft.Data.SqlClient/src/Resources/Strings.Designer.cs: Generated file
Suppressed comments (2)
src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectionPoolTest/ConnectionPoolTest.cs:27
- This unconditionally removes the configured authentication from the pool-test connection string. Local configurations commonly use
Integrated Security=true(includingconfig.default.jsonc:4), so these tests then open an unauthenticated connection becauseOpenWithAccessTokenAsynconly supplies credentials for Azure SQL. Preserve the original authentication for non-Azure targets and strip it only when an Azure access token will be assigned.
src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectionPoolTest/ConnectionPoolTest.cs:58 - This second class-data provider has the same local-test regression: stripping
Integrated Security/SQL credentials leaves no authentication because access tokens are added only for Azure SQL. Keep the configured credentials for non-Azure connection strings.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 556e4cc8-f9fd-46f1-aafa-1459e8659f99
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 75 out of 76 changed files in this pull request and generated 1 comment.
Files not reviewed (1)
- src/Microsoft.Data.SqlClient/src/Resources/Strings.Designer.cs: Generated file
Suppressed comments (1)
src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectionPoolTest/ConnectionPoolTest.cs:58
- This second provider has the same non-Azure regression: removing all auth fields leaves local SQL-auth and integrated-auth configurations unable to connect, because access tokens are added only for Azure. Keep the original configured string outside the Azure path.
| return string.Empty; | ||
| } | ||
|
|
||
| return new SqlConnectionStringBuilder(DataTestUtility.TCPConnectionString.RemoveAuthAndCredsProperties()) |
Removes live AAD Password authentication from test pipelines and uses managed-identity access tokens for Azure SQL tests.
Changes
AZURE_SQL_CONN_STRING_WestUS2andAZURE_SQL_CONN_STRING_EastUS.DataTestUtility; connection-string-only paths use a test Managed Identity provider backed by the same API.AccessTokenand callback tests remove inherited authentication first.CI migration
Supply bare Azure SQL connection strings through
AZURE_SQL_CONN_STRING_WestUS2andAZURE_SQL_CONN_STRING_EastUS, without authentication, user, or password fields. LegacyAAD_PASSWORD_CONN_STR*andAZURE_DB_*_CONN_STRING*variables are no longer consumed by these test legs.Validation