Skip to content

Commit 4fc2f5a

Browse files
committed
Add possibility to skip long running unit tests for DoS attacks.
1 parent 662de6b commit 4fc2f5a

File tree

1 file changed

+35
-9
lines changed

1 file changed

+35
-9
lines changed

xstream/src/test/com/thoughtworks/acceptance/SecurityVulnerabilityTest.java

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2013, 2014, 2017, 2018, 2020, 2021, 2022, 2024 XStream Committers.
2+
* Copyright (C) 2013, 2014, 2017, 2018, 2020, 2021, 2022, 2024, 2025 XStream Committers.
33
* All rights reserved.
44
*
55
* The software in this package is published under the terms of the BSD
@@ -42,6 +42,7 @@
4242
public class SecurityVulnerabilityTest extends AbstractAcceptanceTest {
4343

4444
private final static StringBuffer BUFFER = new StringBuffer();
45+
private final static boolean SKIP_DOS_ATTACK_TESTS = Boolean.getBoolean("skipDoSAttackTests");
4546

4647
@Override
4748
protected void setUp() throws Exception {
@@ -52,13 +53,25 @@ protected void setUp() throws Exception {
5253
xstream.addPermission(ProxyTypePermission.PROXIES);
5354
}
5455

56+
@Override
57+
protected void setupSecurity(final XStream xstream) {
58+
xstream.allowTypes(Exec.class);
59+
}
60+
61+
public static class Exec {
62+
63+
public void exec() {
64+
BUFFER.append("Executed!");
65+
}
66+
}
67+
5568
public void testCannotInjectEventHandler() {
5669
final String xml = ""
5770
+ "<string class='runnable-array'>\n"
5871
+ " <dynamic-proxy>\n"
5972
+ " <interface>java.lang.Runnable</interface>\n"
6073
+ " <handler class='java.beans.EventHandler'>\n"
61-
+ " <target class='com.thoughtworks.acceptance.SecurityVulnerabilityTest$Exec'/>\n"
74+
+ " <target class='com.thoughtworks.acceptance.SecurityVulnerabilityTest_-Exec'/>\n"
6275
+ " <action>exec</action>\n"
6376
+ " </handler>\n"
6477
+ " </dynamic-proxy>\n"
@@ -213,13 +226,6 @@ public void testExplicitlyConvertSwingUIDefaults() {
213226
assertNotNull(hashtable);
214227
}
215228

216-
public static class Exec {
217-
218-
public void exec() {
219-
BUFFER.append("Executed!");
220-
}
221-
}
222-
223229
public void testInstanceOfVoid() {
224230
try {
225231
xstream.fromXML("<void/>");
@@ -353,6 +359,10 @@ public void testExplicitlyUnmarshalEndlessByteArrayInputStream() throws IOExcept
353359
}
354360

355361
public void testDoSAttackWithHashSet() {
362+
if (SKIP_DOS_ATTACK_TESTS) {
363+
return;
364+
}
365+
356366
final Set<Object> set = new HashSet<>();
357367
Set<Object> s1 = set;
358368
Set<Object> s2 = new HashSet<>();
@@ -380,6 +390,10 @@ public void testDoSAttackWithHashSet() {
380390
}
381391

382392
public void testDoSAttackWithLinkedHashSet() {
393+
if (SKIP_DOS_ATTACK_TESTS) {
394+
return;
395+
}
396+
383397
final Set<Object> set = new LinkedHashSet<>();
384398
Set<Object> s1 = set;
385399
Set<Object> s2 = new LinkedHashSet<>();
@@ -407,6 +421,10 @@ public void testDoSAttackWithLinkedHashSet() {
407421
}
408422

409423
public void testDoSAttackWithHashMap() {
424+
if (SKIP_DOS_ATTACK_TESTS) {
425+
return;
426+
}
427+
410428
final Map<Object, Object> map = new HashMap<>();
411429
Map<Object, Object> m1 = map;
412430
Map<Object, Object> m2 = new HashMap<>();
@@ -434,6 +452,10 @@ public void testDoSAttackWithHashMap() {
434452
}
435453

436454
public void testDoSAttackWithLinkedHashMap() {
455+
if (SKIP_DOS_ATTACK_TESTS) {
456+
return;
457+
}
458+
437459
final Map<Object, Object> map = new LinkedHashMap<>();
438460
Map<Object, Object> m1 = map;
439461
Map<Object, Object> m2 = new LinkedHashMap<>();
@@ -461,6 +483,10 @@ public void testDoSAttackWithLinkedHashMap() {
461483
}
462484

463485
public void testDoSAttackWithHashtable() {
486+
if (SKIP_DOS_ATTACK_TESTS) {
487+
return;
488+
}
489+
464490
final Map<Object, Object> map = new Hashtable<>();
465491
Map<Object, Object> m1 = map;
466492
Map<Object, Object> m2 = new Hashtable<>();

0 commit comments

Comments
 (0)