Skip to content

Conversation

cheenamalhotra
Copy link
Member

Fixes #3618

The issue is reproducible when config file is configured with a custom authentication provider.
Using SetProvider (as in tests) to override default providers does not reproduce issue, hence missed.

The fix will be back-ported to other affected branches (release/6.0 and 6.1).

@cheenamalhotra cheenamalhotra requested a review from a team as a code owner September 18, 2025 17:52
@Copilot Copilot AI review requested due to automatic review settings September 18, 2025 17:52
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue where SetProvider method would continue execution after finding a user-defined provider instead of returning immediately, potentially allowing the replacement of existing user-defined authentication providers.

  • Replaces break statement with return false to prevent overriding user-defined providers
  • Ensures proper early exit when a user-defined provider already exists for the authentication method

@paulmedynski
Copy link
Contributor

Should we add a test that confirms the broken behaviour when using the config-file based auth provider registration? And then see it pass with your fix.

Copy link

codecov bot commented Sep 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.31%. Comparing base (1765de5) to head (a792b51).
⚠️ Report is 20 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3620      +/-   ##
==========================================
+ Coverage   69.61%   77.31%   +7.69%     
==========================================
  Files         276      273       -3     
  Lines       61714    46058   -15656     
==========================================
- Hits        42964    35611    -7353     
+ Misses      18750    10447    -8303     
Flag Coverage Δ
addons 90.82% <ø> (ø)
netcore 77.11% <0.00%> (+3.81%) ⬆️
netfx 76.44% <100.00%> (+8.19%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ErikEJ
Copy link
Contributor

ErikEJ commented Sep 18, 2025

Wonder if it would be possible to add a test to prevent regression?

@paulmedynski paulmedynski self-assigned this Sep 23, 2025
@cheenamalhotra cheenamalhotra added this to the 7.0-preview2 milestone Sep 23, 2025
paulmedynski
paulmedynski previously approved these changes Sep 24, 2025
@samsharma2700 samsharma2700 self-assigned this Sep 26, 2025
paulmedynski
paulmedynski previously approved these changes Sep 30, 2025
[InlineData(SqlAuthenticationMethod.ActiveDirectoryInteractive)]
public void DefaultAuthenticationProviders_Interactive(SqlAuthenticationMethod method)
{
Assert.IsType<DummySqlAuthenticationProvider>(SqlAuthenticationProvider.GetProvider(method));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this test add anything over the other one? It seems we could remove this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this for future reference, to capture all the expected providers wherever default providers are tested. Doesn't hurt to test more than once.

[Fact]
public async Task IsDummySqlAuthenticationProviderSetByDefault()
{
var provider = SqlAuthenticationProvider.GetProvider(SqlAuthenticationMethod.ActiveDirectoryInteractive);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to get the config injected into the SqlAuthenticationProviderManager (maybe via an internal method). I see people doing facade patterns over ConfigurationManager which lets you set config without having to modify a global app.config that is visible to all tests.

We have the same basic issue with AppContext switches. We need to move toward more dependency injection so that we can test our flags/config/switches without impacting test parallelization.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is possible, but that scenario doesn't help us with reproducing the issue. Since we are setting the default providers in constructors (which is what we want to test here), the issue is reproduced by loading custom providers via external config file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom SqlClientAuthenticationProvider being overwritten by default one
5 participants