Repository navigation
AOT 2: Load and validate authentication configuration in Abstractions - #4860
Conversation
There was a problem hiding this comment.
🔵 Needs a closer look
Successful CI validation of the reviewed head is not yet established.
No open issues 🎉
What changed in this PR
Adds internal authentication configuration loading to Abstractions ahead of the registry migration in #4821. The driver remains unchanged.
Changes:
- Loads modern or legacy configuration and validates metadata without activating providers.
- Adds fatal-exception detection and trimming/AOT annotation polyfills.
- Adds parsing, loading, and exception tests, including signed-build access.
| File | Description |
|---|---|
| src/Microsoft.Data.SqlClient.Extensions/Abstractions/test/ExceptionHelpersTest.cs | Tests fatal-exception detection across exception trees. |
| src/Microsoft.Data.SqlClient.Extensions/Abstractions/test/AuthenticationConfigurationParsingTest.cs | Tests metadata parsing and snapshot behavior. |
| src/Microsoft.Data.SqlClient.Extensions/Abstractions/test/AuthenticationConfigurationLoadingTest.cs | Tests section selection, fallback, and failures. |
| src/Microsoft.Data.SqlClient.Extensions/Abstractions/test/Abstractions.Test.csproj | Enables test-assembly signing. |
| src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/TrimmingAttributes.cs | Supplies .NET Standard annotation polyfills. |
| src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/SqlAuthenticationConfiguration.cs | Loads and validates authentication settings. |
| src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/ExceptionHelpers.cs | Classifies nested fatal exceptions. |
| src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/Abstractions.csproj | Grants internal test access in signed builds. |
Review effort: Balanced
11839a0 to
f40e013
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4860 +/- ##
==========================================
- Coverage 67.94% 66.60% -1.35%
==========================================
Files 311 311
Lines 45399 68770 +23371
==========================================
+ Hits 30845 45802 +14957
- Misses 14554 22968 +8414
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:
|
2fa9df7 to
3d2a4ed
Compare
Add SqlAuthenticationConfiguration, which reads the modern or legacy authentication section and validates its metadata without activating initializers or providers. Add ExceptionHelpers so configuration failures are filtered without masking fatal exceptions, plus netstandard2.0 polyfills for the trimming annotations. The driver continues to use its existing configuration reader until the registry replaces it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use ConfigurationSection metadata in tests now that the handlers are sealed siblings. Compile trimming attribute polyfills for the net462 target added by #4816. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Preserve warn-and-continue behavior by default and retain strict reading and parsing behind UseStrictAuthenticationConfiguration. Introduce AuthenticationFeatureSwitches and its cache-restoring test helper with only this switch, ready for the next stacked PR to extend. Keep all new tests in Abstractions.Test, covering cached switch defaults, restoration, error policies and real configuration files. Document both modes and the deferred driver integration in #4821. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Explain that ignored authentication configuration errors can result in unexpected provider installation or settings through legacy fallback and defaults. Document that strict mode rejects reading, schema and broker-value errors instead of continuing with broken configuration. Preserve the note that driver integration is deferred to #4821. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Match main's relaxed configuration loading and parsing behavior while retaining warnings about unexpected provider configuration. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tings Return empty strings for missing or incompatible handler metadata, preserving other valid settings. Document the programming-error contract and cover release recovery. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use the reviewer's configuration-loading wording with corrected section names and exception boundaries. Cover absent, empty, and partial real configuration sections without requiring optional settings or providers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Preserve configured provider metadata when useWamBroker is omitted and compare broker overrides with default configuration settings. Rename the modern-section precedence test as requested in review. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Match the driver's SetProvider behavior and the updated review wording: providers configured in app.config cannot be replaced through SetProvider. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Assert and retain an empty provider list for missing or incompatible providers metadata without discarding valid scalar settings. Add Release regression coverage and document per-property recovery. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
TestCommon excludes the driver package's compile assets so it can compile against the implementation DLL, which also drops the transitive Abstractions compile reference. Reference Abstractions directly so SqlAuthenticationMethod resolves. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…els (#4860) - Download the Azure.Artifacts pipeline artifact into the local packages feed in Package-mode test jobs so ManualTests can restore Microsoft.Data.SqlClient.Extensions.Azure (NU1102). - Reference System.Threading.Channels directly from net462 UnitTests, since ExcludeAssets="compile" on the driver package hides its transitive compile assets (CS0234). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
priyankatiwari08
left a comment
There was a problem hiding this comment.
No new defects in the loader. One build issue remains (inline).
cheenamalhotra
left a comment
There was a problem hiding this comment.
Re-reviewed at 8429420. My earlier concerns are fixed and the loader now matches main:
- A broken app.config is traced and treated as empty.
- A wrong section handler is traced and ignored.
- An invalid
useWamBrokervalue is traced and ignored. - Schema mismatches assert and continue.
Required before approval
- Fix the perf-baseline restore (NU1605) in TestCommon.csproj. See my reply on the existing thread. It's a small change; please don't defer it.
Non-blocking
2. The Package-mode CI fixes (Azure artifact download in ci-run-tests-job.yml/ci-run-tests-stage.yml/dotnet-sqlclient-ci-core.yml, and System.Threading.Channels in UnitTests) aren't related to auth config. A separate PR is preferred. If you keep them here, list them in the PR description so they're easy to find and revert.
3. Confirm the test signing key question inline on Abstractions.csproj.
I'll approve once item 1 is in and CI is green.
priyankatiwari08
left a comment
There was a problem hiding this comment.
Looks good — no concerns.
Honor pinned driver versions in TestCommon and permanently work around the published 7.1 preview baseline's incorrect sibling dependencies. Match Abstractions test-friend conditions to the driver's signing policy. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
I added a section to the PR description explaining why the unrelated CI pipeline changes are incluced in this PR. Without them, the CI pipelines would not run, and I wouldn't have been able to validate the PR. Separating into another PR and waiting for reviews and then rebasing again would have delayed things unnecessarily. |

