public async Task EncryptionUTCreateItem() { Container container = this.GetContainerWithMockSetup(); MyItem item = await EncryptionUnitTests.CreateItemAsync(container, EncryptionUnitTests.DekId, MyItem.PathsToEncrypt); // Validate server state Assert.IsTrue(this.testHandler.Items.TryGetValue(item.Id, out JObject serverItem)); Assert.IsNotNull(serverItem); Assert.AreEqual(item.Id, serverItem.Property(Constants.Properties.Id).Value.Value <string>()); Assert.AreEqual(item.PK, serverItem.Property(nameof(MyItem.PK)).Value.Value <string>()); Assert.IsNull(serverItem.Property(nameof(MyItem.EncStr1))); Assert.IsNull(serverItem.Property(nameof(MyItem.EncInt))); JProperty eiJProp = serverItem.Property(Constants.Properties.EncryptedInfo); Assert.IsNotNull(eiJProp); Assert.IsNotNull(eiJProp.Value); Assert.AreEqual(JTokenType.Object, eiJProp.Value.Type); EncryptionProperties encryptionPropertiesAtServer = ((JObject)eiJProp.Value).ToObject <EncryptionProperties>(); Assert.IsNotNull(encryptionPropertiesAtServer); Assert.AreEqual(EncryptionUnitTests.DekId, encryptionPropertiesAtServer.DataEncryptionKeyId); Assert.AreEqual(2, encryptionPropertiesAtServer.EncryptionFormatVersion); Assert.IsNotNull(encryptionPropertiesAtServer.EncryptedData); JObject decryptedJObj = EncryptionUnitTests.ParseStream(new MemoryStream(EncryptionUnitTests.DecryptData(encryptionPropertiesAtServer.EncryptedData))); Assert.AreEqual(2, decryptedJObj.Properties().Count()); Assert.AreEqual(item.EncStr1, decryptedJObj.Property(nameof(MyItem.EncStr1)).Value.Value <string>()); Assert.AreEqual(item.EncInt, decryptedJObj.Property(nameof(MyItem.EncInt)).Value.Value <int>()); }
public async Task EncryptionUTReadItem() { Container container = this.GetContainerWithMockSetup(); MyItem item = await EncryptionUnitTests.CreateItemAsync(container, EncryptionUnitTests.DekId, MyItem.PathsToEncrypt); ItemResponse <MyItem> readResponse = await container.ReadItemAsync <MyItem>(item.Id, new Cosmos.PartitionKey(item.PK)); Assert.AreEqual(item, readResponse.Resource); }