Skip to content

Commit 9aa4f09

Browse files
committed
Task 41737: Merge feat/azure-split to main: Step 3 - Tie everything together
- Re-activate the Azure tests. - Address PR comments.
1 parent 16a3cd8 commit 9aa4f09

8 files changed

Lines changed: 25 additions & 51 deletions

File tree

src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/SqlAuthenticationProviderInternal.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ static Internal()
4848
return;
4949
}
5050

51-
// TODO(ADO-39845): Verify the assembly is signed by us?
51+
// TODO(https://sqlclientdrivers.visualstudio.com/ADO.Net/_workitems/edit/39845):
52+
// Verify the assembly is signed by us?
5253

5354
// Look for the manager class.
5455
const string className = "Microsoft.Data.SqlClient.SqlAuthenticationProviderManager";
@@ -65,7 +66,7 @@ static Internal()
6566
_getProvider = manager.GetMethod(
6667
"GetProvider",
6768
BindingFlags.NonPublic | BindingFlags.Static);
68-
69+
6970
if (_getProvider is null)
7071
{
7172
Log($"MDS GetProvider() method not found; " +
@@ -75,7 +76,7 @@ static Internal()
7576
_setProvider = manager.GetMethod(
7677
"SetProvider",
7778
BindingFlags.NonPublic | BindingFlags.Static);
78-
79+
7980
if (_setProvider is null)
8081
{
8182
Log($"MDS SetProvider() method not found; " +
@@ -164,7 +165,7 @@ internal static bool SetProvider(
164165
if (!result.HasValue)
165166
{
166167
Log($"SetProvider() invocation returned null; " +
167-
"translating to false");
168+
"translating to false");
168169
return false;
169170
}
170171

src/Microsoft.Data.SqlClient.Extensions/Azure/test/AADAuthenticationTests.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44

55
namespace Microsoft.Data.SqlClient.Extensions.Azure.Test;
66

7-
// TODO(https://sqlclientdrivers.visualstudio.com/ADO.Net/_workitems/edit/39233):
8-
// Enable this file once the MDS Azure files have been removed.
9-
#if false
10-
117
// These tests were moved from MDS FunctionalTests AADAuthenticationTests.cs.
128
public class AADAuthenticationTests
139
{
@@ -35,5 +31,3 @@ public void CustomActiveDirectoryProviderTest_AppClientId_DeviceFlowCallback()
3531
Assert.Same(authProvider, SqlAuthenticationProvider.GetProvider(SqlAuthenticationMethod.ActiveDirectoryDeviceCodeFlow));
3632
}
3733
}
38-
39-
#endif

src/Microsoft.Data.SqlClient.Extensions/Azure/test/AADConnectionTest.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
// TODO(https://sqlclientdrivers.visualstudio.com/ADO.Net/_workitems/edit/39233):
6-
// Enable this file once the MDS Azure files have been removed.
7-
#if false
8-
95
using System.Text.RegularExpressions;
106

117
namespace Microsoft.Data.SqlClient.Extensions.Azure.Test;
@@ -392,5 +388,3 @@ public static string RetrieveValueFromConnStr(string connStr, string[] keywords)
392388

393389
#endregion
394390
}
395-
396-
#endif

src/Microsoft.Data.SqlClient.Extensions/Azure/test/Azure.Test.csproj

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,14 @@
4444
<ProjectReference Include="$(RepoRoot)/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Microsoft.Data.SqlClient.TestUtilities.csproj" />
4545
</ItemGroup>
4646

47-
<!--
48-
TODO(https://sqlclientdrivers.visualstudio.com/ADO.Net/_workitems/edit/39233):
49-
Uncomment the below items once the Azure files are removed from MDS.
50-
-->
51-
5247
<!-- Conditional Project References -->
53-
<!-- <ItemGroup Condition="'$(ReferenceType)' == 'Project'">
48+
<ItemGroup Condition="'$(ReferenceType)' == 'Project'">
5449
<ProjectReference Include="$(RepoRoot)/src/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.csproj" />
55-
</ItemGroup> -->
50+
</ItemGroup>
5651

5752
<!-- Conditional Package References -->
58-
<!-- <ItemGroup Condition="'$(ReferenceType)' == 'Package'">
53+
<ItemGroup Condition="'$(ReferenceType)' == 'Package'">
5954
<PackageReference Include="Microsoft.Data.SqlClient" />
60-
</ItemGroup> -->
55+
</ItemGroup>
6156

6257
</Project>

src/Microsoft.Data.SqlClient.Extensions/Azure/test/Config.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,8 @@ internal static class Config
6363
internal static bool HasUserManagedIdentityClientId() => !UserManagedIdentityClientId.Empty();
6464
internal static bool HasWorkloadIdentityFederationServiceConnectionId() => !WorkloadIdentityFederationServiceConnectionId.Empty();
6565

66-
// TODO(https://sqlclientdrivers.visualstudio.com/ADO.Net/_workitems/edit/39233):
67-
// Uncomment this once the MDS Azure files have been removed.
68-
// internal static bool IsAzureSqlServer() =>
69-
// Utils.IsAzureSqlServer(new SqlConnectionStringBuilder(TcpConnectionString).DataSource);
66+
internal static bool IsAzureSqlServer() =>
67+
Utils.IsAzureSqlServer(new SqlConnectionStringBuilder(TcpConnectionString).DataSource);
7068

7169
internal static bool OnAdoPool() => AdoPool;
7270
internal static bool OnLinux() => RuntimeInformation.IsOSPlatform(OSPlatform.Linux);

src/Microsoft.Data.SqlClient.Extensions/Azure/test/DefaultAuthProviderTests.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
// TODO(https://sqlclientdrivers.visualstudio.com/ADO.Net/_workitems/edit/39233):
6-
// Enable this file once the MDS Azure files have been removed.
7-
#if false
8-
95
namespace Microsoft.Data.SqlClient.Extensions.Azure.Test;
106

117
public class DefaultAuthProviderTests
@@ -64,5 +60,3 @@ public void AuthProviderInstalled()
6460
}
6561
}
6662
}
67-
68-
#endif

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Connection/SqlConnectionInternal.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,7 +1674,7 @@ internal void OnFeatureExtAck(int featureId, byte[] data)
16741674
$"SqlInternalConnectionTds.OnFeatureExtAck | ERR | " +
16751675
$"Object ID {ObjectID}, " +
16761676
$"Unknown token for JSONSUPPORT");
1677-
1677+
16781678
throw SQL.ParsingError(ParsingErrorState.CorruptedTdsStream);
16791679
}
16801680

@@ -2691,7 +2691,7 @@ private SqlFedAuthToken GetFedAuthToken(SqlFedAuthInfo fedAuthInfo)
26912691
const int defaultRetryPeriod = 100;
26922692

26932693
// Number of attempts we are willing to perform.
2694-
const int maxAttempts = 1;
2694+
const int maxAttempts = 2;
26952695

26962696
// Username to use in error messages.
26972697
string? username = null;
@@ -2704,7 +2704,7 @@ private SqlFedAuthToken GetFedAuthToken(SqlFedAuthInfo fedAuthInfo)
27042704

27052705
// We will perform retries if the provider indicates an error that
27062706
// is retryable.
2707-
for (int attempt = 0; attempt <= maxAttempts; ++attempt)
2707+
for (int attempt = 1; attempt <= maxAttempts; ++attempt)
27082708
{
27092709
try
27102710
{
@@ -2809,7 +2809,7 @@ private SqlFedAuthToken GetFedAuthToken(SqlFedAuthInfo fedAuthInfo)
28092809
authParamsBuilder.WithPassword(ConnectionOptions.Password);
28102810
}
28112811
SqlAuthenticationParameters parameters = authParamsBuilder;
2812-
CancellationTokenSource cts = new();
2812+
using CancellationTokenSource cts = new();
28132813
// Use Connection timeout value to cancel token acquire request after certain period of time.(int)
28142814
if (_timeout.MillisecondsRemaining < Int32.MaxValue)
28152815
{
@@ -2845,12 +2845,12 @@ private SqlFedAuthToken GetFedAuthToken(SqlFedAuthInfo fedAuthInfo)
28452845
throw SQL.ActiveDirectoryTokenRetrievingTimeout(Enum.GetName(typeof(SqlAuthenticationMethod), ConnectionOptions.Authentication), ex.FailureCode, ex);
28462846
}
28472847

2848-
// We use a doubling backoff if the provider didn't provide
2848+
// We use a linear backoff if the provider didn't provide
28492849
// a retry period.
28502850
int retryPeriod =
28512851
ex.RetryPeriod > 0
28522852
? ex.RetryPeriod
2853-
: defaultRetryPeriod * (2 ^ attempt);
2853+
: defaultRetryPeriod * attempt;
28542854

28552855
SqlClientEventSource.Log.TryAdvancedTraceEvent("<sc.SqlInternalConnectionTds.GetFedAuthToken|ADV> {0}, Attempt: {1}, sleeping {2}[Milliseconds]", ObjectID, attempt, retryPeriod);
28562856
SqlClientEventSource.Log.TryAdvancedTraceEvent("<sc.SqlInternalConnectionTds.GetFedAuthToken|ADV> {0}, Attempt: {1}, remaining {2}[Milliseconds]", ObjectID, attempt, _timeout.MillisecondsRemaining);

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ static SqlAuthenticationProviderManager()
6666
return;
6767
}
6868

