1 64 65 package com.jcorporate.expresso.core.security.filters; 66 67 import com.jcorporate.expresso.services.test.ExpressoTestCase; 68 import junit.framework.TestSuite; 69 70 71 77 public class FilterTest 78 extends ExpressoTestCase { 79 private static final String [] TestStrings = { 80 "abcdefg<>%^lmnop", 81 "\"This is a test of the emergency broadcast system!!!\"", 82 "cat /etc/password", "\\What about This???\\", "\' Or this \'", 83 "& This? ", "And lets just talk about some other stuff\n \t!!", 84 "<a HREF=\"www.nazdome.com\">", 85 "javascript:openWindow(\"Bad Girls dot Com\");" 86 }; 87 FilterManager fm = null; 88 89 public FilterTest(String testName) 90 throws Exception { 91 super(testName); 92 } 93 94 public void setUp() { 95 96 fm = FilterManager.getInstance(); 98 99 if (fm == null) { 100 fail("Filter Manager was NULL!"); 101 102 return; 103 } 104 } 105 106 public static void main(String [] args) 107 throws Exception { 108 junit.textui.TestRunner.run(suite()); 109 } 110 111 public static junit.framework.Test suite() 112 throws Exception { 113 return new TestSuite(FilterTest.class); 114 } 115 116 public void testStandardFilter() 117 throws Exception { 118 final String [] StandardFilterResult = { 119 "abcdefg<>%^lmnop", 120 ""This is a test of the emergency broadcast " + 121 "system!!!"", 122 "cat /etc/password", "\\What about This???\\", "' Or this '", 123 "& This? ", 124 "And lets just talk about some other stuff<br /> !!", 125 "<a HREF="www.nazdome.com">", 126 "javascript:openWindow("Bad Girls " + "dot Com");" 127 }; 128 String result1; 129 String result2; 130 131 for (int i = 0; i < TestStrings.length; i++) { 133 result1 = fm.filterString(TestStrings[i], ISO_8859_1.class, 134 "standardFilter"); 135 assertTrue("Standard Filter Round 1: i=" + Integer.toString(i), 136 result1.equals(StandardFilterResult[i])); 137 138 result2 = fm.filterString(result1, ISO_8859_1.class, 141 "standardFilter"); 142 assertTrue("Standard Filter Round 2: i=" + Integer.toString(i), 143 result2.equals(result1)); 144 } 145 } 146 147 public void testStripFilter() 148 throws Exception { 149 final String [] StripFilterResult = { 159 "abcdefg%^lmnop", 160 "This is a test of the emergency broadcast system!!!", 161 "cat /etc/password", "\\What about This???\\", "' Or this '", 162 " This? ", "And lets just talk about some other stuff !!", 163 "a HREF=www.nazdome.com", 164 "javascript:openWindow(Bad Girls dot Com);" 165 }; 166 167 String result1; 168 String result2; 169 170 for (int i = 0; i < TestStrings.length; i++) { 171 result1 = fm.filterString(TestStrings[i], ISO_8859_1.class, 172 "stripFilter"); 173 assertTrue("Strip Filter Round 1: i=" + Integer.toString(i), 174 result1.equals(StripFilterResult[i])); 175 176 result2 = fm.filterString(result1, ISO_8859_1.class, 179 "stripFilter"); 180 assertTrue("Strip Filter Round 2: i=" + Integer.toString(i), 181 result2.equals(result1)); 182 } 183 } 184 185 public void testRawFilter() 186 throws Exception { 187 final String [] RawFilterResult = { 188 "abcdefg<>%^lmnop", 189 "\"This is a test of the emergency broadcast system!!!\"", 190 "cat /etc/password", "\\What about This???\\", "\' Or this \'", 191 "& This? ", "And lets just talk about some other stuff\n \t!!", 192 "<a HREF=\"www.nazdome.com\">", 193 "javascript:openWindow(\"Bad Girls dot Com\");" 194 }; 195 String result1; 196 String result2; 197 198 for (int i = 0; i < TestStrings.length; i++) { 199 result1 = fm.filterString(TestStrings[i], ISO_8859_1.class, 200 "rawFilter"); 201 assertTrue("Raw Filter Rount 1: i=" + Integer.toString(i), 202 result1.equals(RawFilterResult[i])); 203 204 result2 = fm.filterString(result1, ISO_8859_1.class, 207 "rawFilter"); 208 assertTrue("Raw Filter Rount 2: i=" + Integer.toString(i), 209 result2.equals(result1)); 210 } 211 } 212 239 243 public void testBadFiltername() 244 throws Exception { 245 String temp; 246 247 try { 248 temp = fm.filterString(TestStrings[0], ISO_8859_1.class, 249 "badFilterName"); 250 fail("Failed Test: Bad FilterName parameter"); 251 252 return; 253 } catch (IllegalArgumentException e) { 254 } 255 } 256 257 } | Popular Tags |