Example #1
0
 public void XmlFileIsNotZipFile()
 {
     TestFileName = _testXmlFileName;
     TestFileName.CreateFileFromEmbeddedStream(TestFilepath, EmbeddedTestFilePath);
     using (_zipbomb = new ZipBomb(TestFilepath, 5))
     {
         _zipbomb.Inspect();
         _zipbomb.CanDispose = true;
     };
     Assert.IsFalse(_zipbomb.IsZipFile);
     Assert.IsFalse(_zipbomb.IsZipBomb);
 }
Example #2
0
 public void SetThreasholdTooLargeShouldThrowException()
 {
     TestFileName = TestZipBombFileName;
     TestFileName.CreateFileFromEmbeddedStream(TestFilepath, EmbeddedTestFilePath);
     using (_zipbomb = new ZipBomb(TestFilepath, 2001))
     {
         _zipbomb.ThrowException = true;
         _zipbomb.Inspect();
         _zipbomb.CanDispose = true;
     };
     Assert.IsTrue(_zipbomb.IsZipFile);
 }
Example #3
0
 public void FileIsZipBombPassWrongPasswordShouldThrowException()
 {
     TestFileName = TestZipBombFileName;
     TestFileName.CreateFileFromEmbeddedStream(TestFilepath, EmbeddedTestFilePath);
     using (_zipbomb = new ZipBomb(TestFilepath, 5, "---", null, true))
     {
         _zipbomb.ThrowException = true;
         _zipbomb.Inspect();
         _zipbomb.CanDispose = true;
     };
     Assert.IsTrue(_zipbomb.IsZipFile);
 }
Example #4
0
 public void RecurseZipWalkTest()
 {
     TestFileName = SourceZipfileName;
     TestFileName.CreateFileFromEmbeddedStream(TestFilepath, EmbeddedTestFilePath);
     using (var zipWalker = new ZipWalker(this,
                                          new[] { TestFilepath },
                                          2))
     {
         zipWalker.Inspect();
         Assert.AreEqual(zipWalker.CurrentDeepLevel, 1);
         zipWalker.CanDispose = true;//clear the results
     }
 }
Example #5
0
 public void RecurseUnZipMultipeArchiveTypesTest()
 {
     TestFileName = TestZipFileName;
     TestFileName.CreateFileFromEmbeddedStream(TestFilepath, EmbeddedTestFilePath);
     using (var zipWalker = new ZipWalker(this,
                                          new[] { TestFilepath },
                                          2))
     {
         zipWalker.Inspect();
         Assert.AreEqual(zipWalker.CurrentDeepLevel, 1);
         zipWalker.CanDispose = true;
     }
 }
Example #6
0
 public void FileIsZipBomb()
 {
     TestFileName = TestZipBombFileName;
     TestFileName.CreateFileFromEmbeddedStream(TestFilepath, EmbeddedTestFilePath);
     using (_zipbomb = new ZipBomb(TestFilepath,
                                   3,
                                   GlobalDefinitions.DefaultInfectedPassword))
     {
         _zipbomb.Inspect();
         _zipbomb.CanDispose = true;
     };
     Assert.IsTrue(_zipbomb.IsZipFile);
     Assert.IsTrue(_zipbomb.IsZipBomb);
 }
Example #7
0
 public void UnpackedSizeAcceptable()
 {
     TestFileName = TestZipBombFileName;
     TestFileName.CreateFileFromEmbeddedStream(TestFilepath, EmbeddedTestFilePath);
     using (_zipbomb = new ZipBomb(TestFilepath,
                                   5,
                                   null,
                                   600000))
     {
         _zipbomb.Inspect();
         _zipbomb.CanDispose = true;
     };
     Assert.IsTrue(_zipbomb.IsZipFile);
     Assert.IsFalse(_zipbomb.IsUnpackedSizeTooLarge);
 }
Example #8
0
 public void SizeSetTooSmalTheNormaZipFileShowAsZipbomb()
 {
     TestFileName = TestZipFileName;
     TestFileName.CreateFileFromEmbeddedStream(TestFilepath, EmbeddedTestFilePath);
     using (_zipbomb = new ZipBomb(TestFilepath,
                                   5,
                                   GlobalDefinitions.DefaultInfectedPassword,
                                   100000))
     {
         _zipbomb.Inspect();
         _zipbomb.CanDispose = true;
     };
     Assert.IsTrue(_zipbomb.IsZipFile);
     Assert.IsTrue(_zipbomb.IsZipBomb);
     Assert.IsTrue(_zipbomb.IsUnpackedSizeTooLarge);
 }
Example #9
0
        public void MultiThreadMimic()
        {
            TestFileName = TestZipBombFileName;
            TestFileName.CreateFileFromEmbeddedStream(TestFilepath, EmbeddedTestFilePath);
            var tasklist    = new List <Task>();
            var sourcefiles = new List <string>();

            Parallel.Invoke(new ParallelOptions {
                MaxDegreeOfParallelism = 10
            }, () =>
            {
                tasklist.Add(Task.Factory.StartNew(() =>
                {
                    for (int i = 0; i < 2; ++i)
                    {
                        var sourcefileName = string.Format(@"{0}_{1}.zip", Path.GetFullPath(TestFilepath).Replace(@".zip", string.Empty), i);
                        File.Copy(TestFilepath, sourcefileName, true);
                        sourcefiles.Add(sourcefileName);
                        using (var zipbomb = new ZipBomb(TestFilepath,
                                                         3,
                                                         GlobalDefinitions.DefaultInfectedPassword))
                        {
                            zipbomb.Inspect();
                            Assert.IsTrue(zipbomb.IsZipFile);
                            Assert.IsTrue(zipbomb.IsZipBomb);
                            zipbomb.CanDispose = true;
                        };
                    }
                }
                                                   ));
            });
            Task.WaitAll(tasklist.ToArray(), new TimeSpan(0, 0, 100));

            sourcefiles.ForEach(x =>
            {
                if (File.Exists(x))
                {
                    File.Delete(x);
                }
            });
        }