Skip to content

Commit

Permalink
Enable column encryption setting (#908)
Browse files Browse the repository at this point in the history
* Enable the Column Encryption advanced security connection setting and add supporting tests.
  • Loading branch information
Xtrimmer committed Jan 23, 2020
1 parent 1577a0b commit 7b102df
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,20 @@ public static SqlConnectionStringBuilder CreateConnectionStringBuilder(Connectio
throw new ArgumentException(SR.ConnectionServiceConnStringInvalidAuthType(connectionDetails.AuthenticationType));
}
}
if (!string.IsNullOrEmpty(connectionDetails.ColumnEncryptionSetting))
{
switch (connectionDetails.ColumnEncryptionSetting.ToUpper())
{
case "ENABLED":
connectionBuilder.ColumnEncryptionSetting = SqlConnectionColumnEncryptionSetting.Enabled;
break;
case "DISABLED":
connectionBuilder.ColumnEncryptionSetting = SqlConnectionColumnEncryptionSetting.Disabled;
break;
default:
throw new ArgumentException(SR.ConnectionServiceConnStringInvalidColumnEncryptionSetting(connectionDetails.ColumnEncryptionSetting));
}
}
if (connectionDetails.Encrypt.HasValue)
{
connectionBuilder.Encrypt = connectionDetails.Encrypt.Value;
Expand Down Expand Up @@ -1313,6 +1327,7 @@ public ConnectionDetails ParseConnectionString(string connectionString)
ConnectTimeout = builder.ConnectTimeout,
CurrentLanguage = builder.CurrentLanguage,
DatabaseName = builder.InitialCatalog,
ColumnEncryptionSetting = builder.ColumnEncryptionSetting.ToString(),
Encrypt = builder.Encrypt,
FailoverPartner = builder.FailoverPartner,
LoadBalanceTimeout = builder.LoadBalanceTimeout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ public string AuthenticationType
}
}

/// <summary>
/// Gets or sets a value that specifies that Always Encrypted functionality is enabled in a connection.
/// </summary>
public string ColumnEncryptionSetting
{
get
{
return GetOptionValue<string>("columnEncryptionSetting");
}

set
{
SetOptionValue("columnEncryptionSetting", value);
}
}

/// <summary>
/// Gets or sets a Boolean value that indicates whether SQL Server uses SSL encryption for all data sent between the client and server if the server has a certificate installed.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static ConnectionDetails Clone(this ConnectionDetails details)
UserName = details.UserName,
Password = details.Password,
AuthenticationType = details.AuthenticationType,
ColumnEncryptionSetting = details.ColumnEncryptionSetting,
Encrypt = details.Encrypt,
TrustServerCertificate = details.TrustServerCertificate,
PersistSecurityInfo = details.PersistSecurityInfo,
Expand Down
8 changes: 8 additions & 0 deletions src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2987,6 +2987,11 @@ public static string ConnectionServiceConnStringInvalidAuthType(string authType)
return Keys.GetString(Keys.ConnectionServiceConnStringInvalidAuthType, authType);
}

public static string ConnectionServiceConnStringInvalidColumnEncryptionSetting(string columnEncryptionSetting)
{
return Keys.GetString(Keys.ConnectionServiceConnStringInvalidColumnEncryptionSetting, columnEncryptionSetting);
}

public static string ConnectionServiceConnStringInvalidIntent(string intent)
{
return Keys.GetString(Keys.ConnectionServiceConnStringInvalidIntent, intent);
Expand Down Expand Up @@ -3160,6 +3165,9 @@ public class Keys
public const string ConnectionServiceConnStringInvalidAuthType = "ConnectionServiceConnStringInvalidAuthType";


public const string ConnectionServiceConnStringInvalidColumnEncryptionSetting = "ConnectionServiceConnStringInvalidColumnEncryptionSetting";


public const string ConnectionServiceConnStringInvalidIntent = "ConnectionServiceConnStringInvalidIntent";


Expand Down
7 changes: 6 additions & 1 deletion src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,12 @@
<value>Invalid value &apos;{0}&apos; for AuthenticationType. Valid values are &apos;Integrated&apos; and &apos;SqlLogin&apos;.</value>
<comment>.
Parameters: 0 - authType (string) </comment>
</data>
</data>
<data name="ConnectionServiceConnStringInvalidColumnEncryptionSetting" xml:space="preserve">
<value>Invalid value &apos;{0}&apos; for ComlumEncryption. Valid values are &apos;Enabled&apos; and &apos;Disabled&apos;.</value>
<comment>.
Parameters: 0 - columnEncryptionSetting (string) </comment>
</data>
<data name="ConnectionServiceConnStringInvalidIntent" xml:space="preserve">
<value>Invalid value &apos;{0}&apos; for ApplicationIntent. Valid values are &apos;ReadWrite&apos; and &apos;ReadOnly&apos;.</value>
<comment>.
Expand Down
2 changes: 2 additions & 0 deletions src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ ConnectionServiceDbErrorDefaultNotConnected(string uri) = Specified URI '{0}' do

ConnectionServiceConnStringInvalidAuthType(string authType) = Invalid value '{0}' for AuthenticationType. Valid values are 'Integrated' and 'SqlLogin'.

ConnectionServiceConnStringInvalidColumnEncryptionSetting(string columnEncryptionSetting) = Invalid value '{0}' for ComlumEncryption. Valid values are 'Enabled' and 'Disabled'.

ConnectionServiceConnStringInvalidIntent(string intent) = Invalid value '{0}' for ApplicationIntent. Valid values are 'ReadWrite' and 'ReadOnly'.

ConnectionServiceConnectionCanceled = Connection canceled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void ConnectionDetailsWithoutAnyOptionShouldReturnNullOrDefaultForOptions
Assert.Equal(details.MaxPoolSize, expectedForInt);
Assert.Equal(details.MinPoolSize, expectedForInt);
Assert.Equal(details.PacketSize, expectedForInt);
Assert.Equal(details.ColumnEncryptionSetting, expectedForStrings);
Assert.Equal(details.Encrypt, expectedForBoolean);
Assert.Equal(details.MultipleActiveResultSets, expectedForBoolean);
Assert.Equal(details.MultiSubnetFailover, expectedForBoolean);
Expand Down Expand Up @@ -81,6 +82,7 @@ public void ConnectionDetailsPropertySettersShouldSetOptionValuesCorrectly()
details.MaxPoolSize = expectedForInt + index++;
details.MinPoolSize = expectedForInt + index++;
details.PacketSize = expectedForInt + index++;
details.ColumnEncryptionSetting = expectedForStrings + index++;
details.Encrypt = (index++ % 2 == 0);
details.MultipleActiveResultSets = (index++ % 2 == 0);
details.MultiSubnetFailover = (index++ % 2 == 0);
Expand Down Expand Up @@ -110,6 +112,7 @@ public void ConnectionDetailsPropertySettersShouldSetOptionValuesCorrectly()
Assert.Equal(details.MaxPoolSize, expectedForInt + index++);
Assert.Equal(details.MinPoolSize, expectedForInt + index++);
Assert.Equal(details.PacketSize, expectedForInt + index++);
Assert.Equal(details.ColumnEncryptionSetting, expectedForStrings + index++);
Assert.Equal(details.Encrypt, (index++ % 2 == 0));
Assert.Equal(details.MultipleActiveResultSets, (index++ % 2 == 0));
Assert.Equal(details.MultiSubnetFailover, (index++ % 2 == 0));
Expand Down Expand Up @@ -148,6 +151,7 @@ public void ConnectionDetailsOptionsShouldBeDefinedInConnectionProviderOptions()
details.MaxPoolSize = expectedForInt + index++;
details.MinPoolSize = expectedForInt + index++;
details.PacketSize = expectedForInt + index++;
details.ColumnEncryptionSetting = expectedForStrings + index++;
details.Encrypt = (index++ % 2 == 0);
details.MultipleActiveResultSets = (index++ % 2 == 0);
details.MultiSubnetFailover = (index++ % 2 == 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,14 @@ public async Task ConnectingWithNullParametersObjectYieldsErrorMessage()
[InlineData("AuthenticationType", "SqlLogin", "")]
[InlineData("Encrypt", true, "Encrypt")]
[InlineData("Encrypt", false, "Encrypt")]
[InlineData("ColumnEncryptionSetting", "Enabled", "Column Encryption Setting=Enabled")]
[InlineData("ColumnEncryptionSetting", "Disabled", "Column Encryption Setting=Disabled")]
[InlineData("ColumnEncryptionSetting", "enabled", "Column Encryption Setting=Enabled")]
[InlineData("ColumnEncryptionSetting", "disabled", "Column Encryption Setting=Disabled")]
[InlineData("ColumnEncryptionSetting", "ENABLED", "Column Encryption Setting=Enabled")]
[InlineData("ColumnEncryptionSetting", "DISABLED", "Column Encryption Setting=Disabled")]
[InlineData("ColumnEncryptionSetting", "eNaBlEd", "Column Encryption Setting=Enabled")]
[InlineData("ColumnEncryptionSetting", "DiSaBlEd", "Column Encryption Setting=Disabled")]
[InlineData("TrustServerCertificate", true, "TrustServerCertificate")]
[InlineData("TrustServerCertificate", false, "TrustServerCertificate")]
[InlineData("PersistSecurityInfo", true, "Persist Security Info")]
Expand Down Expand Up @@ -545,13 +553,16 @@ public void ConnectingWithOptionalParametersBuildsConnectionString(string proper
}

/// <summary>
/// Build connection string with an invalid auth type
/// Build connection string with an invalid property type
/// </summary>
[Fact]
public void BuildConnectionStringWithInvalidAuthType()
[Theory]
[InlineData("AuthenticationType", "NotAValidAuthType")]
[InlineData("ColumnEncryptionSetting", "NotAValidColumnEncryptionSetting")]
public void BuildConnectionStringWithInvalidOptions(string propertyName, object propertyValue)
{
ConnectionDetails details = TestObjects.GetTestConnectionDetails();
details.AuthenticationType = "NotAValidAuthType";
PropertyInfo info = details.GetType().GetProperty(propertyName);
info.SetValue(details, propertyValue);
Assert.Throws<ArgumentException>(() => ConnectionService.BuildConnectionString(details));
}

Expand Down

0 comments on commit 7b102df

Please sign in to comment.