Ejemplo n.º 1
0
        public static Dictionary <string, bool> TestExecutionProxys()
        {
            Dictionary <string, bool> results = new Dictionary <string, bool>();

            Type     parentType = typeof(Tonsil.Processes.ExecutionProxys.ExecutionProxy);
            Assembly assembly   = parentType.Assembly;

            Type[]             types      = assembly.GetTypes();
            IEnumerable <Type> subclasses = types.Where(t => t.IsSubclassOf(parentType));

            foreach (Type type in subclasses)
            {
                Tonsil.Processes.Process targetProcess = new Notepad();
                Tonsil.Processes.ExecutionProxys.ExecutionProxy processUnderTest = (Tonsil.Processes.ExecutionProxys.ExecutionProxy)Activator.CreateInstance(type);
                processUnderTest.AddCmdlineExecution(targetProcess);
                bool result = TestExecutionProxy(processUnderTest, targetProcess);
                Console.WriteLine(string.Format("{1}: \t{0}", processUnderTest.CmdLine.ToString(), result ? "Pass" : "Fail"));
                results.Add(processUnderTest.CmdLine.ToString(), result);
            }
            return(results);
        }
Ejemplo n.º 2
0
        public static Dictionary <string, bool> TestExecutionProxyDownloaders()
        {
            Dictionary <string, bool> results = new Dictionary <string, bool>();

            string serverHost = "10.141.41.1";

            Tonsil.Files.HttpFilePath httpFilePath = new Tonsil.Files.HttpFilePath()
            {
                Host      = serverHost,
                Port      = 80,
                Directory = "/somedir/",
                Filename  = "somefile.vbs"
            };
            Tonsil.Files.SmbFilePath smbFilePath = new Tonsil.Files.SmbFilePath()
            {
                Host      = serverHost,
                Port      = 445,
                ShareName = "someshare",
                Directory = @"\somedir\",
                Filename  = "somefile.vbs"
            };
            Tonsil.Files.LocalFilePath localFilePath = new Tonsil.Files.LocalFilePath()
            {
                Directory = @"c:\",
                Filename  = "somefile.vbs"
            };

            List <Tonsil.Files.FilePath> filePaths = new List <Tonsil.Files.FilePath>()
            {
                httpFilePath, smbFilePath
            };

            Tonsil.Files.File destinationFile = new Tonsil.Files.File()
            {
                FileType = Tonsil.Files.FileType.VBScript,
                FilePath = localFilePath
            };

            Type     downloaderParentType = typeof(Tonsil.Processes.Downloaders.Downloader);
            Assembly assembly             = downloaderParentType.Assembly;

            Type[]             types = assembly.GetTypes();
            IEnumerable <Type> downloaderSubclasses     = types.Where(t => t.IsSubclassOf(downloaderParentType));
            Type executionProxyParentType               = typeof(Tonsil.Processes.ExecutionProxys.ExecutionProxy);
            IEnumerable <Type> executionProxySubclasses = types.Where(t => t.IsSubclassOf(executionProxyParentType));

            foreach (Type executionProxyType in executionProxySubclasses)
            {
                foreach (Type downloaderType in downloaderSubclasses)
                {
                    foreach (var filePath in filePaths)
                    {
                        Tonsil.Files.File sourceFile = new Tonsil.Files.File()
                        {
                            FilePath = filePath
                        };
                        Tonsil.Processes.Downloaders.Downloader downloadProcessUnderTest = (Tonsil.Processes.Downloaders.Downloader)Activator.CreateInstance(downloaderType);
                        if (downloadProcessUnderTest.IsValidSource(sourceFile) && downloadProcessUnderTest.IsValidDestination(sourceFile, destinationFile))
                        {
                            downloadProcessUnderTest.AddDownload(sourceFile, destinationFile);

                            Tonsil.Processes.Process targetProcess = downloadProcessUnderTest;
                            Tonsil.Processes.ExecutionProxys.ExecutionProxy processUnderTest = (Tonsil.Processes.ExecutionProxys.ExecutionProxy)Activator.CreateInstance(executionProxyType);
                            processUnderTest.AddCmdlineExecution(targetProcess);
                            bool result = TestDownloader(processUnderTest, sourceFile, destinationFile);
                            Console.WriteLine(string.Format("{1}: \t{0}", processUnderTest.CmdLine.ToString(), result ? "Pass" : "Fail"));
                            results.Add(processUnderTest.CmdLine.ToString(), result);
                        }
                    }
                }
            }
            return(results);
        }