Skip to content

Commit

Permalink
Merge branch 'develop' into devsecops
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-ivanov committed Feb 3, 2025
2 parents 6d2197a + 7941d36 commit 2223518
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,43 @@ public virtual void TaggedDocRemoveStructTreeElementTest(bool continueValidation
}
}

[NUnit.Framework.TestCaseSource("CreateParameters")]
public virtual void AnnotationModificationAllowedTabsChangesTest(bool continueValidationAfterFail) {
SetUp(continueValidationAfterFail);
using (PdfDocument document = new PdfDocument(new PdfReader(SOURCE_FOLDER + "annotationModificationAllowedTabsChangesTest.pdf"
))) {
DocumentRevisionsValidator validator = builder.BuildDocumentRevisionsValidator();
ValidationReport report = validator.ValidateAllDocumentRevisions(validationContext, document);
AssertValidationReport.AssertThat(report, (a) => a.HasStatus(ValidationReport.ValidationResult.VALID).HasNumberOfLogs
(0));
}
}

[NUnit.Framework.TestCaseSource("CreateParameters")]
public virtual void AnnotationModificationNotAllowedTabsChangesTest(bool continueValidationAfterFail) {
SetUp(continueValidationAfterFail);
using (PdfDocument document = new PdfDocument(new PdfReader(SOURCE_FOLDER + "annotationModificationNotAllowedTabsChangesTest.pdf"
))) {
DocumentRevisionsValidator validator = builder.BuildDocumentRevisionsValidator();
ValidationReport report = validator.ValidateAllDocumentRevisions(validationContext, document);
AssertValidationReport.AssertThat(report, (a) => a.HasStatus(ValidationReport.ValidationResult.INVALID).HasNumberOfFailures
(1).HasLogItem((l) => l.WithCheckName(DocumentRevisionsValidator.DOC_MDP_CHECK).WithMessage(DocumentRevisionsValidator
.TABS_MODIFIED).WithStatus(ReportItem.ReportItemStatus.INVALID)));
}
}

[NUnit.Framework.TestCaseSource("CreateParameters")]
public virtual void AnnotationModificationNotAllowedTabsSetToDefaultTest(bool continueValidationAfterFail) {
SetUp(continueValidationAfterFail);
using (PdfDocument document = new PdfDocument(new PdfReader(SOURCE_FOLDER + "annotationModificationNotAllowedTabsSetToDefaultTest.pdf"
))) {
DocumentRevisionsValidator validator = builder.BuildDocumentRevisionsValidator();
ValidationReport report = validator.ValidateAllDocumentRevisions(validationContext, document);
AssertValidationReport.AssertThat(report, (a) => a.HasStatus(ValidationReport.ValidationResult.VALID).HasNumberOfLogs
(0));
}
}

[NUnit.Framework.TestCaseSource("CreateParameters")]
public virtual void OutlinesNotModifiedTest(bool continueValidationAfterFail) {
SetUp(continueValidationAfterFail);
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ public class DocumentRevisionsValidator {
internal const String PAGE_MODIFIED = "Page was unexpectedly modified.";
//\endcond

//\cond DO_NOT_DOCUMENT
internal const String TABS_MODIFIED = "Tabs entry in a page dictionary was unexpectedly modified.";
//\endcond

//\cond DO_NOT_DOCUMENT
internal const String PERMISSIONS_REMOVED = "Permissions dictionary was removed from the catalog.";
//\endcond
Expand Down Expand Up @@ -1510,15 +1514,21 @@ private bool ComparePages(PdfDictionary prevPages, PdfDictionary currPages, Vali
previousPageCopy.Remove(PdfName.Annots);
previousPageCopy.Remove(PdfName.Parent);
previousPageCopy.Remove(PdfName.StructParents);
previousPageCopy.Remove(PdfName.Tabs);
PdfDictionary currentPageCopy = new PdfDictionary(currentKid);
currentPageCopy.Remove(PdfName.Annots);
currentPageCopy.Remove(PdfName.Parent);
currentPageCopy.Remove(PdfName.StructParents);
currentPageCopy.Remove(PdfName.Tabs);
if (!ComparePdfObjects(previousPageCopy, currentPageCopy, usuallyModifiedObjects) || !CompareIndirectReferencesObjNums
(previousKid.Get(PdfName.Parent), currentKid.Get(PdfName.Parent), report, "Page parent")) {
report.AddReportItem(new ReportItem(DOC_MDP_CHECK, PAGE_MODIFIED, ReportItem.ReportItemStatus.INVALID));
return false;
}
if (!CompareTabs(previousKid.GetAsName(PdfName.Tabs), currentKid.GetAsName(PdfName.Tabs))) {
report.AddReportItem(new ReportItem(DOC_MDP_CHECK, TABS_MODIFIED, ReportItem.ReportItemStatus.INVALID));
return false;
}
PdfArray prevNotModifiableAnnots = GetAnnotsNotAllowedToBeModified(previousKid);
PdfArray currNotModifiableAnnots = GetAnnotsNotAllowedToBeModified(currentKid);
if (!ComparePageAnnotations(prevNotModifiableAnnots, currNotModifiableAnnots, report)) {
Expand All @@ -1533,6 +1543,13 @@ private bool ComparePages(PdfDictionary prevPages, PdfDictionary currPages, Vali
return true;
}

private bool CompareTabs(PdfName previousTabs, PdfName currentTabs) {
if (GetAccessPermissions() == AccessPermissions.ANNOTATION_MODIFICATION) {
return true;
}
return Object.Equals(previousTabs, currentTabs) || (previousTabs == null && currentTabs.Equals(PdfName.S));
}

private void CollectRemovedAndAddedAnnotations(PdfArray previousAnnotations, PdfArray currentAnnotations) {
ValidationReport dummyReport = new ValidationReport();
IList<PdfDictionary> prevAnnots = new List<PdfDictionary>();
Expand Down
2 changes: 1 addition & 1 deletion port-hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8d4fbb6308e2126af33891bf5ad981ec9f2fd81b
ce35dbce51bd8c3f1b01e78313f1f5a2a02201ff

0 comments on commit 2223518

Please sign in to comment.