Ejemplo n.º 1
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.º 2
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.º 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
       // [Test]
        public void TestPdfDoesntOverwriteOtherFileWithSameName()
        {
            var attachment =
                new ProtectAttachment(TestUtils.CreateAttachment("FilesWithSameName.zip", "FilesWithSameName.zip", "1"));
            var attachments = new ObservableCollection<IProtectAttachment>()
                                  {
                                      attachment
                                  };

            var actionQueue = new ActionQueue();

            bool discoveryCompleted = false;
            bool appliedAllActions = false;
            actionQueue.StatusUpdate += (sender, args) =>
            {
                if (args.Status == PropertyNames.DiscoveryCompleted)
                {
                    discoveryCompleted = true;
                }

                if (args.Status == PropertyNames.AppliedAllActions) 
                {
                    appliedAllActions = true;
                }
            };

            actionQueue.Discover(attachments.ToList());

            SpinWait.SpinUntil(() => discoveryCompleted, 90000);
            Assert.IsTrue(discoveryCompleted, "Discovery failed to complete.");

            var xlsx = attachment.Children.First(x => x.FileName.Contains(".xlsx"));

            var options = new Dictionary<string, dynamic> {{PropertyNames.PdfFormat, PropertyValues.PdfA}};

            var pdf = WorkshareTaskFactory.CreatePdfTask(xlsx, options);
            var task = new TaskRepack(attachments);
            
            actionQueue.ApplyTasks(new List<IWorkshareTask>()
                                       {
                                           pdf,
                                           task
                                       });

            SpinWait.SpinUntil(() => appliedAllActions, 90000);
            Assert.IsTrue(appliedAllActions, "Failed to apply all actions within the time limit");
            new Workshare.API.Cleaning.OfficeApplicationCacheControl().ReleaseOfficeApplications();

            VerifyFilesAreNotEqual(attachment.FileName);

            SpinWait.SpinUntil(TestUtils.HasOfficeShutDown, 60000);
        }
Ejemplo n.º 5
0
        public void TestExpand()
        {
            using (var file = new SelfDeletingFile("small.zip"))
            {
                var attachment1 = new ProtectAttachment(FcsFileFactory.Create(file.FileName, "small"));

                var task1 = new TaskExtract(attachment1);
                task1.Execute(new CancellationToken());

                Assert.IsTrue(attachment1.Children.Any());

                Assert.IsNotNull(attachment1.Children.FirstOrDefault(x => x.Name == "Memory Usage in Protect.docx"));
                Assert.IsNotNull(attachment1.Children.FirstOrDefault(x => x.Name == "Sample Document_OriginalFile.docx"));

            }
        }
Ejemplo n.º 6
0
        public void TestDocumentTracking()
        {
            var filenames = new List<string>()
                { 
                    "SupportsCleaning.doc",
                    "5DocStats2BuiltInProps.docx",
                    "హాయ్ .docx",
                    "SmallTextComplexDocument.doc",
                    "small.doc",
                    "final.docx",
                    "15Footnotes1Field5DocStats2BuiltInProps.docx"
                };

            filenames.ForEach(delegate(string x)
                {
                    var id = String.Empty;
                    try
                    {
                        var lcfm = new LocalCopyOfFileManager();
                        var sourceFile = Path.Combine(TestRoot, x);
                        Assert.IsTrue(File.Exists(sourceFile), String.Format("File does not exist [{0}]", sourceFile));

                        var testFile = lcfm.GetLocalCopyOfFileTarget(x);
                        File.Copy(sourceFile, testFile, true);
                        Assert.IsTrue(File.Exists(testFile), String.Format("File does not exist [{0}]", testFile));

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

                        var readyRedlineTask = new TaskReadyRedline(attachment);
                        readyRedlineTask.Execute(new CancellationToken());

                        var intelligentDocument = new IntelligentDocument();
                        intelligentDocument.SetFileName(attachment.FileName);
                        Assert.IsTrue(intelligentDocument.IsDocumentBeingTracked(), String.Format("Failed to add tracking id to test file [{0}]", x));
                        
                        id = intelligentDocument.GetDocumentTrackingId();
                        Assert.IsFalse(String.IsNullOrEmpty(id), String.Format("Failed to get tracking id for test file [{0}]", x));
                        Assert.IsFalse(String.IsNullOrEmpty(GetDocumentChecksum(id)), String.Format("Failed to get checksum for test file [{0}]", x));
                    }
                    finally
                    {
                        DeleteEntry(id);
                    }
                });
        }
Ejemplo n.º 7
0
        private void UnPackZipFile(IProtectAttachment protectAttachment, CancellationToken token, string password)
        {
            if (protectAttachment.FileType != FileType.ZIP) 
                return;

            var lcfm = new LocalCopyOfFileManager();
            var files = ZipFilePackager.Expand(protectAttachment, password, token, lcfm);
            foreach (var file in files)
            {
                if (token.IsCancellationRequested)
                    return;

                ProtectAttachment attachment;
                var fileType = FileTypeBridge.GetSupportedFileType(file);
                switch (fileType)
                {
                    case FileType.Unknown:
                        {
                            attachment = new ProtectAttachment(new SimpleFile(file, Path.GetFileName(file)), lcfm);
                            break;
                        }
                    case FileType.Email:
                    case FileType.ZIP:
                    case FileType.OutlookMessageFile:
                        {
                            attachment = new ProtectAttachment(FcsFileFactory.Create(file, Path.GetFileName(file)), lcfm);
                            UnPack(attachment, token);
                            break;
                        }
                    default:
                        {
                            attachment = new ProtectAttachment(FcsFileFactory.Create(file, Path.GetFileName(file)), lcfm);
                            break;
                        }
                }

                attachment.Directory = GetDirectory(attachment.FileName, lcfm);

                protectAttachment.Children.Add(attachment);
            }
        }
Ejemplo n.º 8
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.º 9
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.º 10
0
        public void Execute(CancellationToken token)
        {
            var links = new List<SendLinkInfo>();

            IApiHelper apiHelper = _session.ApiHelper;
            DateTime? utcExpiryDate = null;
            if (_options.ExpiryDate.HasValue)
            {
                utcExpiryDate = _options.ExpiryDate.Value.ToUniversalTime();
            }

            DeckFolderStructureResponse folderResponse = null;
            var existedFolderId = _attachments.Where(r=>r.Links!=null).SelectMany(a => a.Links, (b,c) => c.FolderId).FirstOrDefault();
            if (existedFolderId > 0)
            {
                folderResponse = apiHelper.GetFolder(existedFolderId);
            }
            else
            {
                folderResponse = apiHelper.CreateOutboxFolder(DateTime.Now.ToString(), "",
                                                                                    utcExpiryDate,
                                                                                    _options.GetReturnReceipt);
            }
            
            var attachmentsToRemove = new List<IProtectAttachment>();

            foreach (IProtectAttachment attachment in _attachments)
            {
                if (token.IsCancellationRequested)
                    return;

                attachment.Status = PropertyNames.Processing;

                if (IsSendLinkHtmlFile(attachment) && attachment.Links != null && attachment.Links.Count > 0)
                {
                    links.AddRange(attachment.Links);
                }
                else
                {
                    FolderId = folderResponse.Id;

                    string cloudLink;

                    string name = Path.GetFileNameWithoutExtension(attachment.Name);

                    if (!string.IsNullOrEmpty(attachment.LargeAttachmentFileName))
                        name = Path.GetFileNameWithoutExtension(attachment.FileName);

                    SkyDoxApi.UploadFile((l, d) => { }, attachment.FileName, name, FolderId, out cloudLink,
                                         apiHelper);

                    SendLinkInfo link = GetSendLinkInfo(attachment, folderResponse.Url,FolderId);
                    links.Add(link);
                }

                attachmentsToRemove.Add(attachment);
            }

            apiHelper.SetFolderPermissions(folderResponse.Id, GetFolderPermissions());
            apiHelper.FolderFinished(folderResponse.Id);

            foreach (var attachment in attachmentsToRemove)
                _attachments.Remove(attachment);

            SendLinkInfo contentFile = CreateSendLinkContentFile(links);

            var linkAttachment = new ProtectAttachment(FcsFileFactory.Create(contentFile.FilePath, contentFile.DisplayName));
            linkAttachment.Links = links;

            _attachments.Add(linkAttachment);

            RaiseMixpanelEvent();
        }
Ejemplo n.º 11
0
        //[Test]
        public void TestExpandRepackMaintainsDirectoryStructure_03() // Bug fix
        {

            var zipAttachment =
               new ProtectAttachment(TestUtils.CreateAttachment("small.zip", "small.zip", "1"));

            var expectedDirectoryStructure = GetZipFileDirectoryStructure(zipAttachment.FileName);

            var attachments = new ObservableCollection<IProtectAttachment>()
                                {
                                    zipAttachment
                                };

            var actionQueue = new ActionQueue();

            bool discoveryCompleted = false;
            bool appliedAllActions = false;
            actionQueue.StatusUpdate += (sender, args) =>
            {
                if (args.Status == PropertyNames.DiscoveryCompleted)
                {
                    discoveryCompleted = true;
                }

                if (args.Status == PropertyNames.AppliedAllActions)
                {
                    appliedAllActions = true;
                }
            };

            actionQueue.Discover(attachments.ToList());

            SpinWait.SpinUntil(() => discoveryCompleted, 90000);
            Assert.IsTrue(discoveryCompleted);

            var options = new Dictionary<string, dynamic> { { PropertyNames.PdfFormat, PropertyValues.PdfA } };

            var tasks = WorkshareTaskFactory.Create(attachments, options, null);

            actionQueue.ApplyTasks(tasks);

            SpinWait.SpinUntil(() => appliedAllActions, 120000);

            Assert.IsTrue(appliedAllActions, "Failed to apply all actions within the time limit");

            var flattenedList = TestUtils.Flatten(zipAttachment.Children, new List<FileType>() { FileType.Email });

            foreach (var item in flattenedList)
            {
                Assert.IsTrue(item.FileType == FileType.PDFDocument);
            }

            zipAttachment.Children.Clear();

            VerifyFilesAreOfType(zipAttachment, FileType.PDFDocument);

            var currentStructure = GetZipFileDirectoryStructure(zipAttachment.FileName);

            var result = expectedDirectoryStructure.Except(currentStructure).ToList();
            Assert.IsTrue(result.Count == 0);

            new Workshare.API.Cleaning.OfficeApplicationCacheControl().ReleaseOfficeApplications();
            SpinWait.SpinUntil(TestUtils.HasOfficeShutDown, 60000);
        }
Ejemplo n.º 12
0
       // [Test]
        public void TestConvertCollectionToPdf_02() // Another bug fix
        {
            var zipAttachment =
                new ProtectAttachment(TestUtils.CreateAttachment("small.zip", "small.zip", "1"));

            var passwordAttachment = new ProtectAttachment(TestUtils.CreateAttachment("password.docx", "password.docx", "1"));

            var attachments = new ObservableCollection<IProtectAttachment>()
                                {
                                    passwordAttachment,
                                    zipAttachment
                                };

            var actionQueue = new ActionQueue();

            bool discoveryCompleted = false;
            bool appliedAllActions = false;
            actionQueue.StatusUpdate += (sender, args) =>
            {
                if (args.Status == PropertyNames.DiscoveryCompleted)
                {
                    discoveryCompleted = true;
                }

                if (args.Status == PropertyNames.AppliedAllActions)
                {
                    appliedAllActions = true;
                }
            };

            actionQueue.Discover(attachments.ToList());

            SpinWait.SpinUntil(() => discoveryCompleted, 90000);
            Assert.IsTrue(discoveryCompleted, "Discovery failed to complete.");

            var options = new Dictionary<string, dynamic> { { PropertyNames.PdfFormat, PropertyValues.PdfA } };

            var tasks = WorkshareTaskFactory.Create(attachments, options, null);

            actionQueue.ApplyTasks(tasks);

            SpinWait.SpinUntil(() => appliedAllActions, 120000);

            Assert.IsTrue(appliedAllActions, "Failed to apply all actions within the time limit");

            var flattenedList = TestUtils.Flatten(zipAttachment.Children, new List<FileType>() { FileType.Email });

            foreach (var item in flattenedList)
            {
                Assert.IsTrue(item.FileType == FileType.PDFDocument);
            }

            zipAttachment.Children.Clear();

            VerifyFilesAreOfType(zipAttachment, FileType.PDFDocument);

            new Workshare.API.Cleaning.OfficeApplicationCacheControl().ReleaseOfficeApplications();

            SpinWait.SpinUntil(TestUtils.HasOfficeShutDown, 60000);
        }
Ejemplo n.º 13
0
        public void UnPackMessageFile(IProtectAttachment attachment, CancellationToken token)
        {
            if (!IsMsgFile(attachment.FileType))
                return;

            MessageItem message = _mapiUtils.GetItemFromMsgFile(attachment.FileName, false);

            Attachments attachments = message.Attachments;
            for (int i = 1; i <= attachments.Count; ++i)
            {
                if (token.IsCancellationRequested)
                    return;

                Attachment redemptionAttachment = attachments.Item(i);
                if (!MapiSignatureInspector.IsSignature(redemptionAttachment, (OlBodyFormat) message.BodyFormat))
                {
                    var lcfm = new LocalCopyOfFileManager();
                    string tempFile = lcfm.GetLocalCopyOfFileTarget(redemptionAttachment.FileName);
                    redemptionAttachment.SaveAsFile(tempFile);
                    var protectAttachment =
                        new ProtectAttachment(FcsFileFactory.Create(tempFile, redemptionAttachment.DisplayName), lcfm);
                    protectAttachment.Index = redemptionAttachment.Position.ToString();

                    attachment.Children.Add(protectAttachment);

                    if (protectAttachment.FileType == FileType.ZIP || IsMsgFile(protectAttachment.FileType))
                    {
                        UnPack(protectAttachment, token);
                    }
                    
                }

                Marshal.ReleaseComObject(redemptionAttachment);
            }

            Marshal.ReleaseComObject(attachments);
            Marshal.ReleaseComObject(message);
        }