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 Oct 15, 2024
2 parents 49717d5 + c61e628 commit 1710ff9
Show file tree
Hide file tree
Showing 22 changed files with 135 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public virtual void EncryptedDocumentWithFormFields() {
}

[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
public virtual void EncryptAes256Pdf2PermissionsTest01() {
String filename = "encryptAes256Pdf2PermissionsTest01.pdf";
int permissions = EncryptionConstants.ALLOW_FILL_IN | EncryptionConstants.ALLOW_SCREENREADERS | EncryptionConstants
Expand Down Expand Up @@ -107,7 +106,6 @@ public virtual void EncryptAes256Pdf2PermissionsTest01() {
}

[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
public virtual void EncryptAes256Pdf2PermissionsTest02() {
String filename = "encryptAes256Pdf2PermissionsTest02.pdf";
// This test differs from the previous one (encryptAes256Pdf2PermissionsTest01) only in permissions.
Expand Down
23 changes: 23 additions & 0 deletions itext.tests/itext.forms.tests/itext/forms/PdfFormFieldTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,29 @@ public virtual void PdfWithSignatureAndFontInBuilderFieldTest() {
, destinationFolder, "diff_"));
}

[NUnit.Framework.Test]
[LogMessage(FormsLogMessageConstants.FORM_FIELD_HAS_CYCLED_PARENT_STRUCTURE, Ignore = true)]
public virtual void FormFieldCycleRefTest() {
String fileName = destinationFolder + "formFieldCycleRefTest.pdf";
PdfDocument pdfDoc = new PdfDocument(CompareTool.CreateTestPdfWriter(fileName));
pdfDoc.SetTagged();
pdfDoc.InitializeOutlines();
PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(pdfDoc, true);
PdfFormField formField = new CheckBoxFormFieldBuilder(pdfDoc, "TestCheck").SetWidgetRectangle(new Rectangle
(36, 560, 20, 20)).CreateCheckBox().SetValue("1", true);
PdfFormField child1 = new TextFormFieldBuilder(pdfDoc, "child").SetWidgetRectangle(new Rectangle(100, 300,
200, 20)).CreateText();
PdfFormField child2 = new TextFormFieldBuilder(pdfDoc, "another_name").SetWidgetRectangle(new Rectangle(100
, 250, 200, 20)).CreateText();
formField.AddKid(child1);
child1.AddKid(child2);
formField.SetParent(child2);
acroForm.AddField(formField);
pdfDoc.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(fileName, sourceFolder + "cmp_formFieldCycleRefTest.pdf"
, destinationFolder, "diff_"));
}

//\cond DO_NOT_DOCUMENT
internal class CustomButtonFormField : PdfButtonFormField {
private int counter = 0;
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ You should have received a copy of the GNU Affero General Public License
using NUnit.Framework;
using iText.Bouncycastleconnector;
using iText.Commons.Bouncycastle;
using iText.Kernel.Logs;
using iText.Kernel.Pdf;
using iText.Kernel.Utils;
using iText.Test;
using iText.Test.Attributes;

namespace iText.Kernel.Crypto {
[NUnit.Framework.Category("BouncyCastleIntegrationTest")]
Expand Down Expand Up @@ -59,7 +57,6 @@ public static void AfterClass() {
}

[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT)]
public virtual void CheckMD5LogMessageWhileReadingPdfTest() {
String fileName = "checkMD5LogMessageWhileReadingPdf.pdf";
using (PdfDocument document = new PdfDocument(new PdfReader(sourceFolder + fileName))) {
Expand All @@ -68,7 +65,6 @@ public virtual void CheckMD5LogMessageWhileReadingPdfTest() {

// this test checks log message
[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT)]
public virtual void CheckMD5LogMessageWhileCreatingPdfTest() {
String fileName = "checkMD5LogMessageWhileCreatingPdf.pdf";
using (PdfDocument document = new PdfDocument(CompareTool.CreateTestPdfWriter(destinationFolder + fileName
Expand All @@ -79,7 +75,6 @@ public virtual void CheckMD5LogMessageWhileCreatingPdfTest() {

// this test checks log message
[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Count = 3)]
public virtual void CheckMD5LogMessageForEachPdfTest() {
String fileName = "checkMD5LogMessageForEachPdf.pdf";
for (int i = 0; i < 3; ++i) {
Expand All @@ -89,6 +84,6 @@ public virtual void CheckMD5LogMessageForEachPdfTest() {
}
}
}
// this test checks log message
// this test checks absence of log messages
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ public virtual void EncryptWithPasswordAes128() {
}

[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
public virtual void EncryptWithPasswordAes256() {
String filename = "encryptWithPasswordAes256.pdf";
int encryptionType = EncryptionConstants.ENCRYPTION_AES_256;
Expand All @@ -151,7 +150,6 @@ public virtual void EncryptWithPasswordAes128NoCompression() {
}

[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
public virtual void EncryptWithPasswordAes256NoCompression() {
String filename = "encryptWithPasswordAes256NoCompression.pdf";
int encryptionType = EncryptionConstants.ENCRYPTION_AES_256;
Expand Down Expand Up @@ -311,7 +309,6 @@ public virtual void EncryptWithPasswordAes128EmbeddedFilesOnly() {
}

[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
public virtual void EncryptWithPasswordAes256EmbeddedFilesOnly() {
String filename = "encryptWithPasswordAes256EmbeddedFilesOnly.pdf";
int encryptionType = EncryptionConstants.ENCRYPTION_AES_256 | EncryptionConstants.EMBEDDED_FILES_ONLY;
Expand Down Expand Up @@ -342,15 +339,13 @@ public virtual void EncryptWithPasswordAes256EmbeddedFilesOnly() {
}

[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
public virtual void EncryptAes256Pdf2NotEncryptMetadata() {
String filename = "encryptAes256Pdf2NotEncryptMetadata.pdf";
int encryptionType = EncryptionConstants.ENCRYPTION_AES_256 | EncryptionConstants.DO_NOT_ENCRYPT_METADATA;
EncryptWithPassword2(filename, encryptionType, CompressionConstants.DEFAULT_COMPRESSION);
}

[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
public virtual void EncryptAes256Pdf2NotEncryptMetadata02() {
String filename = "encryptAes256Pdf2NotEncryptMetadata02.pdf";
int encryptionType = EncryptionConstants.ENCRYPTION_AES_256 | EncryptionConstants.DO_NOT_ENCRYPT_METADATA;
Expand All @@ -377,15 +372,13 @@ public virtual void EncryptAes256EncryptedStampingUpdate() {
}

[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
public virtual void EncryptAes256FullCompression() {
String filename = "encryptAes256FullCompression.pdf";
int encryptionType = EncryptionConstants.ENCRYPTION_AES_256;
EncryptWithPassword2(filename, encryptionType, CompressionConstants.DEFAULT_COMPRESSION, true);
}

[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
public virtual void EncryptWithPasswordAes256Pdf2() {
String filename = "encryptWithPasswordAes256Pdf2.pdf";
int encryptionType = EncryptionConstants.ENCRYPTION_AES_256;
Expand All @@ -402,7 +395,6 @@ public virtual void EncryptWithPasswordAes128Pdf2() {
}

[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
public virtual void StampAndUpdateVersionNewAes256() {
String filename = "stampAndUpdateVersionNewAes256.pdf";
PdfDocument doc = new PdfDocument(new PdfReader(sourceFolder + "encryptedWithPasswordAes256.pdf", new ReaderProperties
Expand All @@ -414,7 +406,6 @@ public virtual void StampAndUpdateVersionNewAes256() {
}

[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
public virtual void EncryptAes256Pdf2Permissions() {
String filename = "encryptAes256Pdf2Permissions.pdf";
int permissions = EncryptionConstants.ALLOW_FILL_IN | EncryptionConstants.ALLOW_SCREENREADERS | EncryptionConstants
Expand Down Expand Up @@ -461,7 +452,6 @@ public virtual void CheckMD5LogAbsenceInUnapprovedMode() {

// this test checks log message absence
[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true, Count = 2)]
public virtual void DecryptAdobeWithPasswordAes256() {
String filename = System.IO.Path.Combine(sourceFolder + "AdobeAes256.pdf").ToString();
DecryptWithPassword(filename, "user".GetBytes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ You should have received a copy of the GNU Affero General Public License
using iText.Commons.Utils;
using iText.Kernel.Crypto;
using iText.Kernel.Exceptions;
using iText.Kernel.Logs;
using iText.Kernel.Pdf;
using iText.Kernel.Utils;
using iText.Test;
Expand All @@ -54,7 +53,6 @@ public static void SetUp() {
CreateOrClearDestinationFolder(DESTINATION_FOLDER);
}

[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
[NUnit.Framework.Test]
public virtual void TestSimpleEncryptDecryptTest() {
try {
Expand All @@ -72,7 +70,6 @@ public virtual void TestSimpleEncryptDecryptTest() {
}

[LogMessage(VersionConforming.NOT_SUPPORTED_AES_GCM, Ignore = true)]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
[NUnit.Framework.Test]
public virtual void TestSimpleEncryptDecryptPdf17Test() {
try {
Expand All @@ -89,7 +86,6 @@ public virtual void TestSimpleEncryptDecryptPdf17Test() {
DecryptWithCertificate(fileName, DESTINATION_FOLDER, "test.cer", "test.pem");
}

[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
[NUnit.Framework.Test]
public virtual void DecryptExternalFileTest() {
try {
Expand All @@ -101,7 +97,6 @@ public virtual void DecryptExternalFileTest() {
DecryptWithCertificate("externalFile.pdf", SOURCE_FOLDER, "decrypter.cert.pem", "signerkey.pem");
}

[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
[NUnit.Framework.Test]
public virtual void InvalidCryptFilterTest() {
String fileName = "invalidCryptFilter.pdf";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ You should have received a copy of the GNU Affero General Public License
using iText.Bouncycastleconnector;
using iText.Commons.Bouncycastle;
using iText.Kernel.Exceptions;
using iText.Kernel.Logs;
using iText.Kernel.Pdf;
using iText.Kernel.Utils;
using iText.Kernel.Utils.Objectpathitems;
Expand All @@ -52,7 +51,6 @@ public static void SetUp() {
}

[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
public virtual void SimpleEncryptDecryptTest() {
String srcFile = SRC + "simpleDocument.pdf";
String encryptedCmpFile = SRC + "cmp_encryptedSimpleDocument.pdf";
Expand All @@ -74,7 +72,6 @@ public virtual void SimpleEncryptDecryptTest() {

[NUnit.Framework.Test]
[LogMessage(VersionConforming.NOT_SUPPORTED_AES_GCM)]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
public virtual void SimpleEncryptDecryptPdf15Test() {
String srcFile = SRC + "simpleDocument.pdf";
String outFile = DEST + "notSupportedVersionDocument.pdf";
Expand All @@ -87,7 +84,6 @@ public virtual void SimpleEncryptDecryptPdf15Test() {
}

[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
public virtual void KnownOutputTest() {
String srcFile = SRC + "encryptedDocument.pdf";
String outFile = DEST + "encryptedDocument.pdf";
Expand All @@ -100,29 +96,25 @@ public virtual void KnownOutputTest() {
}

// In all these tampered files, the stream content of object 14 has been modified.
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
[NUnit.Framework.Test]
public virtual void MacTamperedTest() {
String srcFile = SRC + "encryptedDocumentTamperedMac.pdf";
AssertTampered(srcFile);
}

[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
[NUnit.Framework.Test]
public virtual void InitVectorTamperedTest() {
String srcFile = SRC + "encryptedDocumentTamperedIv.pdf";
AssertTampered(srcFile);
}

[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
[NUnit.Framework.Test]
public virtual void CiphertextTamperedTest() {
String srcFile = SRC + "encryptedDocumentTamperedCiphertext.pdf";
AssertTampered(srcFile);
}

[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
[LogMessage(iText.IO.Logs.IoLogMessageConstant.ENCRYPTION_ENTRIES_P_AND_ENCRYPT_METADATA_NOT_CORRESPOND_PERMS_ENTRY
)]
public virtual void PdfEncryptionWithEmbeddedFilesTest() {
Expand Down Expand Up @@ -158,7 +150,6 @@ public virtual void PdfEncryptionWithEmbeddedFilesTest() {
}

[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
public virtual void PdfEncryptionWithMetadataTest() {
byte[] documentId = new byte[] { (byte)88, (byte)189, (byte)192, (byte)48, (byte)240, (byte)200, (byte)87,
(byte)183, (byte)244, (byte)119, (byte)224, (byte)109, (byte)226, (byte)173, (byte)32, (byte)90 };
Expand Down Expand Up @@ -191,7 +182,6 @@ public virtual void PdfEncryptionWithMetadataTest() {
}

[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
public virtual void EncryptPdfWithMissingCFTest() {
byte[] documentId = new byte[] { (byte)88, (byte)189, (byte)192, (byte)48, (byte)240, (byte)200, (byte)87,
(byte)183, (byte)244, (byte)119, (byte)224, (byte)109, (byte)226, (byte)173, (byte)32, (byte)90 };
Expand All @@ -206,7 +196,6 @@ public virtual void EncryptPdfWithMissingCFTest() {
}

[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
public virtual void EncryptPdfWithMissingStdCFTest() {
byte[] documentId = new byte[] { (byte)88, (byte)189, (byte)192, (byte)48, (byte)240, (byte)200, (byte)87,
(byte)183, (byte)244, (byte)119, (byte)224, (byte)109, (byte)226, (byte)173, (byte)32, (byte)90 };
Expand All @@ -226,7 +215,6 @@ public virtual void EncryptPdfWithMissingStdCFTest() {
}

[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
public virtual void EncryptPdfWithMissingCFMTest() {
byte[] documentId = new byte[] { (byte)88, (byte)189, (byte)192, (byte)48, (byte)240, (byte)200, (byte)87,
(byte)183, (byte)244, (byte)119, (byte)224, (byte)109, (byte)226, (byte)173, (byte)32, (byte)90 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public static void AfterClass() {
}

[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
public virtual void StandaloneMacStandardEncryptionTest() {
String fileName = "standaloneMacStandardEncryptionTest.pdf";
String outputFileName = DESTINATION_FOLDER + fileName;
Expand All @@ -82,7 +81,6 @@ public virtual void StandaloneMacStandardEncryptionTest() {
}

[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
public virtual void NoMacProtectionTest() {
String fileName = "noMacProtectionTest.pdf";
String outputFileName = DESTINATION_FOLDER + fileName;
Expand Down Expand Up @@ -115,21 +113,20 @@ public virtual void MacEncryptionWithAesGcmTest() {
}

[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
[LogMessage(iText.IO.Logs.IoLogMessageConstant.PDF_WRITER_CLOSING_FAILED)]
public virtual void StandaloneMacUnwritableStreamTest() {
WriterProperties writerProperties = new WriterProperties().SetPdfVersion(PdfVersion.PDF_2_0).SetStandardEncryption
(PASSWORD, PASSWORD, 0, EncryptionConstants.ENCRYPTION_AES_256, new MacProperties(MacProperties.MacDigestAlgorithm
.SHA_256));
MemoryStream unwritableStream = new _MemoryStream_152();
MemoryStream unwritableStream = new _MemoryStream_147();
using (PdfDocument pdfDoc = new PdfDocument(new PdfWriter(unwritableStream, writerProperties))) {
pdfDoc.AddNewPage().AddAnnotation(new PdfTextAnnotation(new Rectangle(100, 100, 100, 100)));
}
unwritableStream.Dispose();
}

private sealed class _MemoryStream_152 : MemoryStream {
public _MemoryStream_152() {
private sealed class _MemoryStream_147 : MemoryStream {
public _MemoryStream_147() {
}

public override void Write(byte[] b, int off, int len) {
Expand All @@ -138,7 +135,6 @@ public override void Write(byte[] b, int off, int len) {
}

[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
public virtual void StandaloneMacWithAllHashAlgorithmsTest() {
for (int i = 0; i < EnumUtil.GetAllValuesOfEnum<MacProperties.MacDigestAlgorithm>().Count; i++) {
String fileName = "standaloneMacWithAllHashAlgorithmsTest" + (i + 1) + ".pdf";
Expand All @@ -159,7 +155,6 @@ public virtual void StandaloneMacWithAllHashAlgorithmsTest() {
}

[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
public virtual void StandaloneMacPdfVersionNotSetTest() {
String fileName = "standaloneMacPdfVersionNotSetTest.pdf";
String outputFileName = DESTINATION_FOLDER + fileName;
Expand Down Expand Up @@ -209,7 +204,6 @@ public virtual void AddMacOnAppendModeTest() {
}

[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
public virtual void AddMacWithDisableMacPropertyTest() {
// MAC should not be added in disable MAC mode even if it was provided with writer properties
String fileName = "addMacWithDisableMacPropertyTest.pdf";
Expand Down Expand Up @@ -280,7 +274,6 @@ public virtual void StandaloneMacOldEncryptionAlgorithmTest() {
}

[NUnit.Framework.Test]
[LogMessage(KernelLogMessageConstant.MD5_IS_NOT_FIPS_COMPLIANT, Ignore = true)]
public virtual void StandaloneMacPublicKeyEncryptionTest() {
try {
BouncyCastleFactoryCreator.GetFactory().IsEncryptionFeatureSupported(0, true);
Expand Down
Loading

0 comments on commit 1710ff9

Please sign in to comment.