-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Javad
authored
Jan 27, 2024
1 parent
759dc69
commit 01a589e
Showing
8 changed files
with
180 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/DateOnlyReadTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted.Setup; | ||
using Xunit; | ||
|
||
namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted | ||
{ | ||
public sealed class DateOnlyReadTests : IClassFixture<PlatformSpecificTestContext>, IDisposable | ||
{ | ||
private SQLSetupStrategy fixture; | ||
|
||
private readonly string tableName; | ||
|
||
public DateOnlyReadTests(PlatformSpecificTestContext context) | ||
{ | ||
fixture = context.Fixture; | ||
tableName = fixture.DateOnlyTestTable.Name; | ||
} | ||
|
||
// tests | ||
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsTargetReadyForAeWithKeyStore))] | ||
[ClassData(typeof(TestSelectOnEncryptedNonEncryptedColumnsDataDateOnly))] | ||
public void TestSelectOnEncryptedNonEncryptedColumns(string connString, string selectQuery, int totalColumnsInSelect, string[] types) | ||
{ | ||
Assert.False(string.IsNullOrWhiteSpace(selectQuery), "FAILED: select query should not be null or empty."); | ||
Assert.True(totalColumnsInSelect <= 3, "FAILED: totalColumnsInSelect should <= 3."); | ||
|
||
using (SqlConnection sqlConn = new SqlConnection(connString)) | ||
{ | ||
sqlConn.Open(); | ||
|
||
Table.DeleteData(tableName, sqlConn); | ||
|
||
// insert 1 row data | ||
CustomerDateOnly customer = new CustomerDateOnly( | ||
45, | ||
"Microsoft", | ||
"Corporation", | ||
new DateOnly(2001, 1, 31), | ||
new TimeOnly(18, 36, 45)); | ||
|
||
DatabaseHelper.InsertCustomerDateOnlyData(sqlConn, null, tableName, customer); | ||
|
||
using (SqlCommand sqlCommand = new SqlCommand(string.Format(selectQuery, tableName), | ||
sqlConn, null, SqlCommandColumnEncryptionSetting.Enabled)) | ||
{ | ||
using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader()) | ||
{ | ||
Assert.True(sqlDataReader.HasRows, "FAILED: Select statement did not return any rows."); | ||
|
||
while (sqlDataReader.Read()) | ||
{ | ||
DatabaseHelper.CompareResults(sqlDataReader, types, totalColumnsInSelect); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
public void Dispose() | ||
{ | ||
foreach (string connStrAE in DataTestUtility.AEConnStringsSetup) | ||
{ | ||
using (SqlConnection sqlConnection = new SqlConnection(connStrAE)) | ||
{ | ||
sqlConnection.Open(); | ||
Table.DeleteData(fixture.DateOnlyTestTable.Name, sqlConnection); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public class TestSelectOnEncryptedNonEncryptedColumnsDataDateOnly : IEnumerable<object[]> | ||
{ | ||
public IEnumerator<object[]> GetEnumerator() | ||
{ | ||
foreach (string connStrAE in DataTestUtility.AEConnStrings) | ||
{ | ||
yield return new object[] { connStrAE, @"select CustomerId, FirstName, LastName from [{0}] ", 3, new string[] { @"int", @"string", @"string" } }; | ||
yield return new object[] { connStrAE, @"select CustomerId, FirstName from [{0}] ", 2, new string[] { @"int", @"string" } }; | ||
yield return new object[] { connStrAE, @"select LastName from [{0}] ", 1, new string[] { @"string" }}; | ||
yield return new object[] { connStrAE, @"select DateOfBirth, TimeOfDay from [{0}] ", 2, new string[] { @"DateOnly", "TimeOnly" } }; | ||
} | ||
} | ||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
....Data.SqlClient/tests/ManualTests/AlwaysEncrypted/TestFixtures/Setup/DateOnlyTestTable.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted.Setup | ||
{ | ||
public class DateOnlyTestTable : Table | ||
{ | ||
private const string ColumnEncryptionAlgorithmName = @"AEAD_AES_256_CBC_HMAC_SHA_256"; | ||
public ColumnEncryptionKey columnEncryptionKey1; | ||
public ColumnEncryptionKey columnEncryptionKey2; | ||
private bool useDeterministicEncryption; | ||
|
||
public DateOnlyTestTable(string tableName, ColumnEncryptionKey columnEncryptionKey1, ColumnEncryptionKey columnEncryptionKey2, bool useDeterministicEncryption = false) : base(tableName) | ||
{ | ||
this.columnEncryptionKey1 = columnEncryptionKey1; | ||
this.columnEncryptionKey2 = columnEncryptionKey2; | ||
this.useDeterministicEncryption = useDeterministicEncryption; | ||
} | ||
|
||
public override void Create(SqlConnection sqlConnection) | ||
{ | ||
string encryptionType = useDeterministicEncryption ? "DETERMINISTIC" : DataTestUtility.EnclaveEnabled ? "RANDOMIZED" : "DETERMINISTIC"; | ||
string sql = | ||
$@"CREATE TABLE [dbo].[{Name}] | ||
( | ||
[CustomerId] [int] ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = [{columnEncryptionKey1.Name}], ENCRYPTION_TYPE = {encryptionType}, ALGORITHM = '{ColumnEncryptionAlgorithmName}'), | ||
[FirstName] [nvarchar](50) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = [{columnEncryptionKey2.Name}], ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = '{ColumnEncryptionAlgorithmName}'), | ||
[LastName] [nvarchar](50) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = [{columnEncryptionKey2.Name}], ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = '{ColumnEncryptionAlgorithmName}'), | ||
[TimeOfDay] [time] ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = [{columnEncryptionKey1.Name}], ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = '{ColumnEncryptionAlgorithmName}'), | ||
[DateOfBirth] [date] ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = [{columnEncryptionKey1.Name}], ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = '{ColumnEncryptionAlgorithmName}') | ||
)"; | ||
|
||
using (SqlCommand command = sqlConnection.CreateCommand()) | ||
{ | ||
command.CommandText = sql; | ||
command.ExecuteNonQuery(); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters