예제 #1
0
        public static void ClassInitilize(TestContext testContext)
        {
            EncryptionProcessorTests.encryptionOptions = new EncryptionOptions()
            {
                DataEncryptionKeyId = EncryptionProcessorTests.dekId,
                EncryptionAlgorithm = CosmosEncryptionAlgorithm.AEAes256CbcHmacSha256Randomized,
                PathsToEncrypt      = TestDoc.PathsToEncrypt
            };

            EncryptionProcessorTests.mockEncryptor = new Mock <Encryptor>();
            EncryptionProcessorTests.mockEncryptor.Setup(m => m.EncryptAsync(It.IsAny <byte[]>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync((byte[] plainText, string dekId, string algo, CancellationToken t) =>
                          dekId == EncryptionProcessorTests.dekId ? TestCommon.EncryptData(plainText) : throw new InvalidOperationException("DEK not found."));
            EncryptionProcessorTests.mockEncryptor.Setup(m => m.DecryptAsync(It.IsAny <byte[]>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync((byte[] cipherText, string dekId, string algo, CancellationToken t) =>
                          dekId == EncryptionProcessorTests.dekId ? TestCommon.DecryptData(cipherText) : throw new InvalidOperationException("Null DEK was returned."));
        }
        public static void ClassInitialize(TestContext testContext)
        {
            CosmosEncryptorTests.mockDataEncryptionKey = new Mock <DataEncryptionKey>();
            CosmosEncryptorTests.mockDataEncryptionKey
            .Setup(m => m.EncryptData(It.IsAny <byte[]>()))
            .Returns((byte[] plainText) => TestCommon.EncryptData(plainText));
            CosmosEncryptorTests.mockDataEncryptionKey
            .Setup(m => m.DecryptData(It.IsAny <byte[]>()))
            .Returns((byte[] cipherText) => TestCommon.DecryptData(cipherText));

            CosmosEncryptorTests.mockDataEncryptionKeyProvider = new Mock <DataEncryptionKeyProvider>();
            CosmosEncryptorTests.mockDataEncryptionKeyProvider
            .Setup(m => m.FetchDataEncryptionKeyAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync((string dekId, string algo, CancellationToken cancellationToken) =>
                          dekId == CosmosEncryptorTests.dekId ? CosmosEncryptorTests.mockDataEncryptionKey.Object : null);

            CosmosEncryptorTests.cosmosEncryptor = new CosmosEncryptor(CosmosEncryptorTests.mockDataEncryptionKeyProvider.Object);
        }
예제 #3
0
 public static void ClassInitilize(TestContext testContext)
 {
     propertyEncryptionOptions = new List <EncryptionOptions> {
         {
             new EncryptionOptions()
             {
                 DataEncryptionKeyId = PropertyEncryptionProcessorTests.pdekId,
                 EncryptionAlgorithm = CosmosEncryptionAlgorithm.AEAD_AES_256_CBC_HMAC_SHA256,
                 PathsToEncrypt      = TestDoc.PropertyPathsToEncrypt
             }
         }
     };
     PathsToEncrypt.Add(TestDoc.PropertyPathsToEncrypt, pdekId);
     PropertyEncryptionProcessorTests.mockEncryptor = new Mock <Encryptor>();
     PropertyEncryptionProcessorTests.mockEncryptor.Setup(m => m.EncryptAsync(It.IsAny <byte[]>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
     .ReturnsAsync((byte[] plainText, string dekId, string algo, CancellationToken t) =>
                   dekId == PropertyEncryptionProcessorTests.pdekId ? TestCommon.EncryptData(plainText) : throw new InvalidOperationException("DEK not found."));
     PropertyEncryptionProcessorTests.mockEncryptor.Setup(m => m.DecryptAsync(It.IsAny <byte[]>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
     .ReturnsAsync((byte[] cipherText, string dekId, string algo, CancellationToken t) =>
                   dekId == PropertyEncryptionProcessorTests.pdekId ? TestCommon.DecryptData(cipherText) : throw new InvalidOperationException("Null DEK was returned."));
 }