public void TestFileCollector()
        {
            var testFolder = AsaHelpers.GetTempFolder();

            Directory.CreateDirectory(testFolder);

            var opts = new CollectCommandOptions()
            {
                EnableFileSystemCollector = true,
                GatherHashes        = true,
                SelectedDirectories = testFolder,
                DownloadCloud       = false,
            };

            using (var file = File.Open(Path.Combine(testFolder, "AsaLibTesterMZ"), FileMode.OpenOrCreate))
            {
                file.Write(FileSystemUtils.WindowsMagicNumber, 0, 2);
                file.Write(FileSystemUtils.WindowsMagicNumber, 0, 2);

                file.Close();
            }

            using (var file = File.Open(Path.Combine(testFolder, "AsaLibTesterJavaClass"), FileMode.OpenOrCreate))
            {
                file.Write(FileSystemUtils.JavaMagicNumber, 0, 4);
                file.Close();
            }

            var fsc = new FileSystemCollector(opts);

            fsc.Execute();

            Assert.IsTrue(fsc.Results.Any(x => x is FileSystemObject FSO && FSO.Path.EndsWith("AsaLibTesterJavaClass") && FSO.IsExecutable == true));
            Assert.IsTrue(fsc.Results.Any(x => x is FileSystemObject FSO && FSO.Path.EndsWith("AsaLibTesterMZ") && FSO.IsExecutable == true));
        }
예제 #2
0
        public void TestFileCollector()
        {
            Setup();

            var FirstRunId  = "TestFileCollector-1";
            var SecondRunId = "TestFileCollector-2";

            var testFolder = AsaHelpers.GetTempFolder();

            Directory.CreateDirectory(testFolder);

            var opts = new CollectCommandOptions()
            {
                RunId = FirstRunId,
                EnableFileSystemCollector = true,
                GatherHashes          = true,
                SelectedDirectories   = testFolder,
                DownloadCloud         = false,
                CertificatesFromFiles = false
            };

            var fsc = new FileSystemCollector(opts);

            fsc.Execute();

            using (var file = File.Open(Path.Combine(testFolder, "AsaLibTesterMZ"), FileMode.OpenOrCreate))
            {
                file.Write(FileSystemUtils.WindowsMagicNumber, 0, 2);
                file.Write(FileSystemUtils.WindowsMagicNumber, 0, 2);

                file.Close();
            }

            using (var file = File.Open(Path.Combine(testFolder, "AsaLibTesterJavaClass"), FileMode.OpenOrCreate))
            {
                file.Write(FileSystemUtils.JavaMagicNumber, 0, 4);
                file.Close();
            }

            opts.RunId = SecondRunId;

            fsc = new FileSystemCollector(opts);
            fsc.Execute();

            BaseCompare bc = new BaseCompare();

            if (!bc.TryCompare(FirstRunId, SecondRunId))
            {
                Assert.Fail();
            }

            var results = bc.Results;

            Assert.IsTrue(results.ContainsKey("FILE_CREATED"));
            Assert.IsTrue(results["FILE_CREATED"].Where(x => x.Identity.Contains("AsaLibTesterMZ") && ((FileSystemObject)x.Compare).IsExecutable == true).Any());
            Assert.IsTrue(results["FILE_CREATED"].Where(x => x.Identity.Contains("AsaLibTesterJavaClass") && ((FileSystemObject)x.Compare).IsExecutable == true).Any());

            TearDown();
        }
예제 #3
0
        public void TestFileCompare()
        {
            var FirstRunId  = "TestFileCollector-1";
            var SecondRunId = "TestFileCollector-2";

            var testFolder = AsaHelpers.GetTempFolder();

            Directory.CreateDirectory(testFolder);

            var opts = new CollectCommandOptions()
            {
                RunId = FirstRunId,
                EnableFileSystemCollector = true,
                GatherHashes        = true,
                SelectedDirectories = testFolder,
                DownloadCloud       = false,
            };

            var fsc = new FileSystemCollector(opts);

            fsc.Execute();

            using (var file = File.Open(Path.Combine(testFolder, "AsaLibTesterMZ"), FileMode.OpenOrCreate))
            {
                file.Write(FileSystemUtils.WindowsMagicNumber, 0, 2);
                file.Write(FileSystemUtils.WindowsMagicNumber, 0, 2);

                file.Close();
            }

            using (var file = File.Open(Path.Combine(testFolder, "AsaLibTesterJavaClass"), FileMode.OpenOrCreate))
            {
                file.Write(FileSystemUtils.JavaMagicNumber, 0, 4);
                file.Close();
            }

            opts.RunId = SecondRunId;

            var fsc2 = new FileSystemCollector(opts);

            fsc2.Execute();

            Assert.IsTrue(fsc2.Results.Any(x => x is FileSystemObject FSO && FSO.Path.EndsWith("AsaLibTesterMZ") && FSO.IsExecutable == true));
            Assert.IsTrue(fsc2.Results.Any(x => x is FileSystemObject FSO && FSO.Path.EndsWith("AsaLibTesterJavaClass") && FSO.IsExecutable == true));

            BaseCompare bc = new BaseCompare();

            bc.Compare(fsc.Results, fsc2.Results, FirstRunId, SecondRunId);
            var results = bc.Results;

            Assert.IsTrue(results.ContainsKey((RESULT_TYPE.FILE, CHANGE_TYPE.CREATED)));
            Log.Debug(JsonConvert.SerializeObject(results));
            Assert.IsTrue(results[(RESULT_TYPE.FILE, CHANGE_TYPE.CREATED)].Any(x => x.Compare is FileSystemObject FSO && FSO.Identity.Contains("AsaLibTesterMZ") && FSO.IsExecutable == true));
        public void TestFileCompare()
        {
            var FirstRunId  = "TestFileCollector-1";
            var SecondRunId = "TestFileCollector-2";

            var testFolder = AsaHelpers.GetTempFolder();

            Directory.CreateDirectory(testFolder);

            var opts = new CollectCommandOptions()
            {
                RunId = FirstRunId,
                EnableFileSystemCollector = true,
                GatherHashes          = true,
                SelectedDirectories   = testFolder,
                DownloadCloud         = false,
                CertificatesFromFiles = false
            };

            var fsc = new FileSystemCollector(opts);

            fsc.Execute();

            fsc.Results.AsParallel().ForAll(x => DatabaseManager.Write(x, FirstRunId));

            using (var file = File.Open(Path.Combine(testFolder, "AsaLibTesterMZ"), FileMode.OpenOrCreate))
            {
                file.Write(FileSystemUtils.WindowsMagicNumber, 0, 2);
                file.Write(FileSystemUtils.WindowsMagicNumber, 0, 2);

                file.Close();
            }

            using (var file = File.Open(Path.Combine(testFolder, "AsaLibTesterJavaClass"), FileMode.OpenOrCreate))
            {
                file.Write(FileSystemUtils.JavaMagicNumber, 0, 4);
                file.Close();
            }

            opts.RunId = SecondRunId;

            fsc = new FileSystemCollector(opts);
            fsc.Execute();

            Assert.IsTrue(fsc.Results.Any(x => x is FileSystemObject FSO && FSO.Path.EndsWith("AsaLibTesterMZ")));
            Assert.IsTrue(fsc.Results.Any(x => x is FileSystemObject FSO && FSO.Path.EndsWith("AsaLibTesterJavaClass")));

            fsc.Results.AsParallel().ForAll(x => DatabaseManager.Write(x, SecondRunId));

            while (DatabaseManager.HasElements)
            {
                Thread.Sleep(1);
            }

            BaseCompare bc = new BaseCompare();

            if (!bc.TryCompare(FirstRunId, SecondRunId))
            {
                Assert.Fail();
            }

            var results = bc.Results;

            Assert.IsTrue(results.ContainsKey((RESULT_TYPE.FILE, CHANGE_TYPE.CREATED)));
            Assert.IsTrue(results[(RESULT_TYPE.FILE, CHANGE_TYPE.CREATED)].Any(x => x.Identity.Contains("AsaLibTesterMZ") && ((FileSystemObject)x.Compare).IsExecutable == true));