public virtual void TestFindGuardedByteArray()
        {
            var expected = new GuardedByteArray();

            System.Text.Encoding.UTF8.GetBytes("array").ToList().ForEach(expected.AppendByte);
            Assert.AreEqual(expected, Testable.FindGuardedByteArray("attributeGuardedByteArray"));
        }
 public void TestEquals()
 {
     GuardedByteArray arr1 = new GuardedByteArray();
     GuardedByteArray arr2 = new GuardedByteArray();
     Assert.AreEqual(arr1, arr2);
     arr2.AppendByte(0x02);
     Assert.AreNotEqual(arr1, arr2);
     arr1.AppendByte(0x02);
     Assert.AreEqual(arr1, arr2);
 }
        public void TestEquals()
        {
            GuardedByteArray arr1 = new GuardedByteArray();
            GuardedByteArray arr2 = new GuardedByteArray();

            Assert.AreEqual(arr1, arr2);
            arr2.AppendByte(0x02);
            Assert.AreNotEqual(arr1, arr2);
            arr1.AppendByte(0x02);
            Assert.AreEqual(arr1, arr2);
        }
        public void TestGuardedByteArray()
        {
            GuardedByteArray v1 = new GuardedByteArray();

            v1.AppendByte(0x00);
            v1.AppendByte(0x01);
            v1.AppendByte(0x02);
            GuardedByteArray v2 = (GuardedByteArray)CloneObject(v1);

            Assert.AreEqual(new byte[] { 0x00, 0x01, 0x02 }, DecryptToByteArray(v2));
        }
 public void TestBasics()
 {
     GuardedByteArray ss = new GuardedByteArray();
     ss.AppendByte(0x00);
     ss.AppendByte(0x01);
     ss.AppendByte(0x02);
     byte[] decrypted = DecryptToByteArray(ss);
     Assert.AreEqual(new byte[] { 0x00, 0x01, 0x02 }, decrypted);
     String hash = ss.GetBase64SHA1Hash();
     Assert.IsTrue(ss.VerifyBase64SHA1Hash(hash));
     ss.AppendByte(0x03);
     Assert.IsFalse(ss.VerifyBase64SHA1Hash(hash));
 }
 private byte[] DecryptToByteArray(GuardedByteArray bytes)
 {
     byte[] result = null;
     bytes.Access(new GuardedByteArray.LambdaAccessor(
                      array =>
     {
         result = new byte[array.Length];
         for (int i = 0; i < array.Length; i++)
         {
             result[i] = array[i];
         }
     }));
     return(result);
 }
 /// <summary>
 /// Highly insecure method! Do not do this in production
 /// code.
 /// </summary>
 /// <remarks>
 /// This is only for test purposes
 /// </remarks>
 private byte[] DecryptToByteArray(GuardedByteArray str)
 {
     byte[] result = null;
     str.Access(
         array =>
     {
         result = new byte[array.Length];
         for (int i = 0; i < array.Length; i++)
         {
             result[i] = array[i];
         }
     });
     return(result);
 }
 public void TestRange()
 {
     for (byte i = 0; i < 0xFF; i++)
     {
         byte             expected = i;
         GuardedByteArray gba      = new GuardedByteArray();
         gba = (GuardedByteArray)SerializerUtil.CloneObject(gba);
         gba.AppendByte(i);
         gba.Access(new GuardedByteArray.LambdaAccessor(clearChars =>
         {
             int v = (byte)clearChars[0];
             Assert.AreEqual(expected, v);
         }));
     }
 }
        public void TestBasics()
        {
            GuardedByteArray ss = new GuardedByteArray();

            ss.AppendByte(0x00);
            ss.AppendByte(0x01);
            ss.AppendByte(0x02);
            byte[] decrypted = DecryptToByteArray(ss);
            Assert.AreEqual(new byte[] { 0x00, 0x01, 0x02 }, decrypted);
            String hash = ss.GetBase64SHA1Hash();

            Assert.IsTrue(ss.VerifyBase64SHA1Hash(hash));
            ss.AppendByte(0x03);
            Assert.IsFalse(ss.VerifyBase64SHA1Hash(hash));
        }
        public void TestRange()
        {
            for (byte i = 0; i < 0xFF; i++)
            {
                byte expected = i;
                GuardedByteArray gba = new GuardedByteArray();
                gba = (GuardedByteArray)SerializerUtil.CloneObject(gba);
                gba.AppendByte(i);
                gba.Access(new GuardedByteArray.LambdaAccessor(clearChars =>
                {
                    int v = (byte)clearChars[0];
                    Assert.AreEqual(expected, v);
                }));

            }
        }
예제 #11
0
 private byte[] DecryptToByteArray(GuardedByteArray bytes)
 {
     byte[] result = null;
     bytes.Access(new GuardedByteArray.LambdaAccessor(
                                     array =>
                                     {
                                         result = new byte[array.Length];
                                         for (int i = 0; i < array.Length; i++)
                                         {
                                             result[i] = array[i];
                                         }
                                     }));
     return result;
 }
예제 #12
0
 public void TestGuardedByteArray()
 {
     GuardedByteArray v1 = new GuardedByteArray();
     v1.AppendByte(0x00);
     v1.AppendByte(0x01);
     v1.AppendByte(0x02);
     GuardedByteArray v2 = (GuardedByteArray)CloneObject(v1);
     Assert.AreEqual(new byte[] { 0x00, 0x01, 0x02 }, DecryptToByteArray(v2));
 }
 public virtual void TestFindGuardedByteArray()
 {
     var expected = new GuardedByteArray();
     System.Text.Encoding.UTF8.GetBytes("array").ToList().ForEach(expected.AppendByte);
     Assert.AreEqual(expected, Testable.FindGuardedByteArray("attributeGuardedByteArray"));
 }
예제 #14
0
        public void TestCreateTestConfiguration()
        {
            IDictionary <string, object> expectedData = new Dictionary <string, object>();

            expectedData["String"]            = "retipipiter";
            expectedData["StringArray"]       = new [] { "value1", "value2", "value3" };
            expectedData["Long"]              = 11L;
            expectedData["LongArray"]         = new [] { 12L, 13L };
            expectedData["LongObject"]        = 14L;
            expectedData["LongObjectArray"]   = new long?[] { 15, null };
            expectedData["Char"]              = 'a';
            expectedData["CharArray"]         = new [] { 'b', 'c' };
            expectedData["Character"]         = 'd';
            expectedData["CharacterArray"]    = new char?[] { 'e', 'f' };
            expectedData["Double"]            = 0D;
            expectedData["DoubleArray"]       = new [] { 0D, 100D };
            expectedData["DoubleObject"]      = 0d;
            expectedData["DoubleObjectArray"] = new double?[] { 0D, 100D };
            expectedData["Float"]             = 0F;
            expectedData["FloatArray"]        = new[] { 0F, 100F };
            expectedData["FloatObject"]       = null;
            expectedData["FloatObjectArray"]  = new float?[] { 0F, 100F };
            expectedData["Int"]                = 0;
            expectedData["IntArray"]           = new[] { 0, 100 };
            expectedData["Integer"]            = 0;
            expectedData["IntegerArray"]       = new int?[] { 0, 100 };
            expectedData["Boolean"]            = true;
            expectedData["BooleanArray"]       = new[] { true, false };
            expectedData["BooleanObject"]      = false;
            expectedData["BooleanObjectArray"] = new bool?[] { true, false };
            expectedData["URI"]                = new Uri("http://localhost:8080");            expectedData["URIArray"] = "";
            expectedData["URIArray"]           = new[] { new Uri("http://localhost:8080"), new Uri("http://localhost:8443") };
            expectedData["File"]               = new FileName("c:\\Users\\Admin");
            expectedData["FileArray"]          = new[] { new FileName("c:\\Users\\Admin\\Documents"), new FileName("c:\\Users\\Admin\\Settings") };
            var array = new GuardedByteArray();

            Encoding.UTF8.GetBytes("array").ToList().ForEach(array.AppendByte);
            expectedData["GuardedByteArray"] = array;

            array = new GuardedByteArray();
            Encoding.UTF8.GetBytes("item1").ToList().ForEach(array.AppendByte);
            var array2 = new GuardedByteArray();

            Encoding.UTF8.GetBytes("item2").ToList().ForEach(array2.AppendByte);
            expectedData["GuardedByteArrayArray"] = new [] { array, array2 };

            var secret = new GuardedString();

            "secret".ToCharArray().ToList().ForEach(secret.AppendChar);
            expectedData["GuardedString"] = secret;

            secret = new GuardedString();
            "secret1".ToCharArray().ToList().ForEach(secret.AppendChar);
            var secret2 = new GuardedString();

            "secret2".ToCharArray().ToList().ForEach(secret2.AppendChar);

            expectedData["GuardedStringArray"] = new[] { secret, secret2 };
            expectedData["Script"]             = new ScriptBuilder {
                ScriptLanguage = "PowerShell", ScriptText = "echo 'Hello OpenICF Developer'"
            }.Build();
            expectedData["ScriptArray"] = new[] { new ScriptBuilder {
                                                      ScriptLanguage = "Groovy", ScriptText = "println 'Hello'"
                                                  }.Build(), new ScriptBuilder {
                                                      ScriptLanguage = "Groovy", ScriptText = "println 'OpenICF Developer'"
                                                  }.Build() };

            Environment.SetEnvironmentVariable(TestHelpers.TestConfigEVName, "converter");

            FieldInfo info = typeof(TestHelpers).GetField("_propertyBags", BindingFlags.NonPublic | BindingFlags.Static);

            (info.GetValue(null) as Dictionary <string, PropertyBag>).Clear();

            PropertyBag propertyBag =
                TestHelpers.GetProperties(typeof(Org.IdentityConnectors.TestConnector.FakeConnector));

            (info.GetValue(null) as Dictionary <string, PropertyBag>).Clear();

            APIConfiguration testable = TestHelpers.CreateTestConfiguration(SafeType <Connector> .Get <Org.IdentityConnectors.TestConnector.FakeConnector>(), propertyBag, null);

            foreach (KeyValuePair <string, object> entry in expectedData)
            {
                Assert.AreEqual(entry.Value, testable.ConfigurationProperties.GetProperty(entry.Key).Value, "Configuration property: " + entry.Key + " has different value");
            }
        }
        public void TestCreateTestConfiguration()
        {
            IDictionary<string, object> expectedData = new Dictionary<string, object>();
            expectedData["String"] = "retipipiter";
            expectedData["StringArray"] = new [] { "value1", "value2", "value3" };
            expectedData["Long"] = 11L;
            expectedData["LongArray"] = new []{12L, 13L};
            expectedData["LongObject"] = 14L;
            expectedData["LongObjectArray"] = new long?[]{15, null};
            expectedData["Char"] = 'a';
            expectedData["CharArray"] = new []{'b','c'};
            expectedData["Character"] = 'd';
            expectedData["CharacterArray"] = new char?[]{'e','f'};
            expectedData["Double"] = 0D;
            expectedData["DoubleArray"] = new []{0D, 100D};
            expectedData["DoubleObject"] = 0d;
            expectedData["DoubleObjectArray"] = new double?[] { 0D, 100D };
            expectedData["Float"] = 0F;
            expectedData["FloatArray"] = new[] { 0F, 100F };
            expectedData["FloatObject"] = null;
            expectedData["FloatObjectArray"] = new float?[] { 0F, 100F };
            expectedData["Int"] = 0;
            expectedData["IntArray"] = new[] { 0, 100 };
            expectedData["Integer"] = 0;
            expectedData["IntegerArray"] = new int?[] { 0, 100 };
            expectedData["Boolean"] = true;
            expectedData["BooleanArray"] = new[]{true, false};
            expectedData["BooleanObject"] = false;
            expectedData["BooleanObjectArray"] = new bool?[] { true, false };
            expectedData["URI"] = new Uri("http://localhost:8080");            expectedData["URIArray"] = "";
            expectedData["URIArray"] = new[] { new Uri("http://localhost:8080"), new Uri("http://localhost:8443") };
            expectedData["File"] = new FileName("c:\\Users\\Admin");
            expectedData["FileArray"] = new[] {new FileName("c:\\Users\\Admin\\Documents"), new FileName("c:\\Users\\Admin\\Settings")};
            var array = new GuardedByteArray();
            Encoding.UTF8.GetBytes("array").ToList().ForEach(array.AppendByte);
            expectedData["GuardedByteArray"] = array;

            array = new GuardedByteArray();
            Encoding.UTF8.GetBytes("item1").ToList().ForEach(array.AppendByte);
            var array2 = new GuardedByteArray();
            Encoding.UTF8.GetBytes("item2").ToList().ForEach(array2.AppendByte);
            expectedData["GuardedByteArrayArray"] = new []{array, array2};

            var secret = new GuardedString();
            "secret".ToCharArray().ToList().ForEach(secret.AppendChar);
            expectedData["GuardedString"] = secret;

            secret = new GuardedString();
            "secret1".ToCharArray().ToList().ForEach(secret.AppendChar);
            var secret2 = new GuardedString();
            "secret2".ToCharArray().ToList().ForEach(secret2.AppendChar);

            expectedData["GuardedStringArray"] = new[]{secret, secret2};
            expectedData["Script"] = new ScriptBuilder { ScriptLanguage = "PowerShell", ScriptText = "echo 'Hello OpenICF Developer'" }.Build();
            expectedData["ScriptArray"] = new[]{new ScriptBuilder { ScriptLanguage = "Groovy", ScriptText = "println 'Hello'" }.Build(),new ScriptBuilder { ScriptLanguage = "Groovy", ScriptText = "println 'OpenICF Developer'" }.Build()};

            Environment.SetEnvironmentVariable(TestHelpers.TestConfigEVName, "converter");

            FieldInfo info = typeof (TestHelpers).GetField("_propertyBags", BindingFlags.NonPublic | BindingFlags.Static);
            (info.GetValue(null) as Dictionary<string, PropertyBag>).Clear();

            PropertyBag propertyBag =
                TestHelpers.GetProperties(typeof(Org.IdentityConnectors.TestConnector.FakeConnector));
            (info.GetValue(null) as Dictionary<string, PropertyBag>).Clear();

            APIConfiguration testable = TestHelpers.CreateTestConfiguration(SafeType<Connector>.Get<Org.IdentityConnectors.TestConnector.FakeConnector>(), propertyBag, null);

            foreach (KeyValuePair<string, object> entry in expectedData)
            {
                Assert.AreEqual(entry.Value, testable.ConfigurationProperties.GetProperty(entry.Key).Value, "Configuration property: " + entry.Key + " has different value");
            }
        }
 /// <summary>
 /// Highly insecure method! Do not do this in production
 /// code.
 /// </summary>
 /// <remarks>
 /// This is only for test purposes
 /// </remarks>
 private byte[] DecryptToByteArray(GuardedByteArray str)
 {
     byte[] result = null;
     str.Access(
                                     array =>
                                     {
                                         result = new byte[array.Length];
                                         for (int i = 0; i < array.Length; i++)
                                         {
                                             result[i] = array[i];
                                         }
                                     });
     return result;
 }
 private object ConvertFromString(string sourceValue, Type target)
 {
     if (typeof(string) == target)
     {
         return(Convert.ChangeType(sourceValue, target));
     }
     else if (typeof(long) == target)
     {
         return(Convert.ChangeType(sourceValue, target));
     }
     else if (typeof(long?) == target)
     {
         if (StringUtil.IsBlank(sourceValue))
         {
             return(null);
         }
         else
         {
             return(Convert.ChangeType(sourceValue, typeof(long)));
         }
     }
     else if (typeof(char) == target)
     {
         return(Convert.ChangeType(sourceValue, target));
     }
     else if (typeof(char?) == target)
     {
         if (StringUtil.IsBlank(sourceValue))
         {
             return(null);
         }
         else
         {
             return(Convert.ChangeType(sourceValue, typeof(char)));
         }
     }
     else if (typeof(double) == target)
     {
         return(Convert.ChangeType(sourceValue, target));
     }
     else if (typeof(double?) == target)
     {
         if (StringUtil.IsBlank(sourceValue))
         {
             return(null);
         }
         else
         {
             return(Convert.ChangeType(sourceValue, typeof(double)));
         }
     }
     else if (typeof(float) == target)
     {
         return(Convert.ChangeType(sourceValue, target));
     }
     else if (typeof(float?) == target)
     {
         if (StringUtil.IsBlank(sourceValue))
         {
             return(null);
         }
         else
         {
             return(Convert.ChangeType(sourceValue, typeof(float)));
         }
     }
     else if (typeof(int) == target)
     {
         return(Convert.ChangeType(sourceValue, target));
     }
     else if (typeof(int?) == target)
     {
         if (StringUtil.IsBlank(sourceValue))
         {
             return(null);
         }
         else
         {
             return(Convert.ChangeType(sourceValue, typeof(int)));
         }
     }
     else if (typeof(bool) == target)
     {
         return(Convert.ChangeType(sourceValue, target));
     }
     else if (typeof(bool?) == target)
     {
         if (StringUtil.IsBlank(sourceValue))
         {
             return(null);
         }
         else
         {
             return(Convert.ChangeType(sourceValue, typeof(bool)));
         }
     }
     else if (typeof(Uri) == target)
     {
         return(new Uri(sourceValue));
     }
     else if (typeof(FileName) == target)
     {
         return(new FileName(sourceValue));
     }
     else if (typeof(GuardedByteArray) == target)
     {
         var result = new GuardedByteArray();
         System.Text.Encoding.UTF8.GetBytes(sourceValue).ToList().ForEach(result.AppendByte);
         return(result);
     }
     else if (typeof(GuardedString) == target)
     {
         var result = new GuardedString();
         sourceValue.ToCharArray().ToList().ForEach(result.AppendChar);
         return(result);
     }
     else if (typeof(Script) == target)
     {
         int i = sourceValue.IndexOf('|');
         if (i > 0 && i < sourceValue.Length)
         {
             var scriptLanguage = sourceValue.Substring(0, i);
             var scriptText     = sourceValue.Substring(i + 1);
             return(new ScriptBuilder {
                 ScriptLanguage = scriptLanguage, ScriptText = scriptText
             }.Build());
         }
         else
         {
             throw new FormatException("Expected format is 'ScriptLanguage|ScriptText'");
         }
     }
     throw new NotSupportedException("The conversion cannot be performed.");
 }