69-
// TODO(ADO-39845): Verify the assembly is signed by us?
69+
// TODO(https://sqlclientdrivers.visualstudio.com/ADO.Net/_workitems/edit/39845):
70+
// Verify the assembly is signed by us?
7071

7172
SqlClientEventSource.Log.TryTraceEvent(
7273
nameof(SqlAuthenticationProviderManager) +
@@ -262,18 +263,15 @@ internal static bool SetProvider(SqlAuthenticationMethod authenticationMethod, S
262263
throw SQL.UnsupportedAuthenticationByProvider(authenticationMethod.ToString(), provider.GetType().Name);
263264
}
264265
var methodName = "SetProvider";
265-
if (Instance._authenticationsWithAppSpecifiedProvider.Count > 0)
266+
foreach (SqlAuthenticationMethod candidateMethod in Instance._authenticationsWithAppSpecifiedProvider)
266267
{
267-
foreach (SqlAuthenticationMethod candidateMethod in Instance._authenticationsWithAppSpecifiedProvider)
268+
if (candidateMethod == authenticationMethod)
268269
{
269-
if (candidateMethod == authenticationMethod)
270-
{
271-
Instance._sqlAuthLogger.LogError(nameof(SqlAuthenticationProviderManager), methodName, $"Failed to add provider {GetProviderType(provider)} because a user-defined provider with type {GetProviderType(Instance._providers[authenticationMethod])} already existed for authentication {authenticationMethod}.");
270+
Instance._sqlAuthLogger.LogError(nameof(SqlAuthenticationProviderManager), methodName, $"Failed to add provider {GetProviderType(provider)} because a user-defined provider with type {GetProviderType(Instance._providers[authenticationMethod])} already existed for authentication {authenticationMethod}.");
272271

273-
// The app has already specified a Provider for this
274-
// authentication method, so we won't override it.
275-
return false;
276-
}
272+
// The app has already specified a Provider for this
273+
// authentication method, so we won't override it.
274+
return false;
277275
}
278276
}
279277
Instance._providers.AddOrUpdate(

0 commit comments

Comments
 (0)