1 64 65 package com.jcorporate.expresso.core.misc.tests; 66 67 import com.jcorporate.expresso.core.misc.CookieUtil; 68 import com.jcorporate.expresso.core.security.CryptoManager; 69 import com.jcorporate.expresso.services.test.ExpressoTestCase; 70 import com.jcorporate.expresso.services.test.TestSystemInitializer; 71 import junit.framework.TestSuite; 72 73 74 80 public class CookieTests 81 extends ExpressoTestCase { 82 boolean usingStrongCrypto; 83 84 public CookieTests(String testName) 85 throws Exception { 86 super(testName); 87 } 88 89 public static void main(String [] args) 90 throws Exception { 91 92 TestSystemInitializer.setUp(); 93 junit.textui.TestRunner.run(suite()); 95 } 96 97 public static junit.framework.Test suite() 98 throws Exception { 99 return new TestSuite(CookieTests.class); 100 } 101 102 107 public void setUp() 108 throws Exception { 109 usingStrongCrypto = CryptoManager.getInstance().isUsingStrongCrypto(); 110 } 111 112 public void tearDown() 113 throws Exception { 114 CryptoManager.getInstance().loadClasses(usingStrongCrypto); 115 } 116 117 124 public void testCookieEncryption() 125 throws Exception { 126 CryptoManager cm = CryptoManager.getInstance(); 127 128 cm.loadClasses(true); 130 131 String [] testArray = { 134 "abcdefghijklmnopqrstuvwxyz", 135 "ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+", "abc", "rimo\n", 136 "rimo\b\r\0", "rimovm01", "9123123456789", "^\"\\...//?.<>", "" 137 }; 138 int i; 139 140 for (i = 0; i < testArray.length; i++) { 141 String encode = CookieUtil.cookieEncode(testArray[i]); 142 String decode = CookieUtil.cookieDecode(encode); 143 144 if (i < testArray.length - 1) { 145 assertTrue("Greater Than Zero Length Return " + testArray[i], 146 encode.length() > 0); 147 } 148 149 assertTrue("testEncryptionMode: testArray[i]", 150 decode.equals(testArray[i])); 151 } 152 153 cm.loadClasses(false); 155 156 for (i = 0; i < testArray.length; i++) { 157 String encode = CookieUtil.cookieEncode(testArray[i]); 158 String decode = CookieUtil.cookieDecode(encode); 159 assertTrue("testEncryptionMode: testArray[i]", 160 decode.equals(testArray[i])); 161 } 162 } 163 } 164 | Popular Tags |