WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit b233306

Browse files
allancascanteAllan CascanteBenjin
authored
Don't default to AzureMFA (#2549)
* When parsing a connection string don't default to AzureMFA if the auth method is not, SqlLogin or Integrated or AzureMFA then return null as the AuthenticationType * Updating test, PR feedback --------- Co-authored-by: Allan Cascante <[email protected]> Co-authored-by: Benjin Dubishar (from Dev Box) <[email protected]>
1 parent aab6826 commit b233306

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,15 +1750,30 @@ public ConnectionDetails ParseConnectionString(string connectionString)
17501750
{
17511751
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectionString);
17521752

1753+
string mappedAuthenticationType;
1754+
if (builder.IntegratedSecurity)
1755+
{
1756+
mappedAuthenticationType = "Integrated";
1757+
} else if (builder.Authentication == SqlAuthenticationMethod.ActiveDirectoryInteractive)
1758+
{
1759+
mappedAuthenticationType = "AzureMFA";
1760+
}
1761+
else if (builder.Authentication == SqlAuthenticationMethod.SqlPassword || builder.Authentication == SqlAuthenticationMethod.NotSpecified)
1762+
{
1763+
mappedAuthenticationType = "SqlLogin";
1764+
}
1765+
else
1766+
{
1767+
mappedAuthenticationType = builder.Authentication.ToString();
1768+
}
1769+
17531770
// Set defaults as per MSSQL connection property defaults, not SqlClient's Connection string buider defaults
17541771
ConnectionDetails details = new ConnectionDetails()
17551772
{
17561773
ApplicationIntent = defaultBuilder.ApplicationIntent != builder.ApplicationIntent ? builder.ApplicationIntent.ToString() : null,
17571774
ApplicationName = defaultBuilder.ApplicationName != builder.ApplicationName ? builder.ApplicationName : ApplicationName,
17581775
AttachDbFilename = defaultBuilder.AttachDBFilename != builder.AttachDBFilename ? builder.AttachDBFilename.ToString() : null,
1759-
AuthenticationType = builder.IntegratedSecurity ? "Integrated" :
1760-
((builder.Authentication == SqlAuthenticationMethod.SqlPassword || builder.Authentication == SqlAuthenticationMethod.NotSpecified)
1761-
? "SqlLogin" : "AzureMFA"),
1776+
AuthenticationType = mappedAuthenticationType,
17621777
ConnectRetryCount = defaultBuilder.ConnectRetryCount != builder.ConnectRetryCount ? builder.ConnectRetryCount : 1,
17631778
ConnectRetryInterval = defaultBuilder.ConnectRetryInterval != builder.ConnectRetryInterval ? builder.ConnectRetryInterval : 10,
17641779
ConnectTimeout = defaultBuilder.ConnectTimeout != builder.ConnectTimeout ? builder.ConnectTimeout : 30,

test/Microsoft.SqlTools.ServiceLayer.UnitTests/Connection/ConnectionServiceTests.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,18 +1863,24 @@ public void ParseConnectionStringTest_AuthTypes()
18631863
details = service.ParseConnectionString(connectionString);
18641864
Assert.That(details.AuthenticationType, Is.EqualTo("Integrated"));
18651865

1866-
// AAD auth types boil down to AzureMFA
1867-
connectionString = "Server=tcp:{servername},1433;Initial Catalog={databasename};Authentication=ActiveDirectoryIntegrated;";
1866+
// AAD auth types
1867+
// ActiveDirectoryInteractive is mapped to to AzureMFA
1868+
connectionString = "Server=tcp:{servername},1433;Initial Catalog={databasename};Authentication=ActiveDirectoryInteractive;";
18681869
details = service.ParseConnectionString(connectionString);
18691870
Assert.That(details.AuthenticationType, Is.EqualTo("AzureMFA"));
18701871

1871-
connectionString = "Server=tcp:{servername},1433;Initial Catalog={databasename};Authentication=ActiveDirectoryInteractive;";
1872+
// Other AAD types are unchanged
1873+
connectionString = "Server=tcp:{servername},1433;Initial Catalog={databasename};Authentication=ActiveDirectoryIntegrated;";
18721874
details = service.ParseConnectionString(connectionString);
1873-
Assert.That(details.AuthenticationType, Is.EqualTo("AzureMFA"));
1875+
Assert.That(details.AuthenticationType, Is.EqualTo("ActiveDirectoryIntegrated"));
18741876

18751877
connectionString = "Server=tcp:{servername},1433;Initial Catalog={databasename};Authentication=ActiveDirectoryDefault;";
18761878
details = service.ParseConnectionString(connectionString);
1877-
Assert.That(details.AuthenticationType, Is.EqualTo("AzureMFA"));
1879+
Assert.That(details.AuthenticationType, Is.EqualTo("ActiveDirectoryDefault"));
1880+
1881+
// Invalid throws
1882+
connectionString = "Server=tcp:{servername},1433;Initial Catalog={databasename};Authentication=InvalidAuthType;";
1883+
Assert.Throws<ArgumentException>(() => service.ParseConnectionString(connectionString), "Invalid value for key 'authentication'.");
18781884
}
18791885

18801886
[Test]

0 commit comments

Comments
 (0)