Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2732,6 +2732,14 @@ private SqlFedAuthToken GetFedAuthToken(SqlFedAuthInfo fedAuthInfo)
SqlAuthenticationProvider? authProvider = SqlAuthenticationProviderManager.GetProvider(ConnectionOptions.Authentication);
if (authProvider == null && _accessTokenCallback == null)
{
#pragma warning disable 0618 // ActiveDirectoryPassword is obsolete
if (ConnectionOptions.Authentication >= SqlAuthenticationMethod.ActiveDirectoryPassword
&& ConnectionOptions.Authentication <= SqlAuthenticationMethod.ActiveDirectoryWorkloadIdentity)
#pragma warning restore 0618
Comment on lines +2735 to +2738
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

The AD-auth detection relies on a numeric range comparison over SqlAuthenticationMethod values (>= ActiveDirectoryPassword and <= ActiveDirectoryWorkloadIdentity). This is brittle because it silently depends on enum value ordering/contiguity and could misclassify methods if the enum changes. Prefer an explicit switch/pattern match listing the AD methods (or a shared helper) so the intent stays correct if the enum evolves.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed - just list each method explictily here to make it obvious.

{
throw SQL.CannotFindActiveDirectoryAuthProvider(ConnectionOptions.Authentication.ToString());
}

throw SQL.CannotFindAuthProvider(ConnectionOptions.Authentication.ToString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,11 @@ internal static Exception CannotFindAuthProvider(string authentication)
return ADP.Argument(StringsHelper.GetString(Strings.SQL_CannotFindAuthProvider, authentication));
}

internal static Exception CannotFindActiveDirectoryAuthProvider(string authentication)
{
return ADP.Argument(StringsHelper.GetString(Strings.SQL_CannotFindActiveDirectoryAuthProvider, authentication));
}

internal static Exception ParameterCannotBeEmpty(string paramName)
{
return ADP.ArgumentNull(StringsHelper.GetString(Strings.SQL_ParameterCannotBeEmpty, paramName));
Expand Down
Loading
Loading