1 13 14 package se.anatom.ejbca.ca.store; 15 16 import java.util.ArrayList ; 17 18 import javax.naming.Context ; 19 import javax.naming.NamingException ; 20 21 import junit.framework.TestCase; 22 23 import org.apache.log4j.Logger; 24 import org.ejbca.core.ejb.ca.store.ICertificateStoreSessionHome; 25 import org.ejbca.core.ejb.ca.store.ICertificateStoreSessionRemote; 26 import org.ejbca.core.model.ca.certificateprofiles.CertificateProfile; 27 import org.ejbca.core.model.ca.certificateprofiles.CertificateProfileExistsException; 28 import org.ejbca.core.model.ca.certificateprofiles.EndUserCertificateProfile; 29 import org.ejbca.core.model.log.Admin; 30 import org.ejbca.util.dn.DNFieldExtractor; 31 32 33 38 public class TestCertificateProfile extends TestCase { 39 private static Logger log = Logger.getLogger(TestCertificateProfile.class); 40 41 private static ICertificateStoreSessionRemote cacheAdmin; 42 private static ICertificateStoreSessionHome cacheHome; 43 44 private static final Admin admin = new Admin(Admin.TYPE_INTERNALUSER); 45 46 51 public TestCertificateProfile(String name) { 52 super(name); 53 } 54 55 protected void setUp() throws Exception { 56 log.debug(">setUp()"); 57 if (cacheAdmin == null) { 58 if (cacheHome == null) { 59 Context jndiContext = getInitialContext(); 60 Object obj1 = jndiContext.lookup("CertificateStoreSession"); 61 cacheHome = (ICertificateStoreSessionHome) javax.rmi.PortableRemoteObject.narrow(obj1, ICertificateStoreSessionHome.class); 62 } 63 cacheAdmin = cacheHome.create(); 64 } 65 log.debug("<setUp()"); 66 } 67 68 protected void tearDown() throws Exception { 69 } 70 71 private Context getInitialContext() throws NamingException { 72 log.debug(">getInitialContext"); 73 Context ctx = new javax.naming.InitialContext (); 74 log.debug("<getInitialContext"); 75 return ctx; 76 } 77 78 79 84 public void test01AddCertificateProfile() throws Exception { 85 log.debug(">test01AddCertificateProfile()"); 86 boolean ret = false; 87 try { 88 CertificateProfile profile = new CertificateProfile(); 89 profile.setCRLDistributionPointURI("TEST"); 90 cacheAdmin.addCertificateProfile(admin, "TEST", profile); 91 ret = true; 92 } catch (CertificateProfileExistsException pee) { 93 } 94 95 assertTrue("Creating Certificate Profile failed", ret); 96 log.debug("<test01AddCertificateProfile()"); 97 } 98 99 104 public void test02RenameCertificateProfile() throws Exception { 105 log.debug(">test02RenameCertificateProfile()"); 106 107 boolean ret = false; 108 try { 109 cacheAdmin.renameCertificateProfile(admin, "TEST", "TEST2"); 110 ret = true; 111 } catch (CertificateProfileExistsException pee) { 112 } 113 assertTrue("Renaming Certificate Profile failed", ret); 114 115 log.debug("<test02RenameCertificateProfile()"); 116 } 117 118 123 public void test03CloneCertificateProfile() throws Exception { 124 log.debug(">test03CloneCertificateProfile()"); 125 boolean ret = false; 126 try { 127 cacheAdmin.cloneCertificateProfile(admin, "TEST2", "TEST"); 128 ret = true; 129 } catch (CertificateProfileExistsException pee) { 130 } 131 assertTrue("Cloning Certificate Profile failed", ret); 132 log.debug("<test03CloneCertificateProfile()"); 133 } 134 135 136 141 public void test04EditCertificateProfile() throws Exception { 142 log.debug(">test04EditCertificateProfile()"); 143 144 boolean ret = false; 145 146 CertificateProfile profile = cacheAdmin.getCertificateProfile(admin, "TEST"); 147 assertTrue("Retrieving CertificateProfile failed", profile.getCRLDistributionPointURI().equals("TEST")); 148 149 profile.setCRLDistributionPointURI("TEST2"); 150 151 cacheAdmin.changeCertificateProfile(admin, "TEST", profile); 152 ret = true; 153 154 assertTrue("Editing CertificateProfile failed", ret); 155 156 157 log.debug("<test04EditCertificateProfile()"); 158 } 159 160 161 166 public void test05removeCertificateProfiles() throws Exception { 167 log.debug(">test05removeCertificateProfiles()"); 168 boolean ret = false; 169 try { 170 cacheAdmin.removeCertificateProfile(admin, "TEST"); 171 cacheAdmin.removeCertificateProfile(admin, "TEST2"); 172 ret = true; 173 } catch (Exception pee) { 174 } 175 assertTrue("Removing Certificate Profile failed", ret); 176 177 log.debug("<test05removeCertificateProfiles()"); 178 } 179 180 public void test06createSubjectDNSubSet() throws Exception { 181 log.debug(">test06createSubjectDNSubSet()"); 182 CertificateProfile profile = new CertificateProfile(); 183 184 ArrayList dnsubset = new ArrayList (); 185 dnsubset.add(new Integer (DNFieldExtractor.CN)); 186 dnsubset.add(new Integer (DNFieldExtractor.UID)); 187 dnsubset.add(new Integer (DNFieldExtractor.GIVENNAME)); 188 dnsubset.add(new Integer (DNFieldExtractor.SURNAME)); 189 profile.setSubjectDNSubSet(dnsubset); 190 191 String indn1 = "UID=PVE,CN=Philip Vendil,SN=123435,GIVENNAME=Philip,SURNAME=Vendil"; 192 String outdn1 = profile.createSubjectDNSubSet(indn1); 193 String expecteddn1 = "UID=PVE,CN=Philip Vendil,GIVENNAME=Philip,SURNAME=Vendil"; 194 assertTrue("createSubjectDNSubSet doesn't work" + outdn1 + " != "+ expecteddn1, expecteddn1.equalsIgnoreCase(outdn1)); 195 196 String indn2 = "UID=PVE,CN=Philip Vendil,CN=SecondUsername,SN=123435,SN=54321,GIVENNAME=Philip,SURNAME=Vendil"; 197 String outdn2 = profile.createSubjectDNSubSet(indn2); 198 String expecteddn2 = "UID=PVE,CN=Philip Vendil,CN=SecondUsername,GIVENNAME=Philip,SURNAME=Vendil"; 199 assertTrue("createSubjectDNSubSet doesn't work" + outdn2 + " != "+ expecteddn2, expecteddn2.equalsIgnoreCase(outdn2)); 200 201 log.debug(">test06createSubjectDNSubSet()"); 202 } 203 204 public void test07createSubjectAltNameSubSet() throws Exception { 205 log.debug(">test07createSubjectAltNameSubSet()"); 206 207 CertificateProfile profile = new CertificateProfile(); 208 209 ArrayList altnamesubset = new ArrayList (); 210 altnamesubset.add(new Integer (DNFieldExtractor.RFC822NAME)); 211 altnamesubset.add(new Integer (DNFieldExtractor.UPN)); 212 profile.setSubjectAltNameSubSet(altnamesubset); 213 214 String inaltname1 = "RFC822NAME=test@test.se,UPN=testacc@test.se,IPADDRESS=10.1.1.0"; 215 String outaltname1 = profile.createSubjectAltNameSubSet(inaltname1); 216 String expectedaltname1 = "RFC822NAME=test@test.se,UPN=testacc@test.se"; 217 assertTrue("createSubjectAltNameSubSet doesn't work" + outaltname1 + " != "+ expectedaltname1, expectedaltname1.equalsIgnoreCase(outaltname1)); 218 219 String inaltname2 = "RFC822NAME=test@test.se,RFC822NAME=test2@test2.se,UPN=testacc@test.se,IPADDRESS=10.1.1.0,IPADDRESS=10.1.1.2"; 220 String outaltname2 = profile.createSubjectAltNameSubSet(inaltname2); 221 String expectedaltname2 = "RFC822NAME=test@test.se,RFC822NAME=test2@test2.se,UPN=testacc@test.se"; 222 assertTrue("createSubjectAltNameSubSet doesn't work" + outaltname2 + " != "+ expectedaltname2, expectedaltname2.equalsIgnoreCase(outaltname2)); 223 224 log.debug(">test07createSubjectAltNameSubSet()"); 225 } 226 227 public void test08CertificateProfileValues() throws Exception { 228 CertificateProfile ep = new EndUserCertificateProfile(); 229 assertEquals("2.5.29.32.0", ep.getCertificatePolicyId()); 230 assertEquals(CertificateProfile.LATEST_VERSION, ep.getLatestVersion(),0); 231 String qcId = ep.getQCSemanticsId(); 232 assertEquals("", qcId); 233 CertificateProfile cp = new CertificateProfile(); 234 assertEquals("2.5.29.32.0", cp.getCertificatePolicyId()); 235 assertEquals(CertificateProfile.LATEST_VERSION, cp.getLatestVersion(),0); 236 assertEquals("", cp.getQCSemanticsId()); 237 cp.setQCSemanticsId("1.1.1.2"); 238 assertEquals("1.1.1.2", cp.getQCSemanticsId()); 239 } 240 241 } 242 | Popular Tags |