You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2016/09/09 15:54:01 UTC
svn commit: r1760047 - in /ofbiz/trunk/framework/base:
src/main/java/org/apache/ofbiz/base/util/test/UtilCodecTests.java
src/test/java/org/apache/ofbiz/base/util/UtilCodecTests.java
testdef/basetests.xml
Author: jacopoc
Date: Fri Sep 9 15:54:01 2016
New Revision: 1760047
URL: http://svn.apache.org/viewvc?rev=1760047&view=rev
Log:
Migrated unit tests for UtilCodec defined in the old "integration test" group to the new class that contains actual unit tests for the UtilCodec class.
Removed:
ofbiz/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/test/UtilCodecTests.java
Modified:
ofbiz/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/UtilCodecTests.java
ofbiz/trunk/framework/base/testdef/basetests.xml
Modified: ofbiz/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/UtilCodecTests.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/UtilCodecTests.java?rev=1760047&r1=1760046&r2=1760047&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/UtilCodecTests.java (original)
+++ ofbiz/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/UtilCodecTests.java Fri Sep 9 15:54:01 2016
@@ -18,6 +18,7 @@
*******************************************************************************/
package org.apache.ofbiz.base.util;
+import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import org.junit.Test;
@@ -41,4 +42,41 @@ public class UtilCodecTests {
assertEquals(1, errorList.size());
assertEquals("In field [fieldName] less-than (<) and greater-than (>) symbols are not allowed.", errorList.get(0));
}
+
+ @Test
+ public void testGetEncoder() {
+ encoderTest("string", UtilCodec.getEncoder("string"), "abc\\\"def", "abc\"def");
+ encoderTest("xml", UtilCodec.getEncoder("xml"), "<>'"", "<>'\"");
+ encoderTest("html", UtilCodec.getEncoder("html"), "<>'"", "<>'\"");
+ assertNull("invalid encoder", UtilCodec.getEncoder("foobar"));
+ }
+
+ @Test
+ public void testCheckStringForHtmlStrictNone() {
+ checkStringForHtmlStrictNone_test("null pass-thru", null, null);
+ checkStringForHtmlStrictNone_test("empty pass-thru", "", "");
+ checkStringForHtmlStrictNone_test("o-numeric-encode", "foo", "foo");
+ checkStringForHtmlStrictNone_test("o-hex-encode", "foo", "f%6fo");
+ // jacopoc: temporarily commented because this test is failing after the upgrade of owasp-esapi (still investigating)
+ //checkStringForHtmlStrictNone_test("o-double-hex-encode", "foo", "f%256fo");
+ checkStringForHtmlStrictNone_test("<-not-allowed", "f<oo", "f<oo", "In field [<-not-allowed] less-than (<) and greater-than (>) symbols are not allowed.");
+ checkStringForHtmlStrictNone_test(">-not-allowed", "f>oo", "f>oo", "In field [>-not-allowed] less-than (<) and greater-than (>) symbols are not allowed.");
+ // jleroux: temporarily comments because this test is failing on BuildBot (only) when switching to Gradle
+ //checkStringForHtmlStrictNone_test("high-ascii", "fÀ®", "f%C0%AE");
+ // this looks like a bug, namely the extra trailing ;
+ // jacopoc: temporarily commented because this test is failing after the upgrade of owasp-esapi (still investigating)
+ //checkStringForHtmlStrictNone_test("double-ampersand", "f\";oo", "f%26quot%3boo");
+ checkStringForHtmlStrictNone_test("double-encoding", "%2%353Cscript", "%2%353Cscript", "In field [double-encoding] found character escaping (mixed or double) that is not allowed or other format consistency error: org.apache.ofbiz.base.util.UtilCodec$IntrusionException: Input validation failure");
+ }
+
+ private static void encoderTest(String label, UtilCodec.SimpleEncoder encoder, String wanted, String toEncode) {
+ assertNull(label + "(encoder):null", encoder.encode(null));
+ assertEquals(label + "(encoder):encode", wanted, encoder.encode(toEncode));
+ }
+ private static void checkStringForHtmlStrictNone_test(String label, String fixed, String input, String... wantedMessages) {
+ List<String> gottenMessages = new ArrayList<String>();
+ assertEquals(label, fixed, UtilCodec.checkStringForHtmlStrictNone(label, input, gottenMessages));
+ assertEquals(label, Arrays.asList(wantedMessages), gottenMessages);
+ }
+
}
Modified: ofbiz/trunk/framework/base/testdef/basetests.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/testdef/basetests.xml?rev=1760047&r1=1760046&r2=1760047&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/testdef/basetests.xml (original)
+++ ofbiz/trunk/framework/base/testdef/basetests.xml Fri Sep 9 15:54:01 2016
@@ -31,7 +31,6 @@
<junit-test-suite class-name="org.apache.ofbiz.base.util.test.UtilObjectTests"/>
<junit-test-suite class-name="org.apache.ofbiz.base.util.test.StringUtilTests"/>
<junit-test-suite class-name="org.apache.ofbiz.base.util.test.UtilHttpTests"/>
- <junit-test-suite class-name="org.apache.ofbiz.base.util.test.UtilCodecTests"/>
<junit-test-suite class-name="org.apache.ofbiz.base.util.string.test.FlexibleStringExpanderTests"/>
<junit-test-suite class-name="org.apache.ofbiz.base.util.collections.test.FlexibleMapAccessorTests"/>
<junit-test-suite class-name="org.apache.ofbiz.base.util.test.TimeDurationTests"/>