Skip to content

Commit 4f903d3

Browse files
Adding known exception testing for PercentCodec
Making a test that will fail when the UTF16 handling is corrected for the implementation. Also centralizing the test-scope of the immune character set to just the StringTest impl for easier maintenance later when it's replaced.
1 parent 804350f commit 4f903d3

File tree

2 files changed

+3
-30
lines changed

2 files changed

+3
-30
lines changed

src/test/java/org/owasp/esapi/codecs/percent/PercentCodecCharacterTest.java

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package org.owasp.esapi.codecs.percent;
22

3+
import static org.owasp.esapi.codecs.percent.PercentCodecStringTest.PERCENT_CODEC_IMMUNE;
4+
35
import java.util.ArrayList;
46
import java.util.Collection;
5-
import java.util.List;
67

78
import org.junit.Assert;
89
import org.junit.Test;
@@ -16,41 +17,13 @@
1617
*
1718
*/
1819
public class PercentCodecCharacterTest extends AbstractCodecCharacterTest {
19-
private static final char[] PERCENT_CODEC_IMMUNE;
20-
21-
static {
22-
/*
23-
* The percent codec contains a unique immune character set which include letters and numbers that will not be
24-
* transformed.
25-
* It is being replicated here to allow the test to reasonably expect the correct state back.
26-
*/
27-
List<Character> immune = new ArrayList<>();
28-
// 65 - 90 (capital letters) 97 - 122 lower case 48 - 57 digits
29-
// numbers
30-
for (int index = 48; index < 58; index++) {
31-
immune.add((char) index);
32-
}
33-
// letters
34-
for (int index = 65; index < 91; index++) {
35-
Character capsChar = (char) index;
36-
immune.add(capsChar);
37-
immune.add(Character.toLowerCase(capsChar));
38-
}
39-
40-
PERCENT_CODEC_IMMUNE = new char[immune.size()];
41-
for (int index = 0; index < immune.size(); index++) {
42-
PERCENT_CODEC_IMMUNE[index] = immune.get(index).charValue();
43-
}
44-
}
45-
4620
@Parameters(name = "{0}")
4721
public static Collection<Object[]> buildTests() {
4822
Collection<Object[]> tests = new ArrayList<>();
4923

5024
Collection<CodecCharacterTestTuple> tuples = new ArrayList<>();
5125
tuples.add(newTuple("%3C", Character.valueOf('<')));
5226

53-
//CODEPOINT tuples.add(newTuple("%C4%80", Character.valueOf((char) 0x100)));
5427
tuples.add(newTuple("%00", Character.MIN_VALUE));
5528
tuples.add(newTuple("%3D", '='));
5629
tuples.add(newTuple("%26", '&'));

src/test/java/org/owasp/esapi/codecs/percent/PercentCodecStringTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*/
1515
public class PercentCodecStringTest extends AbstractCodecStringTest {
16-
private static final char[] PERCENT_CODEC_IMMUNE;
16+
public static final char[] PERCENT_CODEC_IMMUNE;
1717

1818
static {
1919
/*

0 commit comments

Comments
 (0)