Exemple #1
0
        public async Task EncryptionUTCreateItemWithUnknownDek()
        {
            Container    container = this.GetContainerWithMockSetup();
            DatabaseCore database  = (DatabaseCore)((ContainerCore)(ContainerInlineCore)container).Database;

            MyItem item = EncryptionUnitTests.GetNewItem();

            try
            {
                await container.CreateItemAsync(
                    item,
                    new PartitionKey(item.PK),
                    new ItemRequestOptions
                {
                    EncryptionOptions = new EncryptionOptions
                    {
                        DataEncryptionKey = database.GetDataEncryptionKey("random"),
                        PathsToEncrypt    = MyItem.PathsToEncrypt
                    }
                });

                Assert.Fail();
            }
            catch (CosmosException ex)
            {
                Assert.IsTrue(ex.Message.Contains(ClientResources.DataEncryptionKeyNotFound));
            }
        }
Exemple #2
0
        private static async Task <MyItem> CreateItemAsync(Container container, string dekId, List <string> pathsToEncrypt)
        {
            DatabaseCore database = (DatabaseCore)((ContainerCore)(ContainerInlineCore)container).Database;

            MyItem item = EncryptionUnitTests.GetNewItem();

            ItemResponse <MyItem> response = await container.CreateItemAsync <MyItem>(
                item,
                requestOptions : new ItemRequestOptions
            {
                EncryptionOptions = new EncryptionOptions
                {
                    DataEncryptionKey = database.GetDataEncryptionKey(dekId),
                    PathsToEncrypt    = pathsToEncrypt
                }
            });

            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
            Assert.AreEqual(item, response.Resource);
            return(item);
        }