Skip to content

APIScan | Fix Builder Mistake #3357

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

Closed
wants to merge 1 commit into from
Closed

Conversation

benrr101
Copy link
Contributor

Description: Made a mistake when I wrote #3354 - forgot to store the modified builder in the builder variable.

Testing: Kinda disappointed it didn't get caught in any CI pathways. Ideally I should write up a test for this specific scenario, but I'm concerned this will be a huge undertaking versus fixing it before it gets released.

@benrr101 benrr101 added this to the 6.1-preview2 milestone May 19, 2025
@Copilot Copilot AI review requested due to automatic review settings May 19, 2025 17:08
@benrr101 benrr101 added the Regression 💥 Issues that are regressions introduced from earlier PRs. label May 19, 2025
@benrr101 benrr101 requested a review from a team as a code owner May 19, 2025 17:08
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 corrects the builder pattern in CreateClientAppInstance by ensuring the modified builder is stored back into the builder variable for the Win32 window scenario.

  • Assigns the result of WithParentActivityOrWindow back to builder
  • Prevents the lost configuration when _iWin32WindowFunc is not null
Comments suppressed due to low confidence (1)

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ActiveDirectoryAuthenticationProvider.cs:559

  • Add a unit test to verify that when _iWin32WindowFunc is provided, WithParentActivityOrWindow is actually called and the returned builder is used, ensuring this configuration isn't lost.
builder = builder.WithParentActivityOrWindow(_iWin32WindowFunc);

Copy link
Contributor

@mdaigle mdaigle left a comment

Choose a reason for hiding this comment

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

I don't think we have any test coverage of UI based app usage and it's hard to do in an automated way. But as far as I know, this is actually the only bit of code that's specific to UI based apps. What do you think about doing a manual verification?

@benrr101
Copy link
Contributor Author

@mdaigle If I had any idea how to do that ... sure

@mdaigle
Copy link
Contributor

mdaigle commented May 19, 2025

The simplest repro would be a netfx winforms app. Visual studio can create one for you from a template.
If you add some code to create a sql connection using interactive app and pass in the window handle, the interactive auth window should pop up on top of the winforms app window when run. I have some sample projects from when I was doing the MSAL s360 work that I can share with you that should work as-is for this purpose.

Copy link

codecov bot commented May 19, 2025

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 67.72%. Comparing base (6d2473d) to head (9b39d4f).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...SqlClient/ActiveDirectoryAuthenticationProvider.cs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3357      +/-   ##
==========================================
+ Coverage   65.10%   67.72%   +2.61%     
==========================================
  Files         300      294       -6     
  Lines       65376    65066     -310     
==========================================
+ Hits        42565    44065    +1500     
+ Misses      22811    21001    -1810     
Flag Coverage Δ
addons ?
netcore 72.16% <ø> (+3.83%) ⬆️
netfx 66.37% <0.00%> (+0.03%) ⬆️

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.

@@ -556,7 +556,7 @@ private IPublicClientApplication CreateClientAppInstance(PublicClientAppKey publ
#if NETFRAMEWORK
if (_iWin32WindowFunc is not null)
{
builder.WithParentActivityOrWindow(_iWin32WindowFunc);
builder = builder.WithParentActivityOrWindow(_iWin32WindowFunc);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this actually necessary? Chaining typically returns the same object the method was called on, not a new object. Pretty sure WithParentActivityOrWindow() is setting internal state on builder and then returning builder. I'd be very surprised if it was returning a different instance of a Builder.

The API docs don't say either way, but the source code returns this:

https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/blob/428838e8ac9588e34c115e30e410e66855700b52/src/client/Microsoft.Identity.Client/AppConfig/PublicClientApplicationBuilder.cs#L287

I think your original change was fine (i.e. it worked) and maybe that's why there were no test failures. This might be slightly more robust, but I doubt MSAL will change its chaining behaviour, and break a bunch of calling code.

Copy link
Member

Choose a reason for hiding this comment

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

Because config is local to builder creation, I think it is necessary to store the updated config in the builder instance.

You can validate the builder assignment need by updating another config that overrides something else that can be validated easily in a standalone console app, where you can directly work with MSAL APIs for testing the theory.

@benrr101 benrr101 removed the Regression 💥 Issues that are regressions introduced from earlier PRs. label May 20, 2025
@benrr101
Copy link
Contributor Author

Backing PR out since as per discussion w/ @paulmedynski the builder just updates it's internal state and returns itself. No need to store the output of any With* call since the builder is modified internally.
Although both storing and not storing are valid, why have an extra PR for something you don't need?

@benrr101 benrr101 closed this May 20, 2025
@benrr101 benrr101 deleted the dev/russellben/apiscan-msal-fix branch June 12, 2025 16:54
@paulmedynski paulmedynski removed this from the 6.1-preview2 milestone Jun 23, 2025
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.

4 participants