Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            using var engine = new FilteringEngine();

            //init and clear existing filters
            engine.Initialize();
            engine.ClearFilters();

            //prevent port scanning
            engine.SetSilentBlockInV4();
            engine.SetSilentBlockInV6();

            //block all incoming connections
            engine.AddFilterInV4(false);
            engine.AddFilterInV6(false);

            //allow all outgoing connections
            engine.AddFilterOutV4(true);
            engine.AddFilterOutV6(true);

            //allow incoming ping requests
            engine.AddFilterInV4(true, new[] { Native.IPPROTO.ICMP });

            //allow incoming requests for DNS, HTTP, HTTPS
            engine.AddFilterInV4(true, new[] { Native.IPPROTO.TCP }, new[] { "53", "80", "443" });

            //allow SMB and RDP incoming connections for specified network
            engine.AddFilterInV4(true, new[] { Native.IPPROTO.TCP }, new[] { "445", "3389" }, new[] { "192.168.1.0/24" });
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var data       = GetDataSource();
            var conditions = GetConditions();
            var mappings   = GetMappings();

            var filteringEngine = new FilteringEngine();

            var filtered = filteringEngine.Filter(data, conditions);

            PrintCollection(filtered, "Filtered:");

            var selectionEngine = new SelectionEngine();

            var selection = selectionEngine.Select <Person, SelectionType>(filtered, mappings);

            PrintCollection(selection, "Selected:");
        }
        /// <summary>
        /// Partition functional tests.
        /// </summary>
        /// <param name="tests">Tests to distribute</param>
        /// <param name="machines">Machines to distribute to</param>
        /// <param name="testBinariesDirectory">Location of test binaries.</param>
        /// <returns>List of TestCollection partitioned</returns>
        public override List <TestRecords> PartitionTests(TestRecords tests, MachineRecord[] machines, DirectoryInfo testBinariesDirectory)
        {
            // We use a round-robin distribution pattern. The algorithm is simple
            // and does a good job of balancing load barring pathological
            // examples, but has the downside of minimizing spatial locality.

            Profiler.StartMethod();

            if (machines.Length <= 0)
            {
                throw new ArgumentException("At least one machine must be specified for distribution.", "machines");
            }

            List <TestRecords> collections = new List <TestRecords>();

            for (int i = 0; i < machines.Length; i++)
            {
                collections.Add(new TestRecords());
            }

            int machineIndex          = 0;
            int testIndex             = 0;
            int distributionFailCount = 0;

            while (testIndex < tests.TestCollection.Count)
            {
                // If the next test to be distributed can be run on the next machine
                // in our round-robin queue, we'll add it. Additionally, if the
                // distributionFailCount is greater than the number of machines, we've
                // tried to distribute it to each machine, and they have all said that
                // they can't run it. In this case, we'll just say to ---- with it and
                // give it to the current machine anyways and continue. Filtering down
                // the line will ensure the test won't actually be run.
                if (MachineCanRunTest(tests.TestCollection[testIndex], machines[machineIndex], testBinariesDirectory) || distributionFailCount > machines.Length)
                {
                    tests.TestCollection[testIndex].Machine = machines[machineIndex];
                    collections[machineIndex].TestCollection.Add(tests.TestCollection[testIndex]);
                    testIndex++;
                    distributionFailCount = 0;
                }
                else
                {
                    distributionFailCount++;
                }

                // Move on to next machine, and wrap around as appropriate.
                machineIndex = (machineIndex + 1) % machines.Length;
            }

            // Now that we've distributed tests to machines, send them all
            // through configuration filtering so any tests that couldn't be
            // matched to a satisfactory machine get marked to not execute.
            foreach (TestRecords collection in collections)
            {
                foreach (TestRecord test in collection.TestCollection)
                {
                    FilteringEngine.FilterConfigurations(test, testBinariesDirectory);
                }
            }

            Profiler.EndMethod();

            return(collections);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Filter a collection of test cases. Goes through each TestRecord
 /// and verifies its TestInfo passes the filtering settings. If it
 /// does not, marks the TestRecord as not enabled for execution,
 /// and provides an explanation.
 /// </summary>
 /// <param name="filteringSettings">Filter to evaluate TestRecord against.</param>
 /// <param name="testBinariesDirectory"/>
 public void Filter(FilteringSettings filteringSettings, DirectoryInfo testBinariesDirectory)
 {
     Profiler.StartMethod();
     FilteringEngine.Filter(filteringSettings, this, testBinariesDirectory);
     Profiler.EndMethod();
 }