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 91c8692

Browse files
committed
Updating test, PR feedback
1 parent 442a698 commit 91c8692

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,22 +1749,22 @@ await Task.Factory.StartNew(() => Task.Run(async () => {
17491749
public ConnectionDetails ParseConnectionString(string connectionString)
17501750
{
17511751
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectionString);
1752-
bool isAzureMFA = builder.Authentication == SqlAuthenticationMethod.ActiveDirectoryInteractive; // Azure Multi-Factor Authentication
1753-
bool isSqlLogin = builder.Authentication == SqlAuthenticationMethod.SqlPassword;// SQL username/password
1754-
bool isIntegrated = builder.IntegratedSecurity; // Windows Integrated Security
1755-
string Authenticationtype = null;
17561752

1757-
if (isAzureMFA)
1753+
string mappedAuthenticationType;
1754+
if (builder.IntegratedSecurity)
17581755
{
1759-
Authenticationtype = "AzureMFA";
1756+
mappedAuthenticationType = "Integrated";
1757+
} else if (builder.Authentication == SqlAuthenticationMethod.ActiveDirectoryInteractive)
1758+
{
1759+
mappedAuthenticationType = "AzureMFA";
17601760
}
1761-
else if(isSqlLogin)
1761+
else if (builder.Authentication == SqlAuthenticationMethod.SqlPassword || builder.Authentication == SqlAuthenticationMethod.NotSpecified)
17621762
{
1763-
Authenticationtype = "SqlLogin";
1763+
mappedAuthenticationType = "SqlLogin";
17641764
}
1765-
else if (isIntegrated)
1765+
else
17661766
{
1767-
Authenticationtype = "Integrated";
1767+
mappedAuthenticationType = builder.Authentication.ToString();
17681768
}
17691769

17701770
// Set defaults as per MSSQL connection property defaults, not SqlClient's Connection string buider defaults
@@ -1773,7 +1773,7 @@ public ConnectionDetails ParseConnectionString(string connectionString)
17731773
ApplicationIntent = defaultBuilder.ApplicationIntent != builder.ApplicationIntent ? builder.ApplicationIntent.ToString() : null,
17741774
ApplicationName = defaultBuilder.ApplicationName != builder.ApplicationName ? builder.ApplicationName : ApplicationName,
17751775
AttachDbFilename = defaultBuilder.AttachDBFilename != builder.AttachDBFilename ? builder.AttachDBFilename.ToString() : null,
1776-
AuthenticationType = Authenticationtype,
1776+
AuthenticationType = mappedAuthenticationType,
17771777
ConnectRetryCount = defaultBuilder.ConnectRetryCount != builder.ConnectRetryCount ? builder.ConnectRetryCount : 1,
17781778
ConnectRetryInterval = defaultBuilder.ConnectRetryInterval != builder.ConnectRetryInterval ? builder.ConnectRetryInterval : 10,
17791779
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)