Skip to content

Commit 61e27ec

Browse files
committed
Merge branch 'develop' into devsecops
2 parents e48be17 + 4e2c229 commit 61e27ec

File tree

25 files changed

+959
-30
lines changed

25 files changed

+959
-30
lines changed

itext.tests/itext.commons.tests/itext/commons/utils/StringNormalizerTest.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2020
You should have received a copy of the GNU Affero General Public License
2121
along with this program. If not, see <https://www.gnu.org/licenses/>.
2222
*/
23+
using iText.Test;
24+
2325
namespace iText.Commons.Utils {
2426
[NUnit.Framework.Category("UnitTest")]
25-
public class StringNormalizerTest {
27+
public class StringNormalizerTest : ExtendedITextTest {
2628
[NUnit.Framework.Test]
2729
public virtual void ToLowerCaseTest() {
2830
NUnit.Framework.Assert.IsNull(StringNormalizer.ToLowerCase(null));

itext.tests/itext.forms.tests/itext/forms/RectangleIntegrationTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ You should have received a copy of the GNU Affero General Public License
2929

3030
namespace iText.Forms {
3131
[NUnit.Framework.Category("IntegrationTest")]
32-
public class RectangleIntegrationTest {
32+
public class RectangleIntegrationTest : ExtendedITextTest {
3333
private static readonly String DESTINATION_FOLDER = TestUtil.GetOutputPath() + "/forms/RectangleTest/";
3434

3535
private static readonly String SOURCE_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2025 Apryse Group NV
4+
Authors: Apryse Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
24+
using System;
25+
using System.Net;
26+
using iText.Commons.Utils;
27+
using iText.Test;
28+
29+
namespace iText.IO.Resolver.Resource {
30+
//\cond DO_NOT_DOCUMENT
31+
[NUnit.Framework.Category("IntegrationTest")]
32+
internal class DefaultResourceRetrieverTest : ExtendedITextTest {
33+
[NUnit.Framework.Test]
34+
public virtual void RetrieveResourceConnectTimeoutTest() {
35+
bool exceptionThrown = false;
36+
Uri url = new Uri("http://10.255.255.1/");
37+
DefaultResourceRetriever resourceRetriever = new DefaultResourceRetriever();
38+
resourceRetriever.SetConnectTimeout(500);
39+
40+
try {
41+
// We check 2 possible exceptions
42+
resourceRetriever.GetInputStreamByUrl(url);
43+
}
44+
catch (WebException e) {
45+
exceptionThrown = true;
46+
// Do not check exception message because it is localized
47+
}
48+
catch (OperationCanceledException e) {
49+
exceptionThrown = true;
50+
NUnit.Framework.Assert.AreEqual("the operation was canceled.", StringNormalizer.ToLowerCase(e.Message));
51+
}
52+
53+
NUnit.Framework.Assert.True(exceptionThrown);
54+
}
55+
}
56+
//\endcond
57+
}
Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2025 Apryse Group NV
4+
Authors: Apryse Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
using System;
24+
using System.IO;
25+
using iText.IO.Exceptions;
26+
using iText.Test;
27+
28+
namespace iText.IO.Resolver.Resource {
29+
[NUnit.Framework.Category("UnitTest")]
30+
public class LimitedInputStreamTest : ExtendedITextTest {
31+
[NUnit.Framework.Test]
32+
public virtual void ReadingByteAfterFileReadingTest() {
33+
using (Stream stream = new LimitedInputStream(new LimitedInputStreamTest.TestStreamGenerator().OpenStream(
34+
), 100)) {
35+
// The user can call the reading methods as many times as he want, and if the
36+
// stream has been read, then should not throw an ReadingByteLimitException exception
37+
for (int i = 0; i < 101; i++) {
38+
NUnit.Framework.Assert.DoesNotThrow(() => stream.Read());
39+
}
40+
}
41+
}
42+
43+
[NUnit.Framework.Test]
44+
public virtual void ReadingByteArrayAfterFileReadingTest() {
45+
using (Stream stream = new LimitedInputStream(new LimitedInputStreamTest.TestStreamGenerator().OpenStream(
46+
), 100)) {
47+
// The user can call the reading methods as many times as he want, and if the
48+
// stream has been read, then should not throw an ReadingByteLimitException exception
49+
NUnit.Framework.Assert.DoesNotThrow(() => stream.Read(new byte[100]));
50+
NUnit.Framework.Assert.DoesNotThrow(() => stream.Read(new byte[1]));
51+
}
52+
}
53+
54+
[NUnit.Framework.Test]
55+
public virtual void ReadingByteArrayWithOffsetAfterFileReadingTest() {
56+
using (Stream stream = new LimitedInputStream(new LimitedInputStreamTest.TestStreamGenerator().OpenStream(
57+
), 100)) {
58+
// The user can call the reading methods as many times as he want, and if the
59+
// stream has been read, then should not throw an ReadingByteLimitException exception
60+
NUnit.Framework.Assert.DoesNotThrow(() => {
61+
stream.JRead(new byte[100], 0, 100);
62+
}
63+
);
64+
NUnit.Framework.Assert.DoesNotThrow(() => {
65+
stream.JRead(new byte[1], 0, 1);
66+
}
67+
);
68+
}
69+
}
70+
71+
[NUnit.Framework.Test]
72+
public virtual void ReadingByteWithLimitOfOneLessThenFileSizeTest() {
73+
using (Stream stream = new LimitedInputStream(new LimitedInputStreamTest.TestStreamGenerator().OpenStream(
74+
), 88)) {
75+
for (int i = 0; i < 88; i++) {
76+
NUnit.Framework.Assert.AreNotEqual(-1, stream.Read());
77+
}
78+
NUnit.Framework.Assert.Catch(typeof(ReadingByteLimitException), () => stream.Read());
79+
}
80+
}
81+
82+
[NUnit.Framework.Test]
83+
public virtual void ReadingByteArrayWithLimitOfOneLessThenFileSizeTest() {
84+
using (Stream stream = new LimitedInputStream(new LimitedInputStreamTest.TestStreamGenerator().OpenStream(
85+
), 88)) {
86+
byte[] bytes = new byte[100];
87+
int numOfReadBytes = stream.Read(bytes);
88+
NUnit.Framework.Assert.AreEqual(88, numOfReadBytes);
89+
NUnit.Framework.Assert.AreEqual(10, bytes[87]);
90+
NUnit.Framework.Assert.AreEqual(0, bytes[88]);
91+
NUnit.Framework.Assert.Catch(typeof(ReadingByteLimitException), () => stream.Read(new byte[1]));
92+
}
93+
}
94+
95+
[NUnit.Framework.Test]
96+
public virtual void ReadingByteArrayWithOffsetAndLimitOfOneLessThenFileSizeTest() {
97+
using (Stream stream = new LimitedInputStream(new LimitedInputStreamTest.TestStreamGenerator().OpenStream(
98+
), 88)) {
99+
byte[] bytes = new byte[100];
100+
int numOfReadBytes = stream.JRead(bytes, 0, 88);
101+
NUnit.Framework.Assert.AreEqual(88, numOfReadBytes);
102+
NUnit.Framework.Assert.AreEqual(10, bytes[87]);
103+
NUnit.Framework.Assert.AreEqual(0, bytes[88]);
104+
NUnit.Framework.Assert.Catch(typeof(ReadingByteLimitException), () => stream.JRead(bytes, 88, 1));
105+
}
106+
}
107+
108+
[NUnit.Framework.Test]
109+
public virtual void ReadingByteArrayWithSmallBufferTest() {
110+
using (Stream stream = new LimitedInputStream(new LimitedInputStreamTest.TestStreamGenerator().OpenStream(
111+
), 89)) {
112+
byte[] bytes = new byte[20];
113+
MemoryStream output = new MemoryStream();
114+
while (true) {
115+
int read = stream.Read(bytes);
116+
if (read < 1) {
117+
break;
118+
}
119+
output.Write(bytes, 0, read);
120+
}
121+
NUnit.Framework.Assert.AreEqual(89, output.Length);
122+
output.Dispose();
123+
}
124+
}
125+
126+
[NUnit.Framework.Test]
127+
public virtual void ReadingByteArrayWithBigBufferTest() {
128+
// retrieveStyleSheetTest.css.dat size is 89 bytes
129+
using (Stream stream = new LimitedInputStream(new LimitedInputStreamTest.TestStreamGenerator().OpenStream(
130+
), 89)) {
131+
byte[] bytes = new byte[100];
132+
NUnit.Framework.Assert.AreEqual(89, stream.Read(bytes));
133+
byte[] tempBytes = (byte[])bytes.Clone();
134+
NUnit.Framework.Assert.AreEqual(-1, stream.Read(bytes));
135+
// Check that the array has not changed when we have read the entire LimitedInputStream
136+
NUnit.Framework.Assert.AreEqual(tempBytes, bytes);
137+
}
138+
}
139+
140+
[NUnit.Framework.Test]
141+
public virtual void ReadingByteArrayWithOffsetAndBigBufferTest() {
142+
using (Stream stream = new LimitedInputStream(new LimitedInputStreamTest.TestStreamGenerator().OpenStream(
143+
), 89)) {
144+
byte[] bytes = new byte[100];
145+
NUnit.Framework.Assert.AreEqual(89, stream.JRead(bytes, 0, 100));
146+
byte[] tempBytes = (byte[])bytes.Clone();
147+
NUnit.Framework.Assert.AreEqual(-1, stream.JRead(bytes, 0, 100));
148+
// Check that the array has not changed when we have read the entire LimitedInputStream
149+
NUnit.Framework.Assert.AreEqual(tempBytes, bytes);
150+
}
151+
}
152+
153+
[NUnit.Framework.Test]
154+
public virtual void ByteArrayOverwritingTest() {
155+
using (Stream stream = new LimitedInputStream(new LimitedInputStreamTest.TestStreamGenerator().OpenStream(
156+
), 90)) {
157+
byte[] bytes = new byte[100];
158+
bytes[89] = 13;
159+
NUnit.Framework.Assert.AreEqual(89, stream.Read(bytes));
160+
// Check that when calling the read(byte[]) method, as many bytes were copied into
161+
// the original array as were read, and not all bytes from the auxiliary array.
162+
NUnit.Framework.Assert.AreEqual(13, bytes[89]);
163+
}
164+
}
165+
166+
[NUnit.Framework.Test]
167+
public virtual void ReadingByteWithZeroLimitTest() {
168+
using (LimitedInputStream stream = new LimitedInputStream(new MemoryStream(new byte[1]), 0)) {
169+
NUnit.Framework.Assert.Catch(typeof(ReadingByteLimitException), () => stream.Read());
170+
}
171+
}
172+
173+
[NUnit.Framework.Test]
174+
public virtual void ReadingByteArrayWithZeroLimitTest() {
175+
using (LimitedInputStream stream = new LimitedInputStream(new MemoryStream(new byte[1]), 0)) {
176+
byte[] bytes = new byte[100];
177+
NUnit.Framework.Assert.Catch(typeof(ReadingByteLimitException), () => stream.Read(bytes));
178+
}
179+
}
180+
181+
[NUnit.Framework.Test]
182+
public virtual void ReadingByteArrayWithOffsetAndZeroLimitTest() {
183+
using (LimitedInputStream stream = new LimitedInputStream(new MemoryStream(new byte[1]), 0)) {
184+
byte[] bytes = new byte[100];
185+
NUnit.Framework.Assert.Catch(typeof(ReadingByteLimitException), () => stream.JRead(bytes, 0, 100));
186+
}
187+
}
188+
189+
[NUnit.Framework.Test]
190+
public virtual void ReadingEmptyByteWithZeroLimitTest() {
191+
using (LimitedInputStream stream = new LimitedInputStream(new MemoryStream(new byte[0]), 0)) {
192+
NUnit.Framework.Assert.AreEqual(-1, stream.Read());
193+
}
194+
}
195+
196+
[NUnit.Framework.Test]
197+
public virtual void ReadingEmptyByteArrayWithZeroLimitTest() {
198+
using (LimitedInputStream stream = new LimitedInputStream(new MemoryStream(new byte[0]), 0)) {
199+
byte[] bytes = new byte[100];
200+
NUnit.Framework.Assert.AreEqual(-1, stream.Read(bytes));
201+
}
202+
}
203+
204+
[NUnit.Framework.Test]
205+
public virtual void ReadingEmptyByteArrayWithOffsetAndZeroLimitTest() {
206+
using (LimitedInputStream stream = new LimitedInputStream(new MemoryStream(new byte[0]), 0)) {
207+
byte[] bytes = new byte[100];
208+
NUnit.Framework.Assert.AreEqual(-1, stream.JRead(bytes, 0, 100));
209+
}
210+
}
211+
212+
[NUnit.Framework.Test]
213+
public virtual void IllegalReadingByteLimitValueTest() {
214+
Exception e = NUnit.Framework.Assert.Catch(typeof(ArgumentException), () => new LimitedInputStream(new MemoryStream
215+
(new byte[0]), -1));
216+
NUnit.Framework.Assert.AreEqual(IoExceptionMessageConstant.READING_BYTE_LIMIT_MUST_NOT_BE_LESS_ZERO, e.Message
217+
);
218+
}
219+
220+
//\cond DO_NOT_DOCUMENT
221+
internal class TestStreamGenerator {
222+
//\cond DO_NOT_DOCUMENT
223+
internal String data = "body {\n" + " background-color: lightblue;\n" + "}\n" + "\n" + "h1 {\n" + " color: navy;\n"
224+
+ " margin-left: 20px;\n" + "}";
225+
//\endcond
226+
227+
//\cond DO_NOT_DOCUMENT
228+
internal virtual Stream OpenStream() {
229+
return new MemoryStream(data.GetBytes(System.Text.Encoding.UTF8));
230+
}
231+
//\endcond
232+
}
233+
//\endcond
234+
}
235+
}

itext.tests/itext.kernel.tests/itext/kernel/pdf/layer/PdfOCPropertiesUnitTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ You should have received a copy of the GNU Affero General Public License
2424
using System.IO;
2525
using iText.IO.Source;
2626
using iText.Kernel.Pdf;
27+
using iText.Test;
2728

2829
namespace iText.Kernel.Pdf.Layer {
2930
[NUnit.Framework.Category("UnitTest")]
30-
public class PdfOCPropertiesUnitTest {
31+
public class PdfOCPropertiesUnitTest : ExtendedITextTest {
3132
[NUnit.Framework.Test]
3233
public virtual void OrderArrayOcgWithTwoParentsTest() {
3334
byte[] docBytes;

itext.tests/itext.pdftest.tests/itext/test/AssertUtilTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ You should have received a copy of the GNU Affero General Public License
2323
using System;
2424

2525
namespace iText.Test {
26-
internal class AssertUtilTest {
26+
[NUnit.Framework.Category("UnitTest")]
27+
internal class AssertUtilTest : ExtendedITextTest {
2728
[NUnit.Framework.Test]
2829
public void AssertPassedWithinTimeoutTestKeepsFailing() {
2930
var callCount = 0;

itext.tests/itext.sign.tests/itext/signatures/IssuingCertificateRetrieverTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ You should have received a copy of the GNU Affero General Public License
3131

3232
namespace iText.Signatures {
3333
//\cond DO_NOT_DOCUMENT
34+
[NUnit.Framework.Category("IntegrationTest")]
3435
internal class IssuingCertificateRetrieverTest : ExtendedITextTest {
3536
private static readonly String CERTS_SRC = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
3637
.CurrentContext.TestDirectory) + "/resources/itext/signatures/certs/";

0 commit comments

Comments
 (0)