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/03 10:41:04 UTC

svn commit: r1759071 - in /ofbiz/trunk/framework/base/src/test: ./ java/ java/org/ java/org/apache/ java/org/apache/ofbiz/ java/org/apache/ofbiz/base/ java/org/apache/ofbiz/base/util/ java/org/apache/ofbiz/base/util/UtilCodecTests.java

Author: jacopoc
Date: Sat Sep  3 10:41:04 2016
New Revision: 1759071

URL: http://svn.apache.org/viewvc?rev=1759071&view=rev
Log:
A couple of unit tests for the UtilCodec class.
Hopefully, now that Gradle provides the tools to build effective unit tests (thanks to the great work by Taher), the test coverage of the framework will improve: contributions are welcome! 

Added:
    ofbiz/trunk/framework/base/src/test/
    ofbiz/trunk/framework/base/src/test/java/
    ofbiz/trunk/framework/base/src/test/java/org/
    ofbiz/trunk/framework/base/src/test/java/org/apache/
    ofbiz/trunk/framework/base/src/test/java/org/apache/ofbiz/
    ofbiz/trunk/framework/base/src/test/java/org/apache/ofbiz/base/
    ofbiz/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/
    ofbiz/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/UtilCodecTests.java   (with props)

Added: 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=1759071&view=auto
==============================================================================
--- ofbiz/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/UtilCodecTests.java (added)
+++ ofbiz/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/UtilCodecTests.java Sat Sep  3 10:41:04 2016
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *******************************************************************************/
+package org.apache.ofbiz.base.util;
+
+import java.util.List;
+import java.util.ArrayList;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class UtilCodecTests {
+
+    @Test
+    public void canonicalizeRevealsEscapedXSS() {
+        String xssVector = "<script&gtalert(\"XSS vector\");</script>";
+        String canonicalizedXssVector = UtilCodec.canonicalize(xssVector, true, true);
+        assertEquals("<script>alert(\"XSS vector\");</script>", canonicalizedXssVector);
+    }
+
+    @Test
+    public void checkStringForHtmlStrictNoneDetectsXSS() {
+        String xssVector = "&lt;script&gtalert(\"XSS vector\");&lt;/script&gt;";
+        List<String> errorList = new ArrayList<>();
+        String canonicalizedXssVector = UtilCodec.checkStringForHtmlStrictNone("fieldName", xssVector, errorList);
+        assertEquals("<script>alert(\"XSS vector\");</script>", canonicalizedXssVector);
+        assertEquals(1, errorList.size());
+        assertEquals("In field [fieldName] less-than (<) and greater-than (>) symbols are not allowed.", errorList.get(0));
+    }
+}

Propchange: ofbiz/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/UtilCodecTests.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/UtilCodecTests.java
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: ofbiz/trunk/framework/base/src/test/java/org/apache/ofbiz/base/util/UtilCodecTests.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain