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 Jun 5, 2024
2 parents 6c2acbb + 455ad0b commit 7b4c7c6
Show file tree
Hide file tree
Showing 29 changed files with 712 additions and 247 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ You should have received a copy of the GNU Affero General Public License
using System.IO;
using iText.Commons.Actions;
using iText.Commons.Actions.Confirmations;
using iText.Commons.Actions.Contexts;
using iText.Commons.Actions.Sequence;
using iText.Commons.Bouncycastle.Cert;
using iText.Commons.Bouncycastle.Crypto;
Expand Down Expand Up @@ -93,7 +94,7 @@ public static void Before() {

[NUnit.Framework.SetUp]
public virtual void SetUpHandler() {
handler = new SignMetaInfoHandlingTest.StoreEventsHandler();
handler = new SignMetaInfoHandlingTest.StoreEventsHandler(UnknownContext.PERMISSIVE);
EventManager.GetInstance().Register(handler);
}

Expand All @@ -115,13 +116,9 @@ public virtual void CreateDocumentWithSignMetaInfoTest() {
// No confirmed events.
NUnit.Framework.Assert.AreEqual(0, confirmedEvents.Count);
IList<AbstractContextBasedITextEvent> events = handler.GetEvents();
NUnit.Framework.Assert.AreEqual(1, events.Count);
NUnit.Framework.Assert.IsTrue(events[0] is ITextCoreProductEvent);
NUnit.Framework.Assert.AreEqual(ITextCoreProductEvent.PROCESS_PDF, ((ITextCoreProductEvent)events[0]).GetEventType
());
NUnit.Framework.Assert.AreEqual(0, events.Count);
}

// ITextCoreProductEvent contains SignMetaInfo, but getter for the meta info is package-private.
[NUnit.Framework.Test]
public virtual void SignWithBaselineLTProfileEventHandlingTest() {
ByteArrayOutputStream @out = new ByteArrayOutputStream();
Expand All @@ -135,20 +132,16 @@ public virtual void SignWithBaselineLTProfileEventHandlingTest() {
padesSigner.SetStampingProperties(new StampingProperties().UseAppendMode());
padesSigner.SignWithBaselineLTProfile(signerProperties, signRsaChain, signRsaPrivateKey, testTsa);
IList<AbstractContextBasedITextEvent> events = handler.GetEvents();
NUnit.Framework.Assert.AreEqual(3, events.Count);
NUnit.Framework.Assert.AreEqual(2, events.Count);
NUnit.Framework.Assert.IsTrue(events[0] is ITextCoreProductEvent);
ITextCoreProductEvent iTextCoreProductEvent = (ITextCoreProductEvent)events[0];
NUnit.Framework.Assert.AreEqual(ITextCoreProductEvent.PROCESS_PDF, iTextCoreProductEvent.GetEventType());
// Only first iTextCoreProductEvent is confirmed.
NUnit.Framework.Assert.IsTrue(events[1] is ConfirmEvent);
ConfirmEvent confirmEvent = (ConfirmEvent)events[1];
NUnit.Framework.Assert.AreEqual(iTextCoreProductEvent, confirmEvent.GetConfirmedEvent());
NUnit.Framework.Assert.IsTrue(events[2] is ITextCoreProductEvent);
NUnit.Framework.Assert.AreEqual(ITextCoreProductEvent.PROCESS_PDF, ((ITextCoreProductEvent)events[2]).GetEventType
());
}

// Second ITextCoreProductEvent contains SignMetaInfo (getter is package-private), so it is not confirmed.
[NUnit.Framework.Test]
public virtual void SignWithBaselineLTAProfileEventHandlingTest() {
ByteArrayOutputStream @out = new ByteArrayOutputStream();
Expand All @@ -161,20 +154,16 @@ public virtual void SignWithBaselineLTAProfileEventHandlingTest() {
padesSigner.SetOcspClient(ocspClient).SetCrlClient(crlClient).SetTimestampSignatureName("timestampSig1");
padesSigner.SignWithBaselineLTAProfile(signerProperties, signRsaChain, signRsaPrivateKey, testTsa);
IList<AbstractContextBasedITextEvent> events = handler.GetEvents();
NUnit.Framework.Assert.AreEqual(3, events.Count);
NUnit.Framework.Assert.AreEqual(2, events.Count);
NUnit.Framework.Assert.IsTrue(events[0] is ITextCoreProductEvent);
ITextCoreProductEvent iTextCoreProductEvent = (ITextCoreProductEvent)events[0];
NUnit.Framework.Assert.AreEqual(ITextCoreProductEvent.PROCESS_PDF, iTextCoreProductEvent.GetEventType());
// Only first iTextCoreProductEvent is confirmed.
NUnit.Framework.Assert.IsTrue(events[1] is ConfirmEvent);
ConfirmEvent confirmEvent = (ConfirmEvent)events[1];
NUnit.Framework.Assert.AreEqual(iTextCoreProductEvent, confirmEvent.GetConfirmedEvent());
NUnit.Framework.Assert.IsTrue(events[2] is ITextCoreProductEvent);
NUnit.Framework.Assert.AreEqual(ITextCoreProductEvent.PROCESS_PDF, ((ITextCoreProductEvent)events[2]).GetEventType
());
}

// Second ITextCoreProductEvent contains SignMetaInfo (getter is package-private), so it is not confirmed.
[NUnit.Framework.Test]
public virtual void SignCMSContainerWithBaselineLTProfileEventHandlingTest() {
ByteArrayOutputStream @out = new ByteArrayOutputStream();
Expand All @@ -194,7 +183,7 @@ public virtual void SignCMSContainerWithBaselineLTProfileEventHandlingTest() {
(preparedDoc.ToArray())), @out, "Signature1", container);
}
IList<AbstractContextBasedITextEvent> events = handler.GetEvents();
NUnit.Framework.Assert.AreEqual(5, events.Count);
NUnit.Framework.Assert.AreEqual(4, events.Count);
NUnit.Framework.Assert.IsTrue(events[0] is ITextCoreProductEvent);
ITextCoreProductEvent iTextCoreProductEvent = (ITextCoreProductEvent)events[0];
NUnit.Framework.Assert.AreEqual(ITextCoreProductEvent.PROCESS_PDF, iTextCoreProductEvent.GetEventType());
Expand All @@ -209,12 +198,8 @@ public virtual void SignCMSContainerWithBaselineLTProfileEventHandlingTest() {
NUnit.Framework.Assert.IsTrue(events[3] is ConfirmEvent);
confirmEvent = (ConfirmEvent)events[3];
NUnit.Framework.Assert.AreEqual(iTextCoreProductEvent, confirmEvent.GetConfirmedEvent());
NUnit.Framework.Assert.IsTrue(events[4] is ITextCoreProductEvent);
NUnit.Framework.Assert.AreEqual(ITextCoreProductEvent.PROCESS_PDF, ((ITextCoreProductEvent)events[4]).GetEventType
());
}

// Third ITextCoreProductEvent contains SignMetaInfo (getter is package-private), so it is not confirmed.
[NUnit.Framework.Test]
public virtual void SignCMSContainerWithBaselineLTAProfileEventHandlingTest() {
ByteArrayOutputStream @out = new ByteArrayOutputStream();
Expand All @@ -234,7 +219,7 @@ public virtual void SignCMSContainerWithBaselineLTAProfileEventHandlingTest() {
(preparedDoc.ToArray())), @out, "Signature1", container);
}
IList<AbstractContextBasedITextEvent> events = handler.GetEvents();
NUnit.Framework.Assert.AreEqual(5, events.Count);
NUnit.Framework.Assert.AreEqual(4, events.Count);
NUnit.Framework.Assert.IsTrue(events[0] is ITextCoreProductEvent);
ITextCoreProductEvent iTextCoreProductEvent = (ITextCoreProductEvent)events[0];
NUnit.Framework.Assert.AreEqual(ITextCoreProductEvent.PROCESS_PDF, iTextCoreProductEvent.GetEventType());
Expand All @@ -249,12 +234,8 @@ public virtual void SignCMSContainerWithBaselineLTAProfileEventHandlingTest() {
NUnit.Framework.Assert.IsTrue(events[3] is ConfirmEvent);
confirmEvent = (ConfirmEvent)events[3];
NUnit.Framework.Assert.AreEqual(iTextCoreProductEvent, confirmEvent.GetConfirmedEvent());
NUnit.Framework.Assert.IsTrue(events[4] is ITextCoreProductEvent);
NUnit.Framework.Assert.AreEqual(ITextCoreProductEvent.PROCESS_PDF, ((ITextCoreProductEvent)events[4]).GetEventType
());
}

// Third ITextCoreProductEvent contains SignMetaInfo (getter is package-private), so it is not confirmed.
[NUnit.Framework.Test]
public virtual void PassSignMetaInfoThroughStampingPropertiesTest() {
ByteArrayOutputStream @out = new ByteArrayOutputStream();
Expand All @@ -269,16 +250,9 @@ public virtual void PassSignMetaInfoThroughStampingPropertiesTest() {
(new SignMetaInfo()));
padesSigner.SignWithBaselineLTProfile(signerProperties, signRsaChain, signRsaPrivateKey, testTsa);
IList<AbstractContextBasedITextEvent> events = handler.GetEvents();
NUnit.Framework.Assert.AreEqual(2, events.Count);
NUnit.Framework.Assert.IsTrue(events[0] is ITextCoreProductEvent);
ITextCoreProductEvent iTextCoreProductEvent = (ITextCoreProductEvent)events[0];
NUnit.Framework.Assert.AreEqual(ITextCoreProductEvent.PROCESS_PDF, iTextCoreProductEvent.GetEventType());
NUnit.Framework.Assert.IsTrue(events[1] is ITextCoreProductEvent);
NUnit.Framework.Assert.AreEqual(ITextCoreProductEvent.PROCESS_PDF, ((ITextCoreProductEvent)events[1]).GetEventType
());
NUnit.Framework.Assert.AreEqual(0, events.Count);
}

// Both ITextCoreProductEvents contain SignMetaInfo, so they are both not confirmed.
private class TestConfigurationEvent : AbstractITextConfigurationEvent {
protected override void DoAction() {
throw new InvalidOperationException();
Expand All @@ -289,17 +263,19 @@ public virtual IList<AbstractProductProcessITextEvent> GetPublicEvents(SequenceI
}
}

private class StoreEventsHandler : IEventHandler {
private class StoreEventsHandler : AbstractContextBasedEventHandler {
private readonly IList<AbstractContextBasedITextEvent> events = new List<AbstractContextBasedITextEvent>();

protected internal StoreEventsHandler(IContext onUnknownContext)
: base(onUnknownContext) {
}

public virtual IList<AbstractContextBasedITextEvent> GetEvents() {
return events;
}

public virtual void OnEvent(IEvent @event) {
if (@event is AbstractContextBasedITextEvent) {
events.Add((AbstractContextBasedITextEvent)@event);
}
protected override void OnAcceptedEvent(AbstractContextBasedITextEvent @event) {
events.Add(@event);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public virtual iText.Signatures.Validation.V1.AssertValidationReport HasLogItems
return this;
}

public virtual iText.Signatures.Validation.V1.AssertValidationReport HasLogItems(int count, Action<AssertValidationReport.AssertValidationReportLogItem
> c) {
return this.HasLogItems(count, count, c);
}

public virtual iText.Signatures.Validation.V1.AssertValidationReport HasStatus(ValidationReport.ValidationResult
expectedStatus) {
chain.SetNext((new AssertValidationReport.StatusCheck(expectedStatus)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Signatures.Testutils;
using iText.Signatures.Testutils.Builder;
using iText.Signatures.Validation.V1.Context;
using iText.Signatures.Validation.V1.Mocks;
using iText.Signatures.Validation.V1.Report;
using iText.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Signatures.Testutils;
using iText.Signatures.Validation.V1.Context;
using iText.Signatures.Validation.V1.Extensions;
using iText.Signatures.Validation.V1.Mocks;
using iText.Signatures.Validation.V1.Report;
using iText.Test;

Expand Down
Loading

0 comments on commit 7b4c7c6

Please sign in to comment.