Example #1
0
        public void ParameterizedTests(
            IEnvelopeEncryption <byte[]> envelopeEncryptionJson,
            Mock <IMetastorePersistence <JObject> > metastorePersistence,
            KeyState cacheIK,
            KeyState metaIK,
            KeyState cacheSK,
            KeyState metaSK,
            AppEncryptionPartition appEncryptionPartition)
        {
            using (AppEncryption <JObject, byte[]> appEncryptionJsonImpl =
                       new AppEncryptionJsonImpl <byte[]>(envelopeEncryptionJson))
            {
                EncryptMetastoreInteractions encryptMetastoreInteractions =
                    new EncryptMetastoreInteractions(cacheIK, metaIK, cacheSK, metaSK);
                DecryptMetastoreInteractions decryptMetastoreInteractions =
                    new DecryptMetastoreInteractions(cacheIK, cacheSK);

                // encrypt with library object(appEncryptionJsonImpl)
                byte[] encryptedPayload = appEncryptionJsonImpl.Encrypt(payload);

                Assert.NotNull(encryptedPayload);
                VerifyEncryptFlow(metastorePersistence, encryptMetastoreInteractions, appEncryptionPartition);

                metastorePersistence.Invocations.Clear();
                JObject decryptedPayload = appEncryptionJsonImpl.Decrypt(encryptedPayload);

                VerifyDecryptFlow(metastorePersistence, decryptMetastoreInteractions, appEncryptionPartition);
                Assert.True(JToken.DeepEquals(payload, decryptedPayload));
            }
        }
Example #2
0
        private void TestEncrypt()
        {
            const string expectedDataRowRecord = "some data row record";
            const string json    = @"{key:'some_key', value:123}";
            JObject      jObject = JObject.Parse(json);

            envelopeEncryptionMock.Setup(x => x.EncryptPayload(It.IsAny <byte[]>())).Returns(expectedDataRowRecord);

            string actualDataRowRecord = appEncryptionJsonImpl.Encrypt(jObject);

            Assert.Equal(expectedDataRowRecord, actualDataRowRecord);
        }