Description
Add authentication configuration loading and parsing to Extensions.Abstractions, so the registry introduced in #4821 can consume settings without activating initializers or providers during loading. The driver is unchanged in this PR and keeps using its existing configuration reader until #4821 replaces it.
Why?
Separating configuration reading from provider activation lets the registry apply settings in a well-defined order and keeps reflection-dependent loading isolated behind trimming annotations. Landing it separately keeps #4821 focused on registration.
How
SqlAuthenticationConfiguration, which reads the modernSqlClientAuthenticationProviderssection and consults legacySqlAuthenticationProviderswhen modern is absent or its handler is incompatible.ConfigurationErrorsExceptionand return empty settings without trying legacy after a reading failure; trace and ignore incompatible handlers; and trace and ignore invaliduseWamBrokeroverrides while retaining other valid settings.netstandard2.0andnet462. Match Abstractions.Test internal access to the driver's policy: unsigned builds grant access, signed Package builds grant keyed access, and signed Project builds omit access.Package-mode build corrections retained in this PR
These corrections address build failures inherited from main, rather than authentication configuration behavior. They are retained here to validate the PR in Package mode and are listed separately to make them easy to identify or revert:
eng/pipelines/common/templates/jobs/ci-run-tests-job.yml: download the Azure package artifact alongside the other sibling package artifacts.eng/pipelines/common/templates/stages/ci-run-tests-stage.ymlandeng/pipelines/dotnet-sqlclient-ci-core.yml: pass the Azure artifact name through to the test jobs.src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft.Data.SqlClient.UnitTests.csproj: referenceSystem.Threading.Channelsdirectly because connection-pool tests use it and the driver package does not provide it transitively.src/Microsoft.Data.SqlClient/tests/Common/Microsoft.Data.SqlClient.TestCommon.csproj: reference the current-family Abstractions package only for unpinned Package builds. For the specific7.1.0-preview1.26124.5baseline, explicitly use the published Abstractions and Logging1.0.0packages. That published SqlClient family release contains incorrect dependency declarations pointing to unpublished prerelease sibling packages. This is a permanent workaround so PerformanceTests can use that release as a baseline; TestCommon needs its own overrides because each project is restored independently.Public API and behavior
This PR adds no public API surface and does not itself change consumer-visible driver behavior. The loader is internal; it becomes active in the driver when #4821 integrates it. Configuration reading in the driver remains gated by
EnableAppConfig.ConfigurationErrorsExceptionuseWamBrokervalueConfigurationErrorsExceptionUse
SqlClientEventSourcetracing to diagnose ignored configuration or unexpected provider selection.Provider construction, bootstrap failure handling and Azure discovery are integrated separately in #4821; this PR does not validate or activate configured types during loading.
Issues
Follow-up registry integration: #4821.
Testing
Configuration tests cover real files for both handlers, absent sections, empty and partial sections, omitted and invalid broker values with retained provider entries, malformed configuration, mismatched handlers, and a declared modern section without an element. Parsing tests cover string-schema recovery in Release.
Remaining validation gaps:
Microsoft.Data.SqlClient.Extensions.Abstractions. Existing driver unit tests verify declarations namingMicrosoft.Data.SqlClientthrough the existing driver reader. The combined end-to-end scenario is added later in AOT 6: Validate authentication scenarios and publishing in both reference modes #4817 (AOT 7).Local validation for commit
31870dca93a1eea172e86f0a93c5c57cbf52903f:dotnet restore src/Microsoft.Data.SqlClient/tests/PerformanceTests/Microsoft.Data.SqlClient.PerformanceTests.csproj -p:ReferenceType=Package -p:MdsPackageVersion=7.1.0-preview1.26124.5 --verbosity minimal- passed with no warning suppression. The initial condition-only fix exposed NU1603; the final baseline overrides resolve it.dotnet test src/Microsoft.Data.SqlClient.Extensions/Abstractions/test/Abstractions.Test.csproj --framework net10.0 --configuration Release --no-restore --verbosity minimal- passed: 100 tests, none skipped.dotnet build src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/Abstractions.csproj --framework net462 --configuration Release --no-restore --verbosity minimal- passed with zero warnings and errors.dotnet build src/Microsoft.Data.SqlClient/tests/Common/Microsoft.Data.SqlClient.TestCommon.csproj --framework net10.0 --configuration Release -p:ReferenceType=Project --verbosity minimal- passed with zero warnings and errors.dotnet build src/Microsoft.Data.SqlClient/tests/Common/Microsoft.Data.SqlClient.TestCommon.csproj --framework net10.0 --configuration Release -p:ReferenceType=Package --verbosity minimal- restore passed, compilation failed because the local cached8.0.0-preview1-devdriver package contains net8.0/net9.0 DLLs but no required net10.0 DLL. The shared cache was not overwritten.git diff --check- passed before committing.The following CI runs were queued for commit
31870dca93a1eea172e86f0a93c5c57cbf52903f. Checkboxes remain unchecked pending successful completion.Pipeline runs: