Exemplo n.º 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()));
            });
        }
Exemplo n.º 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()));
            });
        }
Exemplo n.º 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);
            });
        }
Exemplo n.º 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()));
            });
        }
Exemplo n.º 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);
            });
        }
Exemplo n.º 6
0
 public void Encrypt_NullKey_Throws()
 {
     Assert.Throws <Keen.Core.KeenException>(() => ScopedKey.Encrypt(null, new { X = "X" }));
 }
Exemplo n.º 7
0
 public void Encrypt_NullObject_Success()
 {
     Assert.DoesNotThrow(() => ScopedKey.Encrypt("0123456789ABCDEF0123456789ABCDEF", null));
 }
Exemplo n.º 8
0
 public void Encrypt_64CharKey_Success()
 {
     Assert.DoesNotThrow(() => ScopedKey.Encrypt("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", null));
 }
Exemplo n.º 9
0
 public void Encrypt_BlankKey_Success()
 {
     Assert.DoesNotThrow(() => ScopedKey.Encrypt("", new { X = "X" }));
 }
Exemplo n.º 10
0
 public void Encrypt_NullKey_Success()
 {
     Assert.DoesNotThrow(() => ScopedKey.Encrypt(null, new { X = "X" }));
 }
Exemplo n.º 11
0
 public void Encrypt_NullObject_Success()
 {
     Assert.DoesNotThrow(() => ScopedKey.Encrypt("abc", null));
 }
Exemplo n.º 12
0
 public void Encrypt_BlankKey_Throws()
 {
     Assert.Throws <KeenException>(() => ScopedKey.Encrypt("", new { X = "X" }));
 }