Esempio n. 1
0
        public async Task EncryptionDekReadFeed()
        {
            DatabaseCore databaseCore = null;

            try
            {
                databaseCore = (DatabaseInlineCore)await EncryptionTests.client.CreateDatabaseAsync(Guid.NewGuid().ToString());

                ContainerCore containerCore = (ContainerInlineCore)await EncryptionTests.databaseCore.CreateContainerAsync(Guid.NewGuid().ToString(), "/PK", 400);

                string contosoV1  = "Contoso_v001";
                string contosoV2  = "Contoso_v002";
                string fabrikamV1 = "Fabrikam_v001";
                string fabrikamV2 = "Fabrikam_v002";

                await EncryptionTests.CreateDekAsync(databaseCore, contosoV1);

                await EncryptionTests.CreateDekAsync(databaseCore, contosoV2);

                await EncryptionTests.CreateDekAsync(databaseCore, fabrikamV1);

                await EncryptionTests.CreateDekAsync(databaseCore, fabrikamV2);

                // Test getting all keys
                await EncryptionTests.IterateDekFeedAsync(
                    databaseCore,
                    new List <string> {
                    contosoV1, contosoV2, fabrikamV1, fabrikamV2
                },
                    isExpectedDeksCompleteSetForRequest : true,
                    isResultOrderExpected : false);

                // Test getting specific subset of keys
                await EncryptionTests.IterateDekFeedAsync(
                    databaseCore,
                    new List <string> {
                    contosoV2
                },
                    isExpectedDeksCompleteSetForRequest : false,
                    isResultOrderExpected : true,
                    startId : "Contoso_v000",
                    endId : "Contoso_v999",
                    isDescending : true,
                    itemCountInPage : 1);

                // Ensure only required results are returned (ascending)
                await EncryptionTests.IterateDekFeedAsync(
                    databaseCore,
                    new List <string> {
                    contosoV1, contosoV2
                },
                    isExpectedDeksCompleteSetForRequest : true,
                    isResultOrderExpected : true,
                    startId : "Contoso_v000",
                    endId : "Contoso_v999",
                    isDescending : false);

                // Test startId inclusive and endId inclusive (ascending)
                await EncryptionTests.IterateDekFeedAsync(
                    databaseCore,
                    new List <string> {
                    contosoV1, contosoV2
                },
                    isExpectedDeksCompleteSetForRequest : true,
                    isResultOrderExpected : true,
                    startId : "Contoso_v001",
                    endId : "Contoso_v002",
                    isDescending : false);

                // Ensure only required results are returned (descending)
                await EncryptionTests.IterateDekFeedAsync(
                    databaseCore,
                    new List <string> {
                    contosoV2, contosoV1
                },
                    isExpectedDeksCompleteSetForRequest : true,
                    isResultOrderExpected : true,
                    startId : "Contoso_v000",
                    endId : "Contoso_v999",
                    isDescending : true);

                // Test startId inclusive and endId inclusive (descending)
                await EncryptionTests.IterateDekFeedAsync(
                    databaseCore,
                    new List <string> {
                    contosoV2, contosoV1
                },
                    isExpectedDeksCompleteSetForRequest : true,
                    isResultOrderExpected : true,
                    startId : "Contoso_v001",
                    endId : "Contoso_v002",
                    isDescending : true);

                // Test pagination
                await EncryptionTests.IterateDekFeedAsync(
                    databaseCore,
                    new List <string> {
                    contosoV1, contosoV2, fabrikamV1, fabrikamV2
                },
                    isExpectedDeksCompleteSetForRequest : true,
                    isResultOrderExpected : false,
                    itemCountInPage : 3);
            }
            finally
            {
                if (databaseCore != null)
                {
                    await databaseCore.DeleteStreamAsync();
                }
            }
        }
        public async Task EncryptionDekReadFeed()
        {
            Container newKeyContainer = await EncryptionTests.databaseCore.CreateContainerAsync(Guid.NewGuid().ToString(), "/id", 400);

            try
            {
                CosmosDataEncryptionKeyProvider dekProvider = new CosmosDataEncryptionKeyProvider(new TestKeyWrapProvider());
                await dekProvider.InitializeAsync(EncryptionTests.databaseCore, newKeyContainer.Id);

                string contosoV1  = "Contoso_v001";
                string contosoV2  = "Contoso_v002";
                string fabrikamV1 = "Fabrikam_v001";
                string fabrikamV2 = "Fabrikam_v002";

                await EncryptionTests.CreateDekAsync(dekProvider, contosoV1);

                await EncryptionTests.CreateDekAsync(dekProvider, contosoV2);

                await EncryptionTests.CreateDekAsync(dekProvider, fabrikamV1);

                await EncryptionTests.CreateDekAsync(dekProvider, fabrikamV2);

                // Test getting all keys
                await EncryptionTests.IterateDekFeedAsync(
                    dekProvider,
                    new List <string> {
                    contosoV1, contosoV2, fabrikamV1, fabrikamV2
                },
                    isExpectedDeksCompleteSetForRequest : true,
                    isResultOrderExpected : false,
                    "SELECT * from c");

                // Test getting specific subset of keys
                await EncryptionTests.IterateDekFeedAsync(
                    dekProvider,
                    new List <string> {
                    contosoV2
                },
                    isExpectedDeksCompleteSetForRequest : false,
                    isResultOrderExpected : true,
                    "SELECT TOP 1 * from c where c.id >= 'Contoso_v000' and c.id <= 'Contoso_v999' ORDER BY c.id DESC");

                // Ensure only required results are returned
                await EncryptionTests.IterateDekFeedAsync(
                    dekProvider,
                    new List <string> {
                    contosoV1, contosoV2
                },
                    isExpectedDeksCompleteSetForRequest : true,
                    isResultOrderExpected : true,
                    "SELECT * from c where c.id >= 'Contoso_v000' and c.id <= 'Contoso_v999' ORDER BY c.id ASC");

                // Test pagination
                await EncryptionTests.IterateDekFeedAsync(
                    dekProvider,
                    new List <string> {
                    contosoV1, contosoV2, fabrikamV1, fabrikamV2
                },
                    isExpectedDeksCompleteSetForRequest : true,
                    isResultOrderExpected : false,
                    "SELECT * from c",
                    itemCountInPage : 3);
            }
            finally
            {
                await newKeyContainer.DeleteContainerStreamAsync();
            }
        }