Skip to content

Commit

Permalink
Support docMDP level 3 validation
Browse files Browse the repository at this point in the history
DEVSIX-8344

Autoported commit.
Original commit hash: [03a2c75fa]
  • Loading branch information
AnhelinaM authored and iText-CI committed May 23, 2024
1 parent 0a42acd commit fa0b8d6
Show file tree
Hide file tree
Showing 9 changed files with 675 additions and 616 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ You should have received a copy of the GNU Affero General Public License
using System;
using iText.Bouncycastleconnector;
using iText.Commons.Bouncycastle;
using iText.Commons.Utils;
using iText.Kernel.Pdf;
using iText.Signatures;
using iText.Signatures.Validation.V1.Report;
Expand Down Expand Up @@ -288,5 +289,61 @@ public virtual void RemovedLockedFieldTest() {
.INVALID)));
}
}

[NUnit.Framework.Test]
public virtual void DanglingWidgetAnnotationTest() {
using (PdfDocument document = new PdfDocument(new PdfReader(SOURCE_FOLDER + "danglingWidgetAnnotation.pdf"
))) {
DocumentRevisionsValidator validator = new DocumentRevisionsValidator(document);
ValidationReport report = validator.ValidateAllDocumentRevisions();
// New widget annotation not included into the acroform was added to the 1st page.
AssertValidationReport.AssertThat(report, (a) => a.HasStatus(ValidationReport.ValidationResult.INVALID).HasNumberOfFailures
(1).HasNumberOfLogs(1).HasLogItem((l) => l.WithCheckName(DocumentRevisionsValidator.DOC_MDP_CHECK).WithMessage
(DocumentRevisionsValidator.PAGE_ANNOTATIONS_MODIFIED).WithStatus(ReportItem.ReportItemStatus.INVALID)
));
NUnit.Framework.Assert.AreEqual(AccessPermissions.FORM_FIELDS_MODIFICATION, validator.GetAccessPermissions
());
}
}

[NUnit.Framework.Test]
public virtual void RemoveAllThePageAnnotationsTest() {
using (PdfDocument document = new PdfDocument(new PdfReader(SOURCE_FOLDER + "removeAllAnnots.pdf"))) {
DocumentRevisionsValidator validator = new DocumentRevisionsValidator(document);
ValidationReport report = validator.ValidateAllDocumentRevisions();
// All the annotations on the 2nd page were removed.
AssertValidationReport.AssertThat(report, (a) => a.HasStatus(ValidationReport.ValidationResult.VALID));
NUnit.Framework.Assert.AreEqual(AccessPermissions.ANNOTATION_MODIFICATION, validator.GetAccessPermissions(
));
}
}

[NUnit.Framework.Test]
public virtual void RemoveAllTheFieldAnnotationsTest() {
using (PdfDocument document = new PdfDocument(new PdfReader(SOURCE_FOLDER + "removeFieldAnnots.pdf"))) {
DocumentRevisionsValidator validator = new DocumentRevisionsValidator(document);
ValidationReport report = validator.ValidateAllDocumentRevisions();
// All the annotations of the text field were removed. Note that Acrobat considers it invalid.
AssertValidationReport.AssertThat(report, (a) => a.HasStatus(ValidationReport.ValidationResult.VALID));
NUnit.Framework.Assert.AreEqual(AccessPermissions.ANNOTATION_MODIFICATION, validator.GetAccessPermissions(
));
}
}

[NUnit.Framework.Test]
public virtual void RemoveUnnamedFieldTest() {
using (PdfDocument document = new PdfDocument(new PdfReader(SOURCE_FOLDER + "removeUnnamedField.pdf"))) {
DocumentRevisionsValidator validator = new DocumentRevisionsValidator(document);
ValidationReport report = validator.ValidateAllDocumentRevisions();
// Child field was removed, so parent field was modified. Both fields are unnamed.
AssertValidationReport.AssertThat(report, (a) => a.HasStatus(ValidationReport.ValidationResult.INVALID).HasNumberOfFailures
(3).HasNumberOfLogs(3).HasLogItems(2, 2, (l) => l.WithCheckName(DocumentRevisionsValidator.DOC_MDP_CHECK
).WithMessage(MessageFormatUtil.Format(DocumentRevisionsValidator.FIELD_REMOVED, "")).WithStatus(ReportItem.ReportItemStatus
.INVALID)).HasLogItem((l) => l.WithCheckName(DocumentRevisionsValidator.DOC_MDP_CHECK).WithMessage(DocumentRevisionsValidator
.NOT_ALLOWED_ACROFORM_CHANGES).WithStatus(ReportItem.ReportItemStatus.INVALID)));
NUnit.Framework.Assert.AreEqual(AccessPermissions.ANNOTATION_MODIFICATION, validator.GetAccessPermissions(
));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -448,5 +448,26 @@ public virtual void ModifyPageAnnotsTest() {
.INVALID)));
}
}

[NUnit.Framework.Test]
public virtual void MultipleRevisionsDocumentLevel3Test() {
using (PdfDocument document = new PdfDocument(new PdfReader(SOURCE_FOLDER + "multipleRevisionsDocument3.pdf"
))) {
DocumentRevisionsValidator validator = new DocumentRevisionsValidator(document);
validator.SetAccessPermissions(AccessPermissions.ANNOTATION_MODIFICATION);
PdfRevisionsReader revisionsReader = new PdfRevisionsReader(document.GetReader());
IList<DocumentRevision> documentRevisions = revisionsReader.GetAllRevisions();
ValidationReport validationReport = new ValidationReport();
validator.ValidateRevision(documentRevisions[0], documentRevisions[1], validationReport);
// Between these two revisions annotations were added and deleted, text field was filled-in.
AssertValidationReport.AssertThat(validationReport, (a) => a.HasStatus(ValidationReport.ValidationResult.VALID
).HasNumberOfFailures(0).HasNumberOfLogs(0));
validationReport = new ValidationReport();
validator.ValidateRevision(documentRevisions[1], documentRevisions[2], validationReport);
// Between these two revisions existed annotations were modified, it is allowed.
AssertValidationReport.AssertThat(validationReport, (a) => a.HasStatus(ValidationReport.ValidationResult.VALID
).HasNumberOfFailures(0).HasNumberOfLogs(0));
}
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit fa0b8d6

Please sign in to comment.