Ejemplo n.º 1
0
        public void TestCleanPdfExcludeAttachments()
        {
            var lcfm = new LocalCopyOfFileManager();
            var sourceFile = Path.Combine(TestRoot, "Comments_Bookmarks_Attachments_Markups.pdf");
            var testFile = lcfm.GetLocalCopyOfFileTarget(sourceFile);

            File.Copy(sourceFile, testFile, true);

            var attachment = new ProtectAttachment(FcsFileFactory.Create(testFile, "Comments_Bookmarks_Attachments_Markups"));

            var discoveryTask = new TaskDiscovery(attachment);
            discoveryTask.Execute(new CancellationToken());

            Assert.IsTrue(attachment.RiskAnalysis.DiscoveryResult.GetItemsForType(MetadataType.Attachments).Count > 0);
            Assert.IsTrue(attachment.RiskAnalysis.DiscoveryResult.GetItemsForType(MetadataType.Properties).Count > 0);
            Assert.IsTrue(attachment.RiskAnalysis.DiscoveryResult.GetItemsForType(MetadataType.Bookmarks).Count > 0);
            Assert.IsTrue(attachment.RiskAnalysis.DiscoveryResult.GetItemsForType(MetadataType.Markups).Count > 0);

            var task = new TaskCleanPdf(attachment, new TaskCleanOptions() { ExcludedMetadataTypes = new List<MetadataType>() { MetadataType.Attachments}});
            task.Execute(new CancellationToken());

            discoveryTask.Execute(new CancellationToken());
            Assert.IsTrue(attachment.RiskAnalysis.DiscoveryResult.GetItemsForType(MetadataType.Attachments).Count > 0);
            Assert.IsFalse(attachment.RiskAnalysis.High.ContainsKey(MetadataType.Properties));
            Assert.IsFalse(attachment.RiskAnalysis.High.ContainsKey(MetadataType.Bookmarks));
            Assert.IsFalse(attachment.RiskAnalysis.High.ContainsKey(MetadataType.Markups));

            Assert.IsFalse(attachment.RiskAnalysis.Medium.ContainsKey(MetadataType.Properties));
            Assert.IsFalse(attachment.RiskAnalysis.Medium.ContainsKey(MetadataType.Bookmarks));
            Assert.IsFalse(attachment.RiskAnalysis.Medium.ContainsKey(MetadataType.Markups));

            Assert.IsFalse(attachment.RiskAnalysis.Low.ContainsKey(MetadataType.Properties));
            Assert.IsFalse(attachment.RiskAnalysis.Low.ContainsKey(MetadataType.Bookmarks));
            Assert.IsFalse(attachment.RiskAnalysis.Low.ContainsKey(MetadataType.Markups));
        }
Ejemplo n.º 2
0
        public void TestDiscoveryWhiteTextCountIsCorrect()
        {
            using (var file = new SelfDeletingFile("3WhiteText.xlsx"))
            {
                var attachment = new ProtectAttachment(FcsFileFactory.Create(file.FileName, "3WhiteText.xlsx"));
                var task = new TaskDiscovery(attachment);
                task.Execute(new CancellationToken());
                Assert.IsNotNull(attachment.RiskAnalysis);
                Assert.IsNotNull(attachment.RiskAnalysis.DiscoveryResult);
                Assert.IsTrue(attachment.RiskAnalysis.HasMetaData);
                Assert.IsTrue(attachment.RiskAnalysis.DiscoveryResult.HasMetadataOfType(MetadataType.WhiteText));

                var whiteTexts = attachment.RiskAnalysis.DiscoveryResult.GetItemsForType(MetadataType.WhiteText);

                var foundText =
                    (from text in whiteTexts
                        from detail in text.Details
                        where detail.Name == "Content"
                        select detail.Value).ToList();

                Assert.IsTrue(foundText.Contains("White Text 1"));
                Assert.IsTrue(foundText.Contains("White Text 2"));
                Assert.IsTrue(foundText.Contains("White Text 3"));

                Assert.IsTrue(foundText.Count == 3);
            }
        }
Ejemplo n.º 3
0
 public void TestDiscoverDocument()
 {
     using (var file = new SelfDeletingFile("SmallTextComplexDocument.doc"))
     {
         var attachment = new ProtectAttachment(FcsFileFactory.Create(file.FileName, "SmallTextComplexDocument"));
         var task = new TaskDiscovery(attachment);
         task.Execute(new CancellationToken());
         Assert.IsNotNull(attachment.RiskAnalysis);
         Assert.IsNotNull(attachment.RiskAnalysis.DiscoveryResult);
         Assert.IsTrue(attachment.RiskAnalysis.HasMetaData);
     }
 }
Ejemplo n.º 4
0
        public void TestCleanStripsBinaryData()
        {
            var lcfm = new LocalCopyOfFileManager();
            var sourceFile = Path.Combine(TestRoot, "Small.doc");
            var testFile = lcfm.GetLocalCopyOfFileTarget(sourceFile);

            File.Copy(sourceFile, testFile, true);

            var attachment = new ProtectAttachment(FcsFileFactory.Create(testFile, "Small"));

            var discoveryTask = new TaskDiscovery(attachment);
            discoveryTask.Execute(new CancellationToken());

            Assert.IsTrue(attachment.RiskAnalysis.DiscoveryResult.GetItemsForType(MetadataType.DocumentStatistic).Count > 0);
            Assert.IsTrue(attachment.RiskAnalysis.DiscoveryResult.GetItemsForType(MetadataType.AttachedTemplate).Count > 0);

            var task = new TaskClean(attachment, new TaskCleanOptions());
            task.Execute(new CancellationToken());

            discoveryTask.Execute(new CancellationToken());
            Assert.IsFalse(attachment.RiskAnalysis.HasMetaData);

            new Workshare.API.Cleaning.OfficeApplicationCacheControl().ReleaseOfficeApplications();
        }
Ejemplo n.º 5
0
        public void TestCleanTrackChanges()
        {
            var lcfm = new LocalCopyOfFileManager();
            var sourceFile = Path.Combine(TestRoot, "SmallTextComplexDocument.doc");
            var testFile = lcfm.GetLocalCopyOfFileTarget(sourceFile);

            File.Copy(sourceFile, testFile, true);

            var attachment = new ProtectAttachment(FcsFileFactory.Create(testFile, "SmallTextComplexDocument"));

            var discoveryTask = new TaskDiscovery(attachment);
            discoveryTask.Execute(new CancellationToken());

            Assert.IsTrue(attachment.RiskAnalysis.DiscoveryResult.GetItemsForType(MetadataType.TrackedChange).Count > 0);

            var task = new TaskClean(attachment, new TaskCleanOptions());
            task.Execute(new CancellationToken());

            discoveryTask.Execute(new CancellationToken());
            Assert.IsNull(attachment.RiskAnalysis.DiscoveryResult.GetItemsForType(MetadataType.TrackedChange));
            Assert.IsNull(attachment.RiskAnalysis.DiscoveryResult.GetItemsForType(MetadataType.Comment));

            new Workshare.API.Cleaning.OfficeApplicationCacheControl().ReleaseOfficeApplications();
        }
Ejemplo n.º 6
0
        private void DiscoverAttachments(IEnumerable<IProtectAttachment> attachments)
        {
            foreach (var attachment in attachments)
            {
                try
                {
                    _marshaller.WaitOne();

                    if (IsCancellationPending)
                        return;

                    if (attachment.IsDiscoverable && !attachment.HasPassword)
                    {
                        var discovery = new TaskDiscovery(attachment);

                        RaiseEvent(StatusUpdate, new ActionEventArgs(discovery, PropertyNames.Progress));

                        discovery.Execute(_marshaller.CancellationToken);
                    }
                    else if (attachment.HasPassword)
                    {
                        RaiseEvent(StatusUpdate, new ActionEventArgs(attachment, PropertyNames.RequiresPassword));
                    }
                    else if (!FileTypeHelper.IsSupported(attachment.FileType))
                    {
                        RaiseEvent(StatusUpdate, new ActionEventArgs(attachment, PropertyNames.UnsupportedFileFormat));
                    }

                    if (IsCancellationPending)
                        return;

                    if (attachment.Children.Any())
                    {
                        DiscoverAttachments(attachment.Children);
                    }
                    else if (attachment.IsCollection && !attachment.HasPassword)
                    {
                        // Empty collections ie. a msg file with no attachments
                        RaiseEvent(StatusUpdate, new ActionEventArgs(attachment, PropertyNames.UnsupportedFileFormat));
                    }
                }
                catch (Exception e)
                {
                    Logger.LogError(e);
                    RaiseEvent(StatusUpdate, new ActionEventArgs(PropertyNames.Exception) { Exception = e });
                }
            }
        }