示例#1
0
        public void Encrypt_64CharKeyWithFilter_Success()
        {
            var settings = new ProjectSettingsProvider("projId", "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef");

            IDictionary <string, object> filter = new ExpandoObject();

            filter.Add("property_name", "account_id");
            filter.Add("operator", "eq");
            filter.Add("property_value", 123);

            dynamic secOpsIn = new ExpandoObject();

            secOpsIn.filters = new List <object>()
            {
                filter
            };
            secOpsIn.allowed_operations = new List <string>()
            {
                "read"
            };
            Assert.DoesNotThrow(() =>
            {
                var scopedKey = ScopedKey.Encrypt(settings.MasterKey, (object)secOpsIn);
                var decrypted = ScopedKey.Decrypt(settings.MasterKey, scopedKey);
                var secOpsOut = JObject.Parse(decrypted);
                Assert.True(secOpsIn.allowed_operations[0] == (string)(secOpsOut["allowed_operations"].First()));
            });
        }
示例#2
0
        public void RoundTrip_PopulatedObject_WithIV_Success()
        {
            var settings = new ProjectSettingsProviderEnv();
            var IV       = "C0FFEEC0FFEEC0FFEEC0FFEEC0FFEEC0";

            IDictionary <string, object> filter = new ExpandoObject();

            filter.Add("property_name", "account_id");
            filter.Add("operator", "eq");
            filter.Add("property_value", 123);

            dynamic secOpsIn = new ExpandoObject();

            secOpsIn.filters = new List <object>()
            {
                filter
            };
            secOpsIn.allowed_operations = new List <string>()
            {
                "read"
            };
            Assert.DoesNotThrow(() =>
            {
                var scopedKey = ScopedKey.Encrypt(settings.MasterKey, (object)secOpsIn, IV);
                var decrypted = ScopedKey.Decrypt(settings.MasterKey, scopedKey);
                var secOpsOut = JObject.Parse(decrypted);
                Assert.True(secOpsIn.allowed_operations[0] == (string)(secOpsOut["allowed_operations"].First()));
            });
        }
示例#3
0
        public void Encrypt_PopulatedObject_Success()
        {
            Assert.DoesNotThrow(() =>
            {
                var settings = new ProjectSettingsProviderEnv();

                const string str = "{\"filters\": [{\"property_name\": \"account_id\",\"operator\": \"eq\",\"property_value\": 123}],\"allowed_operations\": [ \"read\" ]}";
                var secOps       = JObject.Parse(str);
                var scopedKey    = ScopedKey.Encrypt(settings.MasterKey, secOps);
            });
        }
示例#4
0
        public void RoundTrip_PopulatedObject_WithIV_Success()
        {
            var          settings = new ProjectSettingsProviderEnv();
            const string IV       = "C0FFEEC0FFEEC0FFEEC0FFEEC0FFEEC0";

            const string str    = "{\"filters\": [{\"property_name\": \"account_id\",\"operator\": \"eq\",\"property_value\": 123}],\"allowed_operations\": [ \"read\" ]}";
            var          secOps = JObject.Parse(str);

            Assert.DoesNotThrow(() =>
            {
                var scopedKey = ScopedKey.Encrypt(settings.MasterKey, secOps, IV);
                var decrypted = ScopedKey.Decrypt(settings.MasterKey, scopedKey);
                var secOpsOut = JObject.Parse(decrypted);
                Assert.True((string)secOps["allowed_operations"].First() == (string)(secOpsOut["allowed_operations"].First()));
            });
        }
示例#5
0
        public void Encrypt_PopulatedObject_Success()
        {
            Assert.DoesNotThrow(() =>
            {
                var settings = new ProjectSettingsProviderEnv();

                dynamic secOps = new ExpandoObject();

                IDictionary <string, object> filter = new ExpandoObject();
                filter.Add("property_name", "account_id");
                filter.Add("operator", "eq");
                filter.Add("property_value", 123);
                secOps.filters = new List <object>()
                {
                    filter
                };
                secOps.allowed_operations = new List <string>()
                {
                    "read"
                };

                var scopedKey = ScopedKey.Encrypt(settings.MasterKey, (object)secOps);
            });
        }
示例#6
0
 public void Encrypt_NullKey_Throws()
 {
     Assert.Throws <Keen.Core.KeenException>(() => ScopedKey.Encrypt(null, new { X = "X" }));
 }
示例#7
0
 public void Encrypt_NullObject_Success()
 {
     Assert.DoesNotThrow(() => ScopedKey.Encrypt("0123456789ABCDEF0123456789ABCDEF", null));
 }
示例#8
0
 public void Encrypt_64CharKey_Success()
 {
     Assert.DoesNotThrow(() => ScopedKey.Encrypt("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", null));
 }
示例#9
0
 public void Encrypt_BlankKey_Success()
 {
     Assert.DoesNotThrow(() => ScopedKey.Encrypt("", new { X = "X" }));
 }
示例#10
0
 public void Encrypt_NullKey_Success()
 {
     Assert.DoesNotThrow(() => ScopedKey.Encrypt(null, new { X = "X" }));
 }
示例#11
0
 public void Encrypt_NullObject_Success()
 {
     Assert.DoesNotThrow(() => ScopedKey.Encrypt("abc", null));
 }
示例#12
0
 public void Encrypt_BlankKey_Throws()
 {
     Assert.Throws <KeenException>(() => ScopedKey.Encrypt("", new { X = "X" }));
 }