Пример #1
0
        public void DoublePackTest()
        {
            IFileSystem mockFileSystem = GenerateMockFileSystem();

            PeachFolderPackager packager = new PeachFolderPackager(mockFileSystem);

            byte[] packedBytes1 = packager.PackFolder(@"c:\logs\abc", new DateTime(0));
            byte[] packedBytes2 = packager.PackFolder(@"c:\logs\abc", new DateTime(0));

            Assert.IsTrue(packedBytes1.SequenceEqual(packedBytes2));
        }
Пример #2
0
        public void MultiFolderNothingModifiedTest()
        {
            IFileSystem mockFileSystem = GenerateMockFileSystem();

            PeachFolderPackager packager = new PeachFolderPackager(mockFileSystem);

            byte[] packedBytes = packager.PackFolder(@"c:\logs", _checkpoints[4].ToUniversalTime());

            MockFileSystem destinationFileSystem = new MockFileSystem();
            FolderUnpacker unpackager            = new FolderUnpacker(destinationFileSystem, "xyz");

            unpackager.UnpackFolder(@"c:\collectedlogs", packedBytes);

            Assert.AreEqual(0, destinationFileSystem.GetTotalFileCount());
            Assert.IsNull(unpackager.GetStatusFileStream());
        }
Пример #3
0
        public void DateAllExcludedPackUnpackTest()
        {
            IFileSystem mockFileSystem = GenerateMockFileSystem();

            PeachFolderPackager packager = new PeachFolderPackager(mockFileSystem);

            byte[] packedBytes = packager.PackFolder(@"c:\logs\", _checkpoints[3].ToUniversalTime());

            MockFileSystem destinationFileSystem = new MockFileSystem();
            FolderUnpacker unpackager            = new FolderUnpacker(destinationFileSystem, "xyz");

            unpackager.UnpackFolder(@"c:\collectedlogs\", packedBytes);

            //
            // No files should have been packed as none were modified after checkpoint 3.
            //

            Assert.AreEqual(0, destinationFileSystem.GetTotalFileCount());
        }
Пример #4
0
        public void SingleFolderNullModifiedDatePackUnpackTest()
        {
            IFileSystem mockFileSystem = GenerateMockFileSystem();

            PeachFolderPackager packager = new PeachFolderPackager(mockFileSystem);

            byte[] packedBytes = packager.PackFolder(@"c:\logs\abc", new DateTime(0));

            MockFileSystem destinationFileSystem = new MockFileSystem();
            FolderUnpacker unpackager            = new FolderUnpacker(destinationFileSystem, "xyz");

            unpackager.UnpackFolder(@"c:\collectedlogs", packedBytes);

            Assert.AreEqual(4, destinationFileSystem.GetTotalFileCount());
            Assert.IsTrue(destinationFileSystem.FileExists(@"c:\collectedlogs\status-xyz.txt"));
            Assert.IsTrue(destinationFileSystem.FileExists(@"c:\collectedlogs\Faults\1\oatmeal.txt"));
            Assert.IsTrue(destinationFileSystem.FileExists(@"c:\collectedlogs\Faults\2\potatoes.txt"));
            Assert.IsTrue(destinationFileSystem.FileExists(@"c:\collectedlogs\Faults\3\carrots.txt"));

            Assert.IsNotNull(unpackager.GetStatusFileStream());
        }
Пример #5
0
        public void DirectoryTraversalTest()
        {
            //
            // This test should throw an exception because the package is attempting to cause FolderUnpacker to unpack outside of
            // the destination folder.
            //

            MockFileSystem mockFileSystem = new MockFileSystem();

            mockFileSystem.AddMockFile(@"c:\root\status.txt", new DateTime(2012, 5, 15, 2, 15, 08), "this is the status.");
            mockFileSystem.AddMockFile(@"c:\root\..\evil.dat", new DateTime(2012, 5, 15, 2, 15, 08), "this is an evil file that's attempting to do directory traversal.");

            PeachFolderPackager packager = new PeachFolderPackager(mockFileSystem);

            byte[] packedBytes = packager.PackFolder(@"c:\root", new DateTime(0));

            MockFileSystem destinationFileSystem = new MockFileSystem();
            FolderUnpacker unpackager            = new FolderUnpacker(destinationFileSystem, "xyz");

            unpackager.UnpackFolder(@"c:\collectedlogs", packedBytes);
        }
Пример #6
0
        public void DuplicateFileTest()
        {
            IFileSystem mockFileSystem = GenerateMockFileSystem();

            PeachFolderPackager packager = new PeachFolderPackager(mockFileSystem);

            byte[] packedBytes = packager.PackFolder(@"c:\logs", new DateTime(0));

            ZipArchive packedArchive = new ZipArchive(new MemoryStream(packedBytes));

            int oatmealFiles = 0;

            for (int i = 0; i < packedArchive.Entries.Count; i++)
            {
                ZipArchiveEntry entry = packedArchive.Entries[i];
                if (entry.FullName.Equals(@"Faults\1\oatmeal.txt"))
                {
                    oatmealFiles++;
                }
            }

            Assert.AreEqual(1, oatmealFiles);
        }
Пример #7
0
        public void DateSeparatedPackUnpackTest()
        {
            IFileSystem mockFileSystem = GenerateMockFileSystem();

            PeachFolderPackager packager = new PeachFolderPackager(mockFileSystem);

            byte[] packedBytes = packager.PackFolder(@"c:\logs\abc\", _checkpoints[0].ToUniversalTime());

            MockFileSystem destinationFileSystem = new MockFileSystem();
            FolderUnpacker unpackager            = new FolderUnpacker(destinationFileSystem, "xyz");

            unpackager.UnpackFolder(@"c:\collectedlogs\", packedBytes);

            //
            // Only 2 files should have been packed as they were the only ones modified after
            // checkpoint 0.
            //

            Assert.AreEqual(2, destinationFileSystem.GetTotalFileCount());
            Assert.IsTrue(destinationFileSystem.FileExists(@"c:\collectedlogs\status-xyz.txt"));
            Assert.IsTrue(destinationFileSystem.FileExists(@"c:\collectedlogs\Faults\3\carrots.txt"));

            Assert.IsNotNull(unpackager.GetStatusFileStream());
        }