Skip to content

Commit 6cd7cea

Browse files
[7.0.1 Cherry-pick] Enable User Agent feature extension (#4154)
Co-authored-by: Cheena Malhotra <13396919+cheenamalhotra@users.noreply.github.com>
1 parent ccce9d3 commit 6cd7cea

5 files changed

Lines changed: 1 addition & 95 deletions

File tree

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@ internal static class LocalAppContextSwitches
3636
private const string EnableMultiSubnetFailoverByDefaultString =
3737
"Switch.Microsoft.Data.SqlClient.EnableMultiSubnetFailoverByDefault";
3838

39-
/// <summary>
40-
/// The name of the app context switch that controls whether
41-
/// the user agent feature is enabled.
42-
/// </summary>
43-
private const string EnableUserAgentString =
44-
"Switch.Microsoft.Data.SqlClient.EnableUserAgent";
45-
4639
#if NET
4740
/// <summary>
4841
/// The name of the app context switch that controls whether
@@ -177,11 +170,6 @@ private enum SwitchValue : byte
177170
/// </summary>
178171
private static SwitchValue s_enableMultiSubnetFailoverByDefault = SwitchValue.None;
179172

180-
/// <summary>
181-
/// The cached value of the EnableUserAgent switch.
182-
/// </summary>
183-
private static SwitchValue s_enableUserAgent = SwitchValue.None;
184-
185173
#if NET
186174
/// <summary>
187175
/// The cached value of the GlobalizationInvariantMode switch.
@@ -319,18 +307,6 @@ static LocalAppContextSwitches()
319307
defaultValue: false,
320308
ref s_enableMultiSubnetFailoverByDefault);
321309

322-
/// <summary>
323-
/// When set to true, the user agent feature is enabled and the driver will
324-
/// send the user agent string to the server.
325-
///
326-
/// The default value of this switch is false.
327-
/// </summary>
328-
public static bool EnableUserAgent =>
329-
AcquireAndReturn(
330-
EnableUserAgentString,
331-
defaultValue: false,
332-
ref s_enableUserAgent);
333-
334310
#if NET
335311
/// <summary>
336312
/// .NET Core 2.0 and up supports Globalization Invariant mode, which

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9663,7 +9663,7 @@ private int ApplyFeatureExData(TdsEnums.FeatureExtension requestedFeatures,
96639663
checked
96649664
{
96659665
// NOTE: As part of TDS spec UserAgent feature extension should be the first feature extension in the list.
9666-
if (LocalAppContextSwitches.EnableUserAgent && ((requestedFeatures & TdsEnums.FeatureExtension.UserAgent) != 0))
9666+
if ((requestedFeatures & TdsEnums.FeatureExtension.UserAgent) != 0)
96679667
{
96689668
length += WriteUserAgentFeatureRequest(userAgent, write);
96699669
}

src/Microsoft.Data.SqlClient/tests/Common/LocalAppContextSwitchesHelper.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public sealed class LocalAppContextSwitchesHelper : IDisposable
4343
private readonly bool? _disableTnirByDefaultOriginal;
4444
#endif
4545
private readonly bool? _enableMultiSubnetFailoverByDefaultOriginal;
46-
private readonly bool? _enableUserAgentOriginal;
4746
#if NET
4847
private readonly bool? _globalizationInvariantModeOriginal;
4948
#endif
@@ -93,8 +92,6 @@ public LocalAppContextSwitchesHelper()
9392
#endif
9493
_enableMultiSubnetFailoverByDefaultOriginal =
9594
GetSwitchValue("s_enableMultiSubnetFailoverByDefault");
96-
_enableUserAgentOriginal =
97-
GetSwitchValue("s_enableUserAgent");
9895
#if NET
9996
_globalizationInvariantModeOriginal =
10097
GetSwitchValue("s_globalizationInvariantMode");
@@ -149,9 +146,6 @@ public void Dispose()
149146
SetSwitchValue(
150147
"s_enableMultiSubnetFailoverByDefault",
151148
_enableMultiSubnetFailoverByDefaultOriginal);
152-
SetSwitchValue(
153-
"s_enableUserAgent",
154-
_enableUserAgentOriginal);
155149
#if NET
156150
SetSwitchValue(
157151
"s_globalizationInvariantMode",
@@ -228,15 +222,6 @@ public bool? EnableMultiSubnetFailoverByDefault
228222
set => SetSwitchValue("s_enableMultiSubnetFailoverByDefault", value);
229223
}
230224

231-
/// <summary>
232-
/// Get or set the EnableUserAgent switch value.
233-
/// </summary>
234-
public bool? EnableUserAgent
235-
{
236-
get => GetSwitchValue("s_enableUserAgent");
237-
set => SetSwitchValue("s_enableUserAgent", value);
238-
}
239-
240225
#if NET
241226
/// <summary>
242227
/// Get or set the GlobalizationInvariantMode switch value.

src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/LocalAppContextSwitchesTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public void TestDefaultAppContextSwitchValues()
2828
Assert.False(LocalAppContextSwitches.UseConnectionPoolV2);
2929
Assert.False(LocalAppContextSwitches.TruncateScaledDecimal);
3030
Assert.False(LocalAppContextSwitches.IgnoreServerProvidedFailoverPartner);
31-
Assert.False(LocalAppContextSwitches.EnableUserAgent);
3231
Assert.False(LocalAppContextSwitches.EnableMultiSubnetFailoverByDefault);
3332
#if NET
3433
Assert.False(LocalAppContextSwitches.GlobalizationInvariantMode);

src/Microsoft.Data.SqlClient/tests/UnitTests/SimulatedServerTests/ConnectionTests.cs

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -840,10 +840,6 @@ public void TestConnWithVectorFeatExtVersionNegotiation(bool expectedConnectionR
840840
[InlineData(false)]
841841
public void TestConnWithUserAgentFeatureExtension(bool sendAck)
842842
{
843-
// Enable sending the UserAgent if desired.
844-
using LocalAppContextSwitchesHelper switchesHelper = new();
845-
switchesHelper.EnableUserAgent = true;
846-
847843
// Start the test server.
848844
using TdsServer server = new();
849845
server.Start();
@@ -904,55 +900,5 @@ public void TestConnWithUserAgentFeatureExtension(bool sendAck)
904900

905901
// TODO: Confirm the server sent an Ack by reading log message from SqlInternalConnectionTds
906902
}
907-
908-
/// <summary>
909-
/// Test to verify no UserAgent relevant information is sent when EnableUserAgentField switch is disabled.
910-
/// </summary>
911-
[Fact]
912-
public void TestConnWithoutUserAgentFeatureExtension()
913-
{
914-
// Disable the client-side UserAgent field entirely
915-
using LocalAppContextSwitchesHelper switchesHelper = new();
916-
switchesHelper.EnableUserAgent = false;
917-
918-
using var server = new TdsServer();
919-
server.Start();
920-
921-
// Do not advertise or force the UserAgent feature on the server
922-
server.ServerSupportedUserAgentFeatureExtVersion = 0x00; // no support
923-
server.EnableUserAgentFeatureExt = false; // no forced ACK
924-
925-
bool loginValidated = false;
926-
bool userAgentFeatureSeen = false;
927-
928-
// Inspect the LOGIN7 packet captured by the test server
929-
server.OnLogin7Validated = loginToken =>
930-
{
931-
var featureExtTokens = loginToken.FeatureExt
932-
.OfType<TDSLogin7GenericOptionToken>()
933-
.ToArray();
934-
935-
// Ensure there is no UserAgentSupport token at all
936-
var uaToken = featureExtTokens.FirstOrDefault(t => t.FeatureID == TDSFeatureID.UserAgentSupport);
937-
userAgentFeatureSeen = uaToken is not null;
938-
939-
loginValidated = true;
940-
};
941-
942-
// Connect to the test TDS server with a basic connection string
943-
var connStr = new SqlConnectionStringBuilder
944-
{
945-
DataSource = $"localhost,{server.EndPoint.Port}",
946-
Encrypt = SqlConnectionEncryptOption.Optional,
947-
}.ConnectionString;
948-
949-
using var connection = new SqlConnection(connStr);
950-
connection.Open();
951-
952-
// Verify that the connection succeeded and no UserAgent data was sent
953-
Assert.Equal(ConnectionState.Open, connection.State);
954-
Assert.True(loginValidated, "Expected LOGIN7 to be validated by the test server");
955-
Assert.False(userAgentFeatureSeen, "Did not expect a UserAgentSupport feature token in LOGIN7");
956-
}
957903
}
958904
}

0 commit comments

Comments
 (0)