|
|
@ -2,31 +2,27 @@
|
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
//------------------------------------------------------------
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
namespace Microsoft.Azure.Cosmos.Encryption.EmulatorTests
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
using Microsoft.Azure.Cosmos;
|
|
|
|
|
|
|
|
using Microsoft.Azure.Cosmos.Encryption;
|
|
|
|
|
|
|
|
using Microsoft.Azure.Cosmos.Fluent;
|
|
|
|
|
|
|
|
using Microsoft.Azure.Cosmos.Scripts;
|
|
|
|
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Net;
|
|
|
|
using System.Net;
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Microsoft.Azure.Cosmos;
|
|
|
|
|
|
|
|
using Microsoft.Azure.Cosmos.Json;
|
|
|
|
|
|
|
|
using Microsoft.Azure.Cosmos.Fluent;
|
|
|
|
|
|
|
|
using Microsoft.Azure.Cosmos.Scripts;
|
|
|
|
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
using JsonWriter = Json.JsonWriter;
|
|
|
|
|
|
|
|
using JsonReader = Json.JsonReader;
|
|
|
|
|
|
|
|
using Microsoft.Azure.Cosmos.Encryption;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[TestClass]
|
|
|
|
[TestClass]
|
|
|
|
public class EncryptionTests
|
|
|
|
public class EncryptionTests
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private static EncryptionKeyWrapMetadata metadata1 = new EncryptionKeyWrapMetadata("metadata1");
|
|
|
|
private static readonly EncryptionKeyWrapMetadata metadata1 = new EncryptionKeyWrapMetadata("metadata1");
|
|
|
|
private static EncryptionKeyWrapMetadata metadata2 = new EncryptionKeyWrapMetadata("metadata2");
|
|
|
|
private static readonly EncryptionKeyWrapMetadata metadata2 = new EncryptionKeyWrapMetadata("metadata2");
|
|
|
|
private const string metadataUpdateSuffix = "updated";
|
|
|
|
private const string metadataUpdateSuffix = "updated";
|
|
|
|
private static TimeSpan cacheTTL = TimeSpan.FromDays(1);
|
|
|
|
private static TimeSpan cacheTTL = TimeSpan.FromDays(1);
|
|
|
|
|
|
|
|
|
|
|
@ -34,9 +30,8 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
|
|
|
|
|
|
|
|
private static CosmosClient client;
|
|
|
|
private static CosmosClient client;
|
|
|
|
|
|
|
|
|
|
|
|
private static DatabaseInternal databaseCore;
|
|
|
|
private static Database database;
|
|
|
|
private static DataEncryptionKeyProperties dekProperties;
|
|
|
|
private static DataEncryptionKeyProperties dekProperties;
|
|
|
|
private static ContainerInternal itemContainerCore;
|
|
|
|
|
|
|
|
private static Container itemContainer;
|
|
|
|
private static Container itemContainer;
|
|
|
|
private static Container keyContainer;
|
|
|
|
private static Container keyContainer;
|
|
|
|
private static CosmosDataEncryptionKeyProvider dekProvider;
|
|
|
|
private static CosmosDataEncryptionKeyProvider dekProvider;
|
|
|
@ -49,14 +44,12 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
EncryptionTests.encryptor = new TestEncryptor(EncryptionTests.dekProvider);
|
|
|
|
EncryptionTests.encryptor = new TestEncryptor(EncryptionTests.dekProvider);
|
|
|
|
|
|
|
|
|
|
|
|
EncryptionTests.client = EncryptionTests.GetClient();
|
|
|
|
EncryptionTests.client = EncryptionTests.GetClient();
|
|
|
|
EncryptionTests.databaseCore = (DatabaseInlineCore)await EncryptionTests.client.CreateDatabaseAsync(Guid.NewGuid().ToString());
|
|
|
|
EncryptionTests.database = await EncryptionTests.client.CreateDatabaseAsync(Guid.NewGuid().ToString());
|
|
|
|
|
|
|
|
|
|
|
|
EncryptionTests.keyContainer = await EncryptionTests.databaseCore.CreateContainerAsync(Guid.NewGuid().ToString(), "/id", 400);
|
|
|
|
EncryptionTests.keyContainer = await EncryptionTests.database.CreateContainerAsync(Guid.NewGuid().ToString(), "/id", 400);
|
|
|
|
await EncryptionTests.dekProvider.InitializeAsync(EncryptionTests.databaseCore, EncryptionTests.keyContainer.Id);
|
|
|
|
await EncryptionTests.dekProvider.InitializeAsync(EncryptionTests.database, EncryptionTests.keyContainer.Id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EncryptionTests.itemContainer = await EncryptionTests.database.CreateContainerAsync(Guid.NewGuid().ToString(), "/PK", 400);
|
|
|
|
EncryptionTests.itemContainer = await EncryptionTests.databaseCore.CreateContainerAsync(Guid.NewGuid().ToString(), "/PK", 400);
|
|
|
|
|
|
|
|
EncryptionTests.itemContainerCore = (ContainerInlineCore)EncryptionTests.itemContainer;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EncryptionTests.dekProperties = await EncryptionTests.CreateDekAsync(EncryptionTests.dekProvider, EncryptionTests.dekId);
|
|
|
|
EncryptionTests.dekProperties = await EncryptionTests.CreateDekAsync(EncryptionTests.dekProvider, EncryptionTests.dekId);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -64,9 +57,9 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
[ClassCleanup]
|
|
|
|
[ClassCleanup]
|
|
|
|
public static async Task ClassCleanup()
|
|
|
|
public static async Task ClassCleanup()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (EncryptionTests.databaseCore != null)
|
|
|
|
if (EncryptionTests.database != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
using (await EncryptionTests.databaseCore.DeleteStreamAsync()) { }
|
|
|
|
using (await EncryptionTests.database.DeleteStreamAsync()) { }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (EncryptionTests.client != null)
|
|
|
|
if (EncryptionTests.client != null)
|
|
|
@ -93,7 +86,7 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
|
|
|
|
|
|
|
|
// Use different DEK provider to avoid (unintentional) cache impact
|
|
|
|
// Use different DEK provider to avoid (unintentional) cache impact
|
|
|
|
CosmosDataEncryptionKeyProvider dekProvider = new CosmosDataEncryptionKeyProvider(new TestKeyWrapProvider());
|
|
|
|
CosmosDataEncryptionKeyProvider dekProvider = new CosmosDataEncryptionKeyProvider(new TestKeyWrapProvider());
|
|
|
|
await dekProvider.InitializeAsync(EncryptionTests.databaseCore, EncryptionTests.keyContainer.Id);
|
|
|
|
await dekProvider.InitializeAsync(EncryptionTests.database, EncryptionTests.keyContainer.Id);
|
|
|
|
DataEncryptionKeyProperties readProperties = await dekProvider.DataEncryptionKeyContainer.ReadDataEncryptionKeyAsync(dekId);
|
|
|
|
DataEncryptionKeyProperties readProperties = await dekProvider.DataEncryptionKeyContainer.ReadDataEncryptionKeyAsync(dekId);
|
|
|
|
Assert.AreEqual(dekProperties, readProperties);
|
|
|
|
Assert.AreEqual(dekProperties, readProperties);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -101,11 +94,11 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
[TestMethod]
|
|
|
|
[TestMethod]
|
|
|
|
public async Task EncryptionDekReadFeed()
|
|
|
|
public async Task EncryptionDekReadFeed()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Container newKeyContainer = await EncryptionTests.databaseCore.CreateContainerAsync(Guid.NewGuid().ToString(), "/id", 400);
|
|
|
|
Container newKeyContainer = await EncryptionTests.database.CreateContainerAsync(Guid.NewGuid().ToString(), "/id", 400);
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
CosmosDataEncryptionKeyProvider dekProvider = new CosmosDataEncryptionKeyProvider(new TestKeyWrapProvider());
|
|
|
|
CosmosDataEncryptionKeyProvider dekProvider = new CosmosDataEncryptionKeyProvider(new TestKeyWrapProvider());
|
|
|
|
await dekProvider.InitializeAsync(EncryptionTests.databaseCore, newKeyContainer.Id);
|
|
|
|
await dekProvider.InitializeAsync(EncryptionTests.database, newKeyContainer.Id);
|
|
|
|
|
|
|
|
|
|
|
|
string contosoV1 = "Contoso_v001";
|
|
|
|
string contosoV1 = "Contoso_v001";
|
|
|
|
string contosoV2 = "Contoso_v002";
|
|
|
|
string contosoV2 = "Contoso_v002";
|
|
|
@ -160,7 +153,7 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
public async Task EncryptionCreateItemWithoutEncryptionOptions()
|
|
|
|
public async Task EncryptionCreateItemWithoutEncryptionOptions()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
TestDoc testDoc = TestDoc.Create();
|
|
|
|
TestDoc testDoc = TestDoc.Create();
|
|
|
|
ItemResponse<TestDoc> createResponse = await EncryptionTests.itemContainerCore.CreateItemAsync(
|
|
|
|
ItemResponse<TestDoc> createResponse = await EncryptionTests.itemContainer.CreateItemAsync(
|
|
|
|
testDoc,
|
|
|
|
testDoc,
|
|
|
|
new PartitionKey(testDoc.PK));
|
|
|
|
new PartitionKey(testDoc.PK));
|
|
|
|
Assert.AreEqual(HttpStatusCode.Created, createResponse.StatusCode);
|
|
|
|
Assert.AreEqual(HttpStatusCode.Created, createResponse.StatusCode);
|
|
|
@ -170,21 +163,21 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
[TestMethod]
|
|
|
|
[TestMethod]
|
|
|
|
public async Task EncryptionCreateItem()
|
|
|
|
public async Task EncryptionCreateItem()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
TestDoc testDoc = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainerCore, EncryptionTests.dekId, TestDoc.PathsToEncrypt);
|
|
|
|
TestDoc testDoc = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainer, EncryptionTests.dekId, TestDoc.PathsToEncrypt);
|
|
|
|
|
|
|
|
|
|
|
|
await EncryptionTests.VerifyItemByReadAsync(EncryptionTests.itemContainerCore, testDoc);
|
|
|
|
await EncryptionTests.VerifyItemByReadAsync(EncryptionTests.itemContainer, testDoc);
|
|
|
|
|
|
|
|
|
|
|
|
await EncryptionTests.VerifyItemByReadStreamAsync(EncryptionTests.itemContainerCore, testDoc);
|
|
|
|
await EncryptionTests.VerifyItemByReadStreamAsync(EncryptionTests.itemContainer, testDoc);
|
|
|
|
|
|
|
|
|
|
|
|
TestDoc expectedDoc = new TestDoc(testDoc);
|
|
|
|
TestDoc expectedDoc = new TestDoc(testDoc);
|
|
|
|
|
|
|
|
|
|
|
|
await EncryptionTests.ValidateQueryResultsAsync(
|
|
|
|
await EncryptionTests.ValidateQueryResultsAsync(
|
|
|
|
EncryptionTests.itemContainerCore,
|
|
|
|
EncryptionTests.itemContainer,
|
|
|
|
"SELECT * FROM c",
|
|
|
|
"SELECT * FROM c",
|
|
|
|
expectedDoc);
|
|
|
|
expectedDoc);
|
|
|
|
|
|
|
|
|
|
|
|
await EncryptionTests.ValidateQueryResultsAsync(
|
|
|
|
await EncryptionTests.ValidateQueryResultsAsync(
|
|
|
|
EncryptionTests.itemContainerCore,
|
|
|
|
EncryptionTests.itemContainer,
|
|
|
|
string.Format(
|
|
|
|
string.Format(
|
|
|
|
"SELECT * FROM c where c.PK = '{0}' and c.id = '{1}' and c.NonSensitive = '{2}'",
|
|
|
|
"SELECT * FROM c where c.PK = '{0}' and c.id = '{1}' and c.NonSensitive = '{2}'",
|
|
|
|
expectedDoc.PK,
|
|
|
|
expectedDoc.PK,
|
|
|
@ -193,12 +186,12 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
expectedDoc);
|
|
|
|
expectedDoc);
|
|
|
|
|
|
|
|
|
|
|
|
await EncryptionTests.ValidateQueryResultsAsync(
|
|
|
|
await EncryptionTests.ValidateQueryResultsAsync(
|
|
|
|
EncryptionTests.itemContainerCore,
|
|
|
|
EncryptionTests.itemContainer,
|
|
|
|
string.Format("SELECT * FROM c where c.Sensitive = '{0}'", testDoc.Sensitive),
|
|
|
|
string.Format("SELECT * FROM c where c.Sensitive = '{0}'", testDoc.Sensitive),
|
|
|
|
expectedDoc: null);
|
|
|
|
expectedDoc: null);
|
|
|
|
|
|
|
|
|
|
|
|
await EncryptionTests.ValidateQueryResultsAsync(
|
|
|
|
await EncryptionTests.ValidateQueryResultsAsync(
|
|
|
|
EncryptionTests.itemContainerCore,
|
|
|
|
EncryptionTests.itemContainer,
|
|
|
|
queryDefinition: new QueryDefinition(
|
|
|
|
queryDefinition: new QueryDefinition(
|
|
|
|
"select * from c where c.id = @theId and c.PK = @thePK")
|
|
|
|
"select * from c where c.id = @theId and c.PK = @thePK")
|
|
|
|
.WithParameter("@theId", expectedDoc.Id)
|
|
|
|
.WithParameter("@theId", expectedDoc.Id)
|
|
|
@ -208,32 +201,32 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
expectedDoc.Sensitive = null;
|
|
|
|
expectedDoc.Sensitive = null;
|
|
|
|
|
|
|
|
|
|
|
|
await EncryptionTests.ValidateQueryResultsAsync(
|
|
|
|
await EncryptionTests.ValidateQueryResultsAsync(
|
|
|
|
EncryptionTests.itemContainerCore,
|
|
|
|
EncryptionTests.itemContainer,
|
|
|
|
"SELECT c.id, c.PK, c.Sensitive, c.NonSensitive FROM c",
|
|
|
|
"SELECT c.id, c.PK, c.Sensitive, c.NonSensitive FROM c",
|
|
|
|
expectedDoc);
|
|
|
|
expectedDoc);
|
|
|
|
|
|
|
|
|
|
|
|
await EncryptionTests.ValidateQueryResultsAsync(
|
|
|
|
await EncryptionTests.ValidateQueryResultsAsync(
|
|
|
|
EncryptionTests.itemContainerCore,
|
|
|
|
EncryptionTests.itemContainer,
|
|
|
|
"SELECT c.id, c.PK, c.NonSensitive FROM c",
|
|
|
|
"SELECT c.id, c.PK, c.NonSensitive FROM c",
|
|
|
|
expectedDoc);
|
|
|
|
expectedDoc);
|
|
|
|
|
|
|
|
|
|
|
|
await EncryptionTests.ValidateSprocResultsAsync(
|
|
|
|
await EncryptionTests.ValidateSprocResultsAsync(
|
|
|
|
EncryptionTests.itemContainerCore,
|
|
|
|
EncryptionTests.itemContainer,
|
|
|
|
expectedDoc);
|
|
|
|
expectedDoc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
[TestMethod]
|
|
|
|
public async Task EncryptionDecryptQueryResultMultipleDocs()
|
|
|
|
public async Task EncryptionDecryptQueryResultMultipleDocs()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
TestDoc testDoc1 = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainerCore, EncryptionTests.dekId, TestDoc.PathsToEncrypt);
|
|
|
|
TestDoc testDoc1 = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainer, EncryptionTests.dekId, TestDoc.PathsToEncrypt);
|
|
|
|
TestDoc testDoc2 = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainerCore, EncryptionTests.dekId, TestDoc.PathsToEncrypt);
|
|
|
|
TestDoc testDoc2 = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainer, EncryptionTests.dekId, TestDoc.PathsToEncrypt);
|
|
|
|
|
|
|
|
|
|
|
|
string query = $"SELECT * FROM c WHERE c.PK in ('{testDoc1.PK}', '{testDoc2.PK}')";
|
|
|
|
string query = $"SELECT * FROM c WHERE c.PK in ('{testDoc1.PK}', '{testDoc2.PK}')";
|
|
|
|
await EncryptionTests.ValidateQueryResultsMultipleDocumentsAsync(EncryptionTests.itemContainerCore, testDoc1, testDoc2, query);
|
|
|
|
await EncryptionTests.ValidateQueryResultsMultipleDocumentsAsync(EncryptionTests.itemContainer, testDoc1, testDoc2, query);
|
|
|
|
|
|
|
|
|
|
|
|
// ORDER BY query
|
|
|
|
// ORDER BY query
|
|
|
|
query = query + " ORDER BY c._ts";
|
|
|
|
query = query + " ORDER BY c._ts";
|
|
|
|
await EncryptionTests.ValidateQueryResultsMultipleDocumentsAsync(EncryptionTests.itemContainerCore, testDoc1, testDoc2, query);
|
|
|
|
await EncryptionTests.ValidateQueryResultsMultipleDocumentsAsync(EncryptionTests.itemContainer, testDoc1, testDoc2, query);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
[TestMethod]
|
|
|
@ -242,85 +235,36 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
string dekId1 = "mydek1";
|
|
|
|
string dekId1 = "mydek1";
|
|
|
|
await EncryptionTests.CreateDekAsync(EncryptionTests.dekProvider, dekId1);
|
|
|
|
await EncryptionTests.CreateDekAsync(EncryptionTests.dekProvider, dekId1);
|
|
|
|
|
|
|
|
|
|
|
|
TestDoc testDoc1 = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainerCore, EncryptionTests.dekId, TestDoc.PathsToEncrypt);
|
|
|
|
TestDoc testDoc1 = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainer, EncryptionTests.dekId, TestDoc.PathsToEncrypt);
|
|
|
|
TestDoc testDoc2 = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainerCore, dekId1, TestDoc.PathsToEncrypt);
|
|
|
|
TestDoc testDoc2 = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainer, dekId1, TestDoc.PathsToEncrypt);
|
|
|
|
string query = $"SELECT * FROM c WHERE c.PK in ('{testDoc1.PK}', '{testDoc2.PK}')";
|
|
|
|
string query = $"SELECT * FROM c WHERE c.PK in ('{testDoc1.PK}', '{testDoc2.PK}')";
|
|
|
|
|
|
|
|
|
|
|
|
await EncryptionTests.ValidateQueryResultsMultipleDocumentsAsync(EncryptionTests.itemContainerCore, testDoc1, testDoc2, query);
|
|
|
|
await EncryptionTests.ValidateQueryResultsMultipleDocumentsAsync(EncryptionTests.itemContainer, testDoc1, testDoc2, query);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
[TestMethod]
|
|
|
|
public async Task EncryptionDecryptQueryResultMultipleEncryptedProperties()
|
|
|
|
public async Task EncryptionDecryptQueryResultMultipleEncryptedProperties()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
TestDoc testDoc = await EncryptionTests.CreateItemAsync(
|
|
|
|
TestDoc testDoc = await EncryptionTests.CreateItemAsync(
|
|
|
|
EncryptionTests.itemContainerCore,
|
|
|
|
EncryptionTests.itemContainer,
|
|
|
|
EncryptionTests.dekId,
|
|
|
|
EncryptionTests.dekId,
|
|
|
|
new List<string>() { "/Sensitive", "/NonSensitive" });
|
|
|
|
new List<string>() { "/Sensitive", "/NonSensitive" });
|
|
|
|
|
|
|
|
|
|
|
|
TestDoc expectedDoc = new TestDoc(testDoc);
|
|
|
|
TestDoc expectedDoc = new TestDoc(testDoc);
|
|
|
|
|
|
|
|
|
|
|
|
await EncryptionTests.ValidateQueryResultsAsync(
|
|
|
|
await EncryptionTests.ValidateQueryResultsAsync(
|
|
|
|
EncryptionTests.itemContainerCore,
|
|
|
|
EncryptionTests.itemContainer,
|
|
|
|
"SELECT * FROM c",
|
|
|
|
"SELECT * FROM c",
|
|
|
|
expectedDoc);
|
|
|
|
expectedDoc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
|
|
|
public async Task EncryptionDecryptQueryBinaryResponse()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
TestDoc testDoc = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainerCore, EncryptionTests.dekId, TestDoc.PathsToEncrypt);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CosmosSerializationFormatOptions options = new CosmosSerializationFormatOptions(
|
|
|
|
|
|
|
|
Documents.ContentSerializationFormat.CosmosBinary.ToString(),
|
|
|
|
|
|
|
|
(content) => JsonNavigator.Create(content),
|
|
|
|
|
|
|
|
() => JsonWriter.Create(JsonSerializationFormat.Binary));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QueryRequestOptions requestOptions = new QueryRequestOptions()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
CosmosSerializationFormatOptions = options
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TestDoc expectedDoc = new TestDoc(testDoc);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string query = "SELECT * FROM c";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FeedIterator feedIterator = EncryptionTests.itemContainerCore.GetItemQueryStreamIterator(
|
|
|
|
|
|
|
|
query,
|
|
|
|
|
|
|
|
requestOptions: requestOptions);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (feedIterator.HasMoreResults)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ResponseMessage response = await feedIterator.ReadNextAsync();
|
|
|
|
|
|
|
|
Assert.IsTrue(response.IsSuccessStatusCode);
|
|
|
|
|
|
|
|
Assert.IsNull(response.ErrorMessage);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Copy the stream and check that the first byte is the correct value
|
|
|
|
|
|
|
|
MemoryStream memoryStream = new MemoryStream();
|
|
|
|
|
|
|
|
response.Content.CopyTo(memoryStream);
|
|
|
|
|
|
|
|
byte[] content = memoryStream.ToArray();
|
|
|
|
|
|
|
|
response.Content.Position = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Examine the first buffer byte to determine the serialization format
|
|
|
|
|
|
|
|
byte firstByte = content[0];
|
|
|
|
|
|
|
|
Assert.AreEqual(128, firstByte);
|
|
|
|
|
|
|
|
Assert.AreEqual(JsonSerializationFormat.Binary, (JsonSerializationFormat)firstByte);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IJsonReader reader = JsonReader.Create(content);
|
|
|
|
|
|
|
|
IJsonWriter textWriter = JsonWriter.Create(JsonSerializationFormat.Text);
|
|
|
|
|
|
|
|
textWriter.WriteAll(reader);
|
|
|
|
|
|
|
|
string json = Encoding.UTF8.GetString(textWriter.GetResult().ToArray());
|
|
|
|
|
|
|
|
Assert.IsNotNull(json);
|
|
|
|
|
|
|
|
Assert.IsTrue(json.Contains(testDoc.Sensitive));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
[TestMethod]
|
|
|
|
public async Task EncryptionDecryptQueryValueResponse()
|
|
|
|
public async Task EncryptionDecryptQueryValueResponse()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
TestDoc testDoc = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainerCore, EncryptionTests.dekId, TestDoc.PathsToEncrypt);
|
|
|
|
TestDoc testDoc = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainer, EncryptionTests.dekId, TestDoc.PathsToEncrypt);
|
|
|
|
string query = "SELECT VALUE COUNT(1) FROM c";
|
|
|
|
string query = "SELECT VALUE COUNT(1) FROM c";
|
|
|
|
|
|
|
|
|
|
|
|
await EncryptionTests.ValidateQueryResponseAsync(EncryptionTests.itemContainerCore, query);
|
|
|
|
await EncryptionTests.ValidateQueryResponseAsync(EncryptionTests.itemContainer, query);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
[TestMethod]
|
|
|
@ -328,63 +272,63 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string partitionKey = Guid.NewGuid().ToString();
|
|
|
|
string partitionKey = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
|
|
TestDoc testDoc1 = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainerCore, EncryptionTests.dekId, TestDoc.PathsToEncrypt, partitionKey);
|
|
|
|
TestDoc testDoc1 = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainer, EncryptionTests.dekId, TestDoc.PathsToEncrypt, partitionKey);
|
|
|
|
TestDoc testDoc2 = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainerCore, EncryptionTests.dekId, TestDoc.PathsToEncrypt, partitionKey);
|
|
|
|
TestDoc testDoc2 = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainer, EncryptionTests.dekId, TestDoc.PathsToEncrypt, partitionKey);
|
|
|
|
|
|
|
|
|
|
|
|
string query = $"SELECT COUNT(c.Id), c.PK " +
|
|
|
|
string query = $"SELECT COUNT(c.Id), c.PK " +
|
|
|
|
$"FROM c WHERE c.PK = '{partitionKey}' " +
|
|
|
|
$"FROM c WHERE c.PK = '{partitionKey}' " +
|
|
|
|
$"GROUP BY c.PK ";
|
|
|
|
$"GROUP BY c.PK ";
|
|
|
|
|
|
|
|
|
|
|
|
await EncryptionTests.ValidateQueryResponseAsync(EncryptionTests.itemContainerCore, query);
|
|
|
|
await EncryptionTests.ValidateQueryResponseAsync(EncryptionTests.itemContainer, query);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
[TestMethod]
|
|
|
|
public async Task EncryptionRudItem()
|
|
|
|
public async Task EncryptionRudItem()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
TestDoc testDoc = await EncryptionTests.UpsertItemAsync(
|
|
|
|
TestDoc testDoc = await EncryptionTests.UpsertItemAsync(
|
|
|
|
EncryptionTests.itemContainerCore,
|
|
|
|
EncryptionTests.itemContainer,
|
|
|
|
TestDoc.Create(),
|
|
|
|
TestDoc.Create(),
|
|
|
|
EncryptionTests.dekId,
|
|
|
|
EncryptionTests.dekId,
|
|
|
|
TestDoc.PathsToEncrypt,
|
|
|
|
TestDoc.PathsToEncrypt,
|
|
|
|
HttpStatusCode.Created);
|
|
|
|
HttpStatusCode.Created);
|
|
|
|
|
|
|
|
|
|
|
|
await EncryptionTests.VerifyItemByReadAsync(EncryptionTests.itemContainerCore, testDoc);
|
|
|
|
await EncryptionTests.VerifyItemByReadAsync(EncryptionTests.itemContainer, testDoc);
|
|
|
|
|
|
|
|
|
|
|
|
testDoc.NonSensitive = Guid.NewGuid().ToString();
|
|
|
|
testDoc.NonSensitive = Guid.NewGuid().ToString();
|
|
|
|
testDoc.Sensitive = Guid.NewGuid().ToString();
|
|
|
|
testDoc.Sensitive = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
|
|
ItemResponse<TestDoc> upsertResponse = await EncryptionTests.UpsertItemAsync(
|
|
|
|
ItemResponse<TestDoc> upsertResponse = await EncryptionTests.UpsertItemAsync(
|
|
|
|
EncryptionTests.itemContainerCore,
|
|
|
|
EncryptionTests.itemContainer,
|
|
|
|
testDoc,
|
|
|
|
testDoc,
|
|
|
|
EncryptionTests.dekId,
|
|
|
|
EncryptionTests.dekId,
|
|
|
|
TestDoc.PathsToEncrypt,
|
|
|
|
TestDoc.PathsToEncrypt,
|
|
|
|
HttpStatusCode.OK);
|
|
|
|
HttpStatusCode.OK);
|
|
|
|
TestDoc updatedDoc = upsertResponse.Resource;
|
|
|
|
TestDoc updatedDoc = upsertResponse.Resource;
|
|
|
|
|
|
|
|
|
|
|
|
await EncryptionTests.VerifyItemByReadAsync(EncryptionTests.itemContainerCore, updatedDoc);
|
|
|
|
await EncryptionTests.VerifyItemByReadAsync(EncryptionTests.itemContainer, updatedDoc);
|
|
|
|
|
|
|
|
|
|
|
|
updatedDoc.NonSensitive = Guid.NewGuid().ToString();
|
|
|
|
updatedDoc.NonSensitive = Guid.NewGuid().ToString();
|
|
|
|
updatedDoc.Sensitive = Guid.NewGuid().ToString();
|
|
|
|
updatedDoc.Sensitive = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
|
|
TestDoc replacedDoc = await EncryptionTests.ReplaceItemAsync(
|
|
|
|
TestDoc replacedDoc = await EncryptionTests.ReplaceItemAsync(
|
|
|
|
EncryptionTests.itemContainerCore,
|
|
|
|
EncryptionTests.itemContainer,
|
|
|
|
updatedDoc,
|
|
|
|
updatedDoc,
|
|
|
|
EncryptionTests.dekId,
|
|
|
|
EncryptionTests.dekId,
|
|
|
|
TestDoc.PathsToEncrypt,
|
|
|
|
TestDoc.PathsToEncrypt,
|
|
|
|
upsertResponse.ETag);
|
|
|
|
upsertResponse.ETag);
|
|
|
|
|
|
|
|
|
|
|
|
await EncryptionTests.VerifyItemByReadAsync(EncryptionTests.itemContainerCore, replacedDoc);
|
|
|
|
await EncryptionTests.VerifyItemByReadAsync(EncryptionTests.itemContainer, replacedDoc);
|
|
|
|
|
|
|
|
|
|
|
|
await EncryptionTests.DeleteItemAsync(EncryptionTests.itemContainerCore, replacedDoc);
|
|
|
|
await EncryptionTests.DeleteItemAsync(EncryptionTests.itemContainer, replacedDoc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
[TestMethod]
|
|
|
|
public async Task EncryptionResourceTokenAuthRestricted()
|
|
|
|
public async Task EncryptionResourceTokenAuthRestricted()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
TestDoc testDoc = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainerCore, EncryptionTests.dekId, TestDoc.PathsToEncrypt);
|
|
|
|
TestDoc testDoc = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainer, EncryptionTests.dekId, TestDoc.PathsToEncrypt);
|
|
|
|
|
|
|
|
|
|
|
|
User restrictedUser = EncryptionTests.databaseCore.GetUser(Guid.NewGuid().ToString());
|
|
|
|
User restrictedUser = EncryptionTests.database.GetUser(Guid.NewGuid().ToString());
|
|
|
|
await EncryptionTests.databaseCore.CreateUserAsync(restrictedUser.Id);
|
|
|
|
await EncryptionTests.database.CreateUserAsync(restrictedUser.Id);
|
|
|
|
|
|
|
|
|
|
|
|
PermissionProperties restrictedUserPermission = await restrictedUser.CreatePermissionAsync(
|
|
|
|
PermissionProperties restrictedUserPermission = await restrictedUser.CreatePermissionAsync(
|
|
|
|
new PermissionProperties(Guid.NewGuid().ToString(), PermissionMode.All, EncryptionTests.itemContainer));
|
|
|
|
new PermissionProperties(Guid.NewGuid().ToString(), PermissionMode.All, EncryptionTests.itemContainer));
|
|
|
@ -392,12 +336,12 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
CosmosDataEncryptionKeyProvider dekProvider = new CosmosDataEncryptionKeyProvider(new TestKeyWrapProvider());
|
|
|
|
CosmosDataEncryptionKeyProvider dekProvider = new CosmosDataEncryptionKeyProvider(new TestKeyWrapProvider());
|
|
|
|
TestEncryptor encryptor = new TestEncryptor(dekProvider);
|
|
|
|
TestEncryptor encryptor = new TestEncryptor(dekProvider);
|
|
|
|
|
|
|
|
|
|
|
|
(string endpoint, string _) = TestCommon.GetAccountInfo();
|
|
|
|
CosmosClient clientForRestrictedUser = TestCommon.CreateCosmosClient(
|
|
|
|
CosmosClient clientForRestrictedUser = new CosmosClientBuilder(endpoint, restrictedUserPermission.Token)
|
|
|
|
restrictedUserPermission.Token,
|
|
|
|
.WithEncryptor(encryptor)
|
|
|
|
builder => builder
|
|
|
|
.Build();
|
|
|
|
.WithEncryptor(encryptor));
|
|
|
|
|
|
|
|
|
|
|
|
Database databaseForRestrictedUser = clientForRestrictedUser.GetDatabase(EncryptionTests.databaseCore.Id);
|
|
|
|
Database databaseForRestrictedUser = clientForRestrictedUser.GetDatabase(EncryptionTests.database.Id);
|
|
|
|
Container containerForRestrictedUser = databaseForRestrictedUser.GetContainer(EncryptionTests.itemContainer.Id);
|
|
|
|
Container containerForRestrictedUser = databaseForRestrictedUser.GetContainer(EncryptionTests.itemContainer.Id);
|
|
|
|
|
|
|
|
|
|
|
|
await EncryptionTests.PerformForbiddenOperationAsync(() =>
|
|
|
|
await EncryptionTests.PerformForbiddenOperationAsync(() =>
|
|
|
@ -416,20 +360,20 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
[TestMethod]
|
|
|
|
[TestMethod]
|
|
|
|
public async Task EncryptionResourceTokenAuthAllowed()
|
|
|
|
public async Task EncryptionResourceTokenAuthAllowed()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
User keyManagerUser = EncryptionTests.databaseCore.GetUser(Guid.NewGuid().ToString());
|
|
|
|
User keyManagerUser = EncryptionTests.database.GetUser(Guid.NewGuid().ToString());
|
|
|
|
await EncryptionTests.databaseCore.CreateUserAsync(keyManagerUser.Id);
|
|
|
|
await EncryptionTests.database.CreateUserAsync(keyManagerUser.Id);
|
|
|
|
|
|
|
|
|
|
|
|
PermissionProperties keyManagerUserPermission = await keyManagerUser.CreatePermissionAsync(
|
|
|
|
PermissionProperties keyManagerUserPermission = await keyManagerUser.CreatePermissionAsync(
|
|
|
|
new PermissionProperties(Guid.NewGuid().ToString(), PermissionMode.All, EncryptionTests.keyContainer));
|
|
|
|
new PermissionProperties(Guid.NewGuid().ToString(), PermissionMode.All, EncryptionTests.keyContainer));
|
|
|
|
|
|
|
|
|
|
|
|
CosmosDataEncryptionKeyProvider dekProvider = new CosmosDataEncryptionKeyProvider(new TestKeyWrapProvider());
|
|
|
|
CosmosDataEncryptionKeyProvider dekProvider = new CosmosDataEncryptionKeyProvider(new TestKeyWrapProvider());
|
|
|
|
TestEncryptor encryptor = new TestEncryptor(dekProvider);
|
|
|
|
TestEncryptor encryptor = new TestEncryptor(dekProvider);
|
|
|
|
(string endpoint, string _) = TestCommon.GetAccountInfo();
|
|
|
|
CosmosClient clientForKeyManagerUser = TestCommon.CreateCosmosClient(
|
|
|
|
CosmosClient clientForKeyManagerUser = new CosmosClientBuilder(endpoint, keyManagerUserPermission.Token)
|
|
|
|
keyManagerUserPermission.Token,
|
|
|
|
.WithEncryptor(encryptor)
|
|
|
|
builder => builder
|
|
|
|
.Build();
|
|
|
|
.WithEncryptor(encryptor));
|
|
|
|
|
|
|
|
|
|
|
|
Database databaseForKeyManagerUser = clientForKeyManagerUser.GetDatabase(EncryptionTests.databaseCore.Id);
|
|
|
|
Database databaseForKeyManagerUser = clientForKeyManagerUser.GetDatabase(EncryptionTests.database.Id);
|
|
|
|
|
|
|
|
|
|
|
|
await dekProvider.InitializeAsync(databaseForKeyManagerUser, EncryptionTests.keyContainer.Id);
|
|
|
|
await dekProvider.InitializeAsync(databaseForKeyManagerUser, EncryptionTests.keyContainer.Id);
|
|
|
|
|
|
|
|
|
|
|
@ -444,7 +388,7 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainerCore, EncryptionTests.dekId, new List<string>() { "/id" });
|
|
|
|
await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainer, EncryptionTests.dekId, new List<string>() { "/id" });
|
|
|
|
Assert.Fail("Expected item creation with id specified to be encrypted to fail.");
|
|
|
|
Assert.Fail("Expected item creation with id specified to be encrypted to fail.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (CosmosException ex) when (ex.StatusCode == HttpStatusCode.BadRequest)
|
|
|
|
catch (CosmosException ex) when (ex.StatusCode == HttpStatusCode.BadRequest)
|
|
|
@ -453,7 +397,7 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainerCore, EncryptionTests.dekId, new List<string>() { "/PK" });
|
|
|
|
await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainer, EncryptionTests.dekId, new List<string>() { "/PK" });
|
|
|
|
Assert.Fail("Expected item creation with PK specified to be encrypted to fail.");
|
|
|
|
Assert.Fail("Expected item creation with PK specified to be encrypted to fail.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (CosmosException ex) when (ex.StatusCode == HttpStatusCode.BadRequest)
|
|
|
|
catch (CosmosException ex) when (ex.StatusCode == HttpStatusCode.BadRequest)
|
|
|
@ -464,31 +408,31 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
[TestMethod]
|
|
|
|
[TestMethod]
|
|
|
|
public async Task EncryptionBulkCrud()
|
|
|
|
public async Task EncryptionBulkCrud()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
TestDoc docToReplace = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainerCore, EncryptionTests.dekId, TestDoc.PathsToEncrypt);
|
|
|
|
TestDoc docToReplace = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainer, EncryptionTests.dekId, TestDoc.PathsToEncrypt);
|
|
|
|
docToReplace.NonSensitive = Guid.NewGuid().ToString();
|
|
|
|
docToReplace.NonSensitive = Guid.NewGuid().ToString();
|
|
|
|
docToReplace.Sensitive = Guid.NewGuid().ToString();
|
|
|
|
docToReplace.Sensitive = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
|
|
TestDoc docToUpsert = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainerCore, EncryptionTests.dekId, TestDoc.PathsToEncrypt);
|
|
|
|
TestDoc docToUpsert = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainer, EncryptionTests.dekId, TestDoc.PathsToEncrypt);
|
|
|
|
docToUpsert.NonSensitive = Guid.NewGuid().ToString();
|
|
|
|
docToUpsert.NonSensitive = Guid.NewGuid().ToString();
|
|
|
|
docToUpsert.Sensitive = Guid.NewGuid().ToString();
|
|
|
|
docToUpsert.Sensitive = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
|
|
TestDoc docToDelete = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainerCore, EncryptionTests.dekId, TestDoc.PathsToEncrypt);
|
|
|
|
TestDoc docToDelete = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainer, EncryptionTests.dekId, TestDoc.PathsToEncrypt);
|
|
|
|
|
|
|
|
|
|
|
|
(string endpoint, string authKey) = TestCommon.GetAccountInfo();
|
|
|
|
CosmosClient clientWithBulk = TestCommon.CreateCosmosClient(builder => builder
|
|
|
|
CosmosClient clientWithBulk = new CosmosClientBuilder(endpoint, authKey)
|
|
|
|
.WithEncryptor(EncryptionTests.encryptor)
|
|
|
|
.WithEncryptor(EncryptionTests.encryptor)
|
|
|
|
.WithBulkExecution(true));
|
|
|
|
.WithBulkExecution(true)
|
|
|
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DatabaseInternal databaseWithBulk = (DatabaseInlineCore)clientWithBulk.GetDatabase(EncryptionTests.databaseCore.Id);
|
|
|
|
Database databaseWithBulk = clientWithBulk.GetDatabase(EncryptionTests.database.Id);
|
|
|
|
ContainerInternal containerWithBulk = (ContainerInlineCore)databaseWithBulk.GetContainer(EncryptionTests.itemContainer.Id);
|
|
|
|
Container containerWithBulk = databaseWithBulk.GetContainer(EncryptionTests.itemContainer.Id);
|
|
|
|
|
|
|
|
|
|
|
|
List<Task> tasks = new List<Task>();
|
|
|
|
List<Task> tasks = new List<Task>
|
|
|
|
tasks.Add(EncryptionTests.CreateItemAsync(containerWithBulk, EncryptionTests.dekId, TestDoc.PathsToEncrypt));
|
|
|
|
{
|
|
|
|
tasks.Add(EncryptionTests.UpsertItemAsync(containerWithBulk, TestDoc.Create(), EncryptionTests.dekId, TestDoc.PathsToEncrypt, HttpStatusCode.Created));
|
|
|
|
EncryptionTests.CreateItemAsync(containerWithBulk, EncryptionTests.dekId, TestDoc.PathsToEncrypt),
|
|
|
|
tasks.Add(EncryptionTests.ReplaceItemAsync(containerWithBulk, docToReplace, EncryptionTests.dekId, TestDoc.PathsToEncrypt));
|
|
|
|
EncryptionTests.UpsertItemAsync(containerWithBulk, TestDoc.Create(), EncryptionTests.dekId, TestDoc.PathsToEncrypt, HttpStatusCode.Created),
|
|
|
|
tasks.Add(EncryptionTests.UpsertItemAsync(containerWithBulk, docToUpsert, EncryptionTests.dekId, TestDoc.PathsToEncrypt, HttpStatusCode.OK));
|
|
|
|
EncryptionTests.ReplaceItemAsync(containerWithBulk, docToReplace, EncryptionTests.dekId, TestDoc.PathsToEncrypt),
|
|
|
|
tasks.Add(EncryptionTests.DeleteItemAsync(containerWithBulk, docToDelete));
|
|
|
|
EncryptionTests.UpsertItemAsync(containerWithBulk, docToUpsert, EncryptionTests.dekId, TestDoc.PathsToEncrypt, HttpStatusCode.OK),
|
|
|
|
|
|
|
|
EncryptionTests.DeleteItemAsync(containerWithBulk, docToDelete)
|
|
|
|
|
|
|
|
};
|
|
|
|
await Task.WhenAll(tasks);
|
|
|
|
await Task.WhenAll(tasks);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -504,51 +448,51 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
TestDoc doc2ToCreate = TestDoc.Create(partitionKey);
|
|
|
|
TestDoc doc2ToCreate = TestDoc.Create(partitionKey);
|
|
|
|
TestDoc doc3ToCreate = TestDoc.Create(partitionKey);
|
|
|
|
TestDoc doc3ToCreate = TestDoc.Create(partitionKey);
|
|
|
|
|
|
|
|
|
|
|
|
ItemResponse<TestDoc> doc1ToReplaceCreateResponse = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainerCore, dek1, TestDoc.PathsToEncrypt, partitionKey);
|
|
|
|
ItemResponse<TestDoc> doc1ToReplaceCreateResponse = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainer, dek1, TestDoc.PathsToEncrypt, partitionKey);
|
|
|
|
TestDoc doc1ToReplace = doc1ToReplaceCreateResponse.Resource;
|
|
|
|
TestDoc doc1ToReplace = doc1ToReplaceCreateResponse.Resource;
|
|
|
|
doc1ToReplace.NonSensitive = Guid.NewGuid().ToString();
|
|
|
|
doc1ToReplace.NonSensitive = Guid.NewGuid().ToString();
|
|
|
|
doc1ToReplace.Sensitive = Guid.NewGuid().ToString();
|
|
|
|
doc1ToReplace.Sensitive = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
|
|
TestDoc doc2ToReplace = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainerCore, dek2, TestDoc.PathsToEncrypt, partitionKey);
|
|
|
|
TestDoc doc2ToReplace = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainer, dek2, TestDoc.PathsToEncrypt, partitionKey);
|
|
|
|
doc2ToReplace.NonSensitive = Guid.NewGuid().ToString();
|
|
|
|
doc2ToReplace.NonSensitive = Guid.NewGuid().ToString();
|
|
|
|
doc2ToReplace.Sensitive = Guid.NewGuid().ToString();
|
|
|
|
doc2ToReplace.Sensitive = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
|
|
TestDoc doc1ToUpsert = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainerCore, dek2, TestDoc.PathsToEncrypt, partitionKey);
|
|
|
|
TestDoc doc1ToUpsert = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainer, dek2, TestDoc.PathsToEncrypt, partitionKey);
|
|
|
|
doc1ToUpsert.NonSensitive = Guid.NewGuid().ToString();
|
|
|
|
doc1ToUpsert.NonSensitive = Guid.NewGuid().ToString();
|
|
|
|
doc1ToUpsert.Sensitive = Guid.NewGuid().ToString();
|
|
|
|
doc1ToUpsert.Sensitive = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
|
|
TestDoc doc2ToUpsert = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainerCore, dek1, TestDoc.PathsToEncrypt, partitionKey);
|
|
|
|
TestDoc doc2ToUpsert = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainer, dek1, TestDoc.PathsToEncrypt, partitionKey);
|
|
|
|
doc2ToUpsert.NonSensitive = Guid.NewGuid().ToString();
|
|
|
|
doc2ToUpsert.NonSensitive = Guid.NewGuid().ToString();
|
|
|
|
doc2ToUpsert.Sensitive = Guid.NewGuid().ToString();
|
|
|
|
doc2ToUpsert.Sensitive = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
|
|
TestDoc docToDelete = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainerCore, dek1, TestDoc.PathsToEncrypt, partitionKey);
|
|
|
|
TestDoc docToDelete = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainer, dek1, TestDoc.PathsToEncrypt, partitionKey);
|
|
|
|
|
|
|
|
|
|
|
|
TransactionalBatchResponse batchResponse = await EncryptionTests.itemContainer.CreateTransactionalBatch(new Cosmos.PartitionKey(partitionKey))
|
|
|
|
TransactionalBatchResponse batchResponse = await EncryptionTests.itemContainer.CreateTransactionalBatch(new Cosmos.PartitionKey(partitionKey))
|
|
|
|
.CreateItem(doc1ToCreate, EncryptionTests.GetBatchItemRequestOptions(EncryptionTests.itemContainerCore, dek1, TestDoc.PathsToEncrypt))
|
|
|
|
.CreateItem(doc1ToCreate, EncryptionTests.GetBatchItemRequestOptions(EncryptionTests.itemContainer, dek1, TestDoc.PathsToEncrypt))
|
|
|
|
.CreateItemStream(doc2ToCreate.ToStream(), EncryptionTests.GetBatchItemRequestOptions(EncryptionTests.itemContainerCore, dek2, TestDoc.PathsToEncrypt))
|
|
|
|
.CreateItemStream(doc2ToCreate.ToStream(), EncryptionTests.GetBatchItemRequestOptions(EncryptionTests.itemContainer, dek2, TestDoc.PathsToEncrypt))
|
|
|
|
.ReplaceItem(doc1ToReplace.Id, doc1ToReplace, EncryptionTests.GetBatchItemRequestOptions(EncryptionTests.itemContainerCore, dek2, TestDoc.PathsToEncrypt, doc1ToReplaceCreateResponse.ETag))
|
|
|
|
.ReplaceItem(doc1ToReplace.Id, doc1ToReplace, EncryptionTests.GetBatchItemRequestOptions(EncryptionTests.itemContainer, dek2, TestDoc.PathsToEncrypt, doc1ToReplaceCreateResponse.ETag))
|
|
|
|
.CreateItem(doc3ToCreate)
|
|
|
|
.CreateItem(doc3ToCreate)
|
|
|
|
.ReplaceItemStream(doc2ToReplace.Id, doc2ToReplace.ToStream(), EncryptionTests.GetBatchItemRequestOptions(EncryptionTests.itemContainerCore, dek2, TestDoc.PathsToEncrypt))
|
|
|
|
.ReplaceItemStream(doc2ToReplace.Id, doc2ToReplace.ToStream(), EncryptionTests.GetBatchItemRequestOptions(EncryptionTests.itemContainer, dek2, TestDoc.PathsToEncrypt))
|
|
|
|
.UpsertItem(doc1ToUpsert, EncryptionTests.GetBatchItemRequestOptions(EncryptionTests.itemContainerCore, dek1, TestDoc.PathsToEncrypt))
|
|
|
|
.UpsertItem(doc1ToUpsert, EncryptionTests.GetBatchItemRequestOptions(EncryptionTests.itemContainer, dek1, TestDoc.PathsToEncrypt))
|
|
|
|
.DeleteItem(docToDelete.Id)
|
|
|
|
.DeleteItem(docToDelete.Id)
|
|
|
|
.UpsertItemStream(doc2ToUpsert.ToStream(), EncryptionTests.GetBatchItemRequestOptions(EncryptionTests.itemContainerCore, dek2, TestDoc.PathsToEncrypt))
|
|
|
|
.UpsertItemStream(doc2ToUpsert.ToStream(), EncryptionTests.GetBatchItemRequestOptions(EncryptionTests.itemContainer, dek2, TestDoc.PathsToEncrypt))
|
|
|
|
.ExecuteAsync();
|
|
|
|
.ExecuteAsync();
|
|
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(HttpStatusCode.OK, batchResponse.StatusCode);
|
|
|
|
Assert.AreEqual(HttpStatusCode.OK, batchResponse.StatusCode);
|
|
|
|
|
|
|
|
|
|
|
|
await EncryptionTests.VerifyItemByReadAsync(EncryptionTests.itemContainerCore, doc1ToCreate);
|
|
|
|
await EncryptionTests.VerifyItemByReadAsync(EncryptionTests.itemContainer, doc1ToCreate);
|
|
|
|
await EncryptionTests.VerifyItemByReadAsync(EncryptionTests.itemContainerCore, doc2ToCreate);
|
|
|
|
await EncryptionTests.VerifyItemByReadAsync(EncryptionTests.itemContainer, doc2ToCreate);
|
|
|
|
await EncryptionTests.VerifyItemByReadAsync(EncryptionTests.itemContainerCore, doc3ToCreate);
|
|
|
|
await EncryptionTests.VerifyItemByReadAsync(EncryptionTests.itemContainer, doc3ToCreate);
|
|
|
|
await EncryptionTests.VerifyItemByReadAsync(EncryptionTests.itemContainerCore, doc1ToReplace);
|
|
|
|
await EncryptionTests.VerifyItemByReadAsync(EncryptionTests.itemContainer, doc1ToReplace);
|
|
|
|
await EncryptionTests.VerifyItemByReadAsync(EncryptionTests.itemContainerCore, doc2ToReplace);
|
|
|
|
await EncryptionTests.VerifyItemByReadAsync(EncryptionTests.itemContainer, doc2ToReplace);
|
|
|
|
await EncryptionTests.VerifyItemByReadAsync(EncryptionTests.itemContainerCore, doc1ToUpsert);
|
|
|
|
await EncryptionTests.VerifyItemByReadAsync(EncryptionTests.itemContainer, doc1ToUpsert);
|
|
|
|
await EncryptionTests.VerifyItemByReadAsync(EncryptionTests.itemContainerCore, doc2ToUpsert);
|
|
|
|
await EncryptionTests.VerifyItemByReadAsync(EncryptionTests.itemContainer, doc2ToUpsert);
|
|
|
|
|
|
|
|
|
|
|
|
ResponseMessage readResponseMessage = await EncryptionTests.itemContainer.ReadItemStreamAsync(docToDelete.Id, new PartitionKey(docToDelete.PK));
|
|
|
|
ResponseMessage readResponseMessage = await EncryptionTests.itemContainer.ReadItemStreamAsync(docToDelete.Id, new PartitionKey(docToDelete.PK));
|
|
|
|
Assert.AreEqual(HttpStatusCode.NotFound, readResponseMessage.StatusCode);
|
|
|
|
Assert.AreEqual(HttpStatusCode.NotFound, readResponseMessage.StatusCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static async Task ValidateSprocResultsAsync(ContainerInternal containerCore, TestDoc expectedDoc)
|
|
|
|
private static async Task ValidateSprocResultsAsync(Container container, TestDoc expectedDoc)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string sprocId = Guid.NewGuid().ToString();
|
|
|
|
string sprocId = Guid.NewGuid().ToString();
|
|
|
|
string sprocBody = @"function(docId) {
|
|
|
|
string sprocBody = @"function(docId) {
|
|
|
@ -564,10 +508,10 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
}";
|
|
|
|
}";
|
|
|
|
|
|
|
|
|
|
|
|
StoredProcedureResponse storedProcedureResponse =
|
|
|
|
StoredProcedureResponse storedProcedureResponse =
|
|
|
|
await containerCore.Scripts.CreateStoredProcedureAsync(new StoredProcedureProperties(sprocId, sprocBody));
|
|
|
|
await container.Scripts.CreateStoredProcedureAsync(new StoredProcedureProperties(sprocId, sprocBody));
|
|
|
|
Assert.AreEqual(HttpStatusCode.Created, storedProcedureResponse.StatusCode);
|
|
|
|
Assert.AreEqual(HttpStatusCode.Created, storedProcedureResponse.StatusCode);
|
|
|
|
|
|
|
|
|
|
|
|
StoredProcedureExecuteResponse<TestDoc> sprocResponse = await containerCore.Scripts.ExecuteStoredProcedureAsync<TestDoc>(
|
|
|
|
StoredProcedureExecuteResponse<TestDoc> sprocResponse = await container.Scripts.ExecuteStoredProcedureAsync<TestDoc>(
|
|
|
|
sprocId,
|
|
|
|
sprocId,
|
|
|
|
new PartitionKey(expectedDoc.PK),
|
|
|
|
new PartitionKey(expectedDoc.PK),
|
|
|
|
parameters: new dynamic[] { expectedDoc.Id });
|
|
|
|
parameters: new dynamic[] { expectedDoc.Id });
|
|
|
@ -577,7 +521,7 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
|
|
|
|
|
|
|
|
// One of query or queryDefinition is to be passed in non-null
|
|
|
|
// One of query or queryDefinition is to be passed in non-null
|
|
|
|
private static async Task ValidateQueryResultsAsync(
|
|
|
|
private static async Task ValidateQueryResultsAsync(
|
|
|
|
ContainerInternal containerCore,
|
|
|
|
Container container,
|
|
|
|
string query = null,
|
|
|
|
string query = null,
|
|
|
|
TestDoc expectedDoc = null,
|
|
|
|
TestDoc expectedDoc = null,
|
|
|
|
QueryDefinition queryDefinition = null)
|
|
|
|
QueryDefinition queryDefinition = null)
|
|
|
@ -586,11 +530,11 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
FeedIterator<TestDoc> queryResponseIterator;
|
|
|
|
FeedIterator<TestDoc> queryResponseIterator;
|
|
|
|
if (query != null)
|
|
|
|
if (query != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
queryResponseIterator = containerCore.GetItemQueryIterator<TestDoc>(query, requestOptions: requestOptions);
|
|
|
|
queryResponseIterator = container.GetItemQueryIterator<TestDoc>(query, requestOptions: requestOptions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
queryResponseIterator = containerCore.GetItemQueryIterator<TestDoc>(queryDefinition, requestOptions: requestOptions);
|
|
|
|
queryResponseIterator = container.GetItemQueryIterator<TestDoc>(queryDefinition, requestOptions: requestOptions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FeedResponse<TestDoc> readDocs = await queryResponseIterator.ReadNextAsync();
|
|
|
|
FeedResponse<TestDoc> readDocs = await queryResponseIterator.ReadNextAsync();
|
|
|
@ -609,12 +553,12 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static async Task ValidateQueryResultsMultipleDocumentsAsync(
|
|
|
|
private static async Task ValidateQueryResultsMultipleDocumentsAsync(
|
|
|
|
ContainerInternal containerCore,
|
|
|
|
Container container,
|
|
|
|
TestDoc testDoc1,
|
|
|
|
TestDoc testDoc1,
|
|
|
|
TestDoc testDoc2,
|
|
|
|
TestDoc testDoc2,
|
|
|
|
string query)
|
|
|
|
string query)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
FeedIterator<TestDoc> queryResponseIterator = containerCore.GetItemQueryIterator<TestDoc>(query);
|
|
|
|
FeedIterator<TestDoc> queryResponseIterator = container.GetItemQueryIterator<TestDoc>(query);
|
|
|
|
FeedResponse<TestDoc> readDocs = await queryResponseIterator.ReadNextAsync();
|
|
|
|
FeedResponse<TestDoc> readDocs = await queryResponseIterator.ReadNextAsync();
|
|
|
|
Assert.AreEqual(null, readDocs.ContinuationToken);
|
|
|
|
Assert.AreEqual(null, readDocs.ContinuationToken);
|
|
|
|
Assert.AreEqual(2, readDocs.Count);
|
|
|
|
Assert.AreEqual(2, readDocs.Count);
|
|
|
@ -624,9 +568,9 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static async Task ValidateQueryResponseAsync(ContainerInternal containerCore, string query)
|
|
|
|
private static async Task ValidateQueryResponseAsync(Container container, string query)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
FeedIterator feedIterator = containerCore.GetItemQueryStreamIterator(query);
|
|
|
|
FeedIterator feedIterator = container.GetItemQueryStreamIterator(query);
|
|
|
|
while (feedIterator.HasMoreResults)
|
|
|
|
while (feedIterator.HasMoreResults)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ResponseMessage response = await feedIterator.ReadNextAsync();
|
|
|
|
ResponseMessage response = await feedIterator.ReadNextAsync();
|
|
|
@ -637,10 +581,8 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
|
|
|
|
|
|
|
|
private static CosmosClient GetClient()
|
|
|
|
private static CosmosClient GetClient()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
(string endpoint, string authKey) = TestCommon.GetAccountInfo();
|
|
|
|
return TestCommon.CreateCosmosClient(
|
|
|
|
return new CosmosClientBuilder(endpoint, authKey)
|
|
|
|
builder => builder.WithEncryptor(encryptor));
|
|
|
|
.WithEncryptor(encryptor)
|
|
|
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static async Task IterateDekFeedAsync(
|
|
|
|
private static async Task IterateDekFeedAsync(
|
|
|
@ -712,49 +654,49 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static async Task<ItemResponse<TestDoc>> UpsertItemAsync(
|
|
|
|
private static async Task<ItemResponse<TestDoc>> UpsertItemAsync(
|
|
|
|
ContainerInternal containerCore,
|
|
|
|
Container container,
|
|
|
|
TestDoc testDoc,
|
|
|
|
TestDoc testDoc,
|
|
|
|
string dekId,
|
|
|
|
string dekId,
|
|
|
|
List<string> pathsToEncrypt,
|
|
|
|
List<string> pathsToEncrypt,
|
|
|
|
HttpStatusCode expectedStatusCode)
|
|
|
|
HttpStatusCode expectedStatusCode)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ItemResponse<TestDoc> upsertResponse = await containerCore.UpsertItemAsync(
|
|
|
|
ItemResponse<TestDoc> upsertResponse = await container.UpsertItemAsync(
|
|
|
|
testDoc,
|
|
|
|
testDoc,
|
|
|
|
new PartitionKey(testDoc.PK),
|
|
|
|
new PartitionKey(testDoc.PK),
|
|
|
|
EncryptionTests.GetRequestOptions(containerCore, dekId, pathsToEncrypt));
|
|
|
|
EncryptionTests.GetRequestOptions(container, dekId, pathsToEncrypt));
|
|
|
|
Assert.AreEqual(expectedStatusCode, upsertResponse.StatusCode);
|
|
|
|
Assert.AreEqual(expectedStatusCode, upsertResponse.StatusCode);
|
|
|
|
Assert.AreEqual(testDoc, upsertResponse.Resource);
|
|
|
|
Assert.AreEqual(testDoc, upsertResponse.Resource);
|
|
|
|
return upsertResponse;
|
|
|
|
return upsertResponse;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static async Task<ItemResponse<TestDoc>> CreateItemAsync(
|
|
|
|
private static async Task<ItemResponse<TestDoc>> CreateItemAsync(
|
|
|
|
ContainerInternal containerCore,
|
|
|
|
Container container,
|
|
|
|
string dekId,
|
|
|
|
string dekId,
|
|
|
|
List<string> pathsToEncrypt,
|
|
|
|
List<string> pathsToEncrypt,
|
|
|
|
string partitionKey = null)
|
|
|
|
string partitionKey = null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
TestDoc testDoc = TestDoc.Create(partitionKey);
|
|
|
|
TestDoc testDoc = TestDoc.Create(partitionKey);
|
|
|
|
ItemResponse<TestDoc> createResponse = await containerCore.CreateItemAsync(
|
|
|
|
ItemResponse<TestDoc> createResponse = await container.CreateItemAsync(
|
|
|
|
testDoc,
|
|
|
|
testDoc,
|
|
|
|
new PartitionKey(testDoc.PK),
|
|
|
|
new PartitionKey(testDoc.PK),
|
|
|
|
EncryptionTests.GetRequestOptions(containerCore, dekId, pathsToEncrypt));
|
|
|
|
EncryptionTests.GetRequestOptions(container, dekId, pathsToEncrypt));
|
|
|
|
Assert.AreEqual(HttpStatusCode.Created, createResponse.StatusCode);
|
|
|
|
Assert.AreEqual(HttpStatusCode.Created, createResponse.StatusCode);
|
|
|
|
Assert.AreEqual(testDoc, createResponse.Resource);
|
|
|
|
Assert.AreEqual(testDoc, createResponse.Resource);
|
|
|
|
return createResponse;
|
|
|
|
return createResponse;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static async Task<ItemResponse<TestDoc>> ReplaceItemAsync(
|
|
|
|
private static async Task<ItemResponse<TestDoc>> ReplaceItemAsync(
|
|
|
|
ContainerInternal containerCore,
|
|
|
|
Container container,
|
|
|
|
TestDoc testDoc,
|
|
|
|
TestDoc testDoc,
|
|
|
|
string dekId,
|
|
|
|
string dekId,
|
|
|
|
List<string> pathsToEncrypt,
|
|
|
|
List<string> pathsToEncrypt,
|
|
|
|
string etag = null)
|
|
|
|
string etag = null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ItemResponse<TestDoc> replaceResponse = await containerCore.ReplaceItemAsync(
|
|
|
|
ItemResponse<TestDoc> replaceResponse = await container.ReplaceItemAsync(
|
|
|
|
testDoc,
|
|
|
|
testDoc,
|
|
|
|
testDoc.Id,
|
|
|
|
testDoc.Id,
|
|
|
|
new PartitionKey(testDoc.PK),
|
|
|
|
new PartitionKey(testDoc.PK),
|
|
|
|
EncryptionTests.GetRequestOptions(containerCore, dekId, pathsToEncrypt, etag));
|
|
|
|
EncryptionTests.GetRequestOptions(container, dekId, pathsToEncrypt, etag));
|
|
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(HttpStatusCode.OK, replaceResponse.StatusCode);
|
|
|
|
Assert.AreEqual(HttpStatusCode.OK, replaceResponse.StatusCode);
|
|
|
|
Assert.AreEqual(testDoc, replaceResponse.Resource);
|
|
|
|
Assert.AreEqual(testDoc, replaceResponse.Resource);
|
|
|
@ -762,10 +704,10 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static async Task<ItemResponse<TestDoc>> DeleteItemAsync(
|
|
|
|
private static async Task<ItemResponse<TestDoc>> DeleteItemAsync(
|
|
|
|
ContainerInternal containerCore,
|
|
|
|
Container container,
|
|
|
|
TestDoc testDoc)
|
|
|
|
TestDoc testDoc)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ItemResponse<TestDoc> deleteResponse = await containerCore.DeleteItemAsync<TestDoc>(
|
|
|
|
ItemResponse<TestDoc> deleteResponse = await container.DeleteItemAsync<TestDoc>(
|
|
|
|
testDoc.Id,
|
|
|
|
testDoc.Id,
|
|
|
|
new PartitionKey(testDoc.PK));
|
|
|
|
new PartitionKey(testDoc.PK));
|
|
|
|
|
|
|
|
|
|
|
@ -775,7 +717,7 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static ItemRequestOptions GetRequestOptions(
|
|
|
|
private static ItemRequestOptions GetRequestOptions(
|
|
|
|
ContainerInternal containerCore,
|
|
|
|
Container container,
|
|
|
|
string dekId,
|
|
|
|
string dekId,
|
|
|
|
List<string> pathsToEncrypt,
|
|
|
|
List<string> pathsToEncrypt,
|
|
|
|
string ifMatchEtag = null)
|
|
|
|
string ifMatchEtag = null)
|
|
|
@ -793,7 +735,7 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static TransactionalBatchItemRequestOptions GetBatchItemRequestOptions(
|
|
|
|
private static TransactionalBatchItemRequestOptions GetBatchItemRequestOptions(
|
|
|
|
ContainerInternal containerCore,
|
|
|
|
Container container,
|
|
|
|
string dekId,
|
|
|
|
string dekId,
|
|
|
|
List<string> pathsToEncrypt,
|
|
|
|
List<string> pathsToEncrypt,
|
|
|
|
string ifMatchEtag = null)
|
|
|
|
string ifMatchEtag = null)
|
|
|
@ -815,7 +757,7 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
ResponseMessage readResponseMessage = await container.ReadItemStreamAsync(testDoc.Id, new PartitionKey(testDoc.PK));
|
|
|
|
ResponseMessage readResponseMessage = await container.ReadItemStreamAsync(testDoc.Id, new PartitionKey(testDoc.PK));
|
|
|
|
Assert.AreEqual(HttpStatusCode.OK, readResponseMessage.StatusCode);
|
|
|
|
Assert.AreEqual(HttpStatusCode.OK, readResponseMessage.StatusCode);
|
|
|
|
Assert.IsNotNull(readResponseMessage.Content);
|
|
|
|
Assert.IsNotNull(readResponseMessage.Content);
|
|
|
|
TestDoc readDoc = TestCommon.SerializerCore.FromStream<TestDoc>(readResponseMessage.Content);
|
|
|
|
TestDoc readDoc = TestCommon.FromStream<TestDoc>(readResponseMessage.Content);
|
|
|
|
Assert.AreEqual(testDoc, readDoc);
|
|
|
|
Assert.AreEqual(testDoc, readDoc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -925,7 +867,7 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
|
|
|
|
|
|
|
|
public Stream ToStream()
|
|
|
|
public Stream ToStream()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return TestCommon.SerializerCore.ToStream(this);
|
|
|
|
return TestCommon.ToStream(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -990,4 +932,4 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|