diff options
Diffstat (limited to 'base/common/test/com/netscape/certsrv')
4 files changed, 1056 insertions, 0 deletions
diff --git a/base/common/test/com/netscape/certsrv/app/CMSEngineDefaultStub.java b/base/common/test/com/netscape/certsrv/app/CMSEngineDefaultStub.java new file mode 100644 index 000000000..cddd1205a --- /dev/null +++ b/base/common/test/com/netscape/certsrv/app/CMSEngineDefaultStub.java @@ -0,0 +1,632 @@ +package com.netscape.certsrv.app; + +import java.math.BigInteger; +import java.security.NoSuchAlgorithmException; +import java.security.cert.Certificate; +import java.security.cert.CertificateEncodingException; +import java.security.cert.X509CRL; +import java.security.cert.X509Certificate; +import java.util.Date; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Locale; +import java.util.Vector; + +import netscape.ldap.LDAPConnection; +import netscape.ldap.LDAPException; +import netscape.ldap.LDAPSSLSocketFactoryExt; +import netscape.security.util.ObjectIdentifier; +import netscape.security.x509.Extension; +import netscape.security.x509.GeneralName; +import netscape.security.x509.X509CertInfo; + +import org.mozilla.jss.CryptoManager.CertificateUsage; +import org.mozilla.jss.util.PasswordCallback; + +import com.netscape.certsrv.acls.EACLsException; +import com.netscape.certsrv.acls.IACL; +import com.netscape.certsrv.apps.ICMSEngine; +import com.netscape.certsrv.apps.ICommandQueue; +import com.netscape.certsrv.authority.IAuthority; +import com.netscape.certsrv.base.EBaseException; +import com.netscape.certsrv.base.IArgBlock; +import com.netscape.certsrv.base.ICRLPrettyPrint; +import com.netscape.certsrv.base.ICertPrettyPrint; +import com.netscape.certsrv.base.IConfigStore; +import com.netscape.certsrv.base.IExtPrettyPrint; +import com.netscape.certsrv.base.IPrettyPrintFormat; +import com.netscape.certsrv.base.ISecurityDomainSessionTable; +import com.netscape.certsrv.base.ISubsystem; +import com.netscape.certsrv.ca.ICRLIssuingPoint; +import com.netscape.certsrv.connector.IHttpConnection; +import com.netscape.certsrv.connector.IPKIMessage; +import com.netscape.certsrv.connector.IRemoteAuthority; +import com.netscape.certsrv.connector.IRequestEncoder; +import com.netscape.certsrv.connector.IResender; +import com.netscape.certsrv.dbs.crldb.ICRLIssuingPointRecord; +import com.netscape.certsrv.dbs.repository.IRepositoryRecord; +import com.netscape.certsrv.ldap.ELdapException; +import com.netscape.certsrv.ldap.ILdapAuthInfo; +import com.netscape.certsrv.ldap.ILdapConnFactory; +import com.netscape.certsrv.ldap.ILdapConnInfo; +import com.netscape.certsrv.logging.ILogger; +import com.netscape.certsrv.notification.IEmailFormProcessor; +import com.netscape.certsrv.notification.IEmailResolver; +import com.netscape.certsrv.notification.IEmailResolverKeys; +import com.netscape.certsrv.notification.IEmailTemplate; +import com.netscape.certsrv.notification.IMailNotification; +import com.netscape.certsrv.password.IPasswordCheck; +import com.netscape.certsrv.policy.IGeneralNameAsConstraintsConfig; +import com.netscape.certsrv.policy.IGeneralNamesAsConstraintsConfig; +import com.netscape.certsrv.policy.IGeneralNamesConfig; +import com.netscape.certsrv.policy.ISubjAltNameConfig; +import com.netscape.certsrv.request.IRequest; +import com.netscape.cmsutil.net.ISocketFactory; +import com.netscape.cmsutil.password.IPasswordStore; + +/** + * Default engine stub for testing. + */ +public class CMSEngineDefaultStub implements ICMSEngine { + public String getId() { + return null; + } + + public void setId(String id) throws EBaseException { + } + + public void init(ISubsystem owner, IConfigStore config) throws EBaseException { + } + + public void startup() throws EBaseException { + } + + public void shutdown() { + } + + public IConfigStore getConfigStore() { + return null; + } + + public int getPID() { + return 0; + } + + public void reinit(String id) throws EBaseException { + } + + public int getCSState() { + return 0; + } + + public void setCSState(int mode) { + } + + public boolean isPreOpMode() { + return false; + } + + public boolean isRunningMode() { + return false; + } + + public String getInstanceDir() { + return null; + } + + public Date getCurrentDate() { + return null; + } + + public long getStartupTime() { + return 0; + } + + public boolean isInRunningState() { + return false; + } + + public Enumeration<String> getSubsystemNames() { + return null; + } + + public Enumeration<ISubsystem> getSubsystems() { + return null; + } + + public ISubsystem getSubsystem(String name) { + return null; + } + + public ILogger getLogger() { + return null; + } + + public ILogger getSignedAuditLogger() { + return null; + } + + public void debug(byte data[]) { + } + + public void debug(String msg) { + } + + public void debug(int level, String msg) { + } + + public void debug(Throwable e) { + } + + public boolean debugOn() { + return false; + } + + public void debugStackTrace() { + } + + public void traceHashKey(String type, String key) { + } + + public void traceHashKey(String type, String key, String val) { + } + + public void traceHashKey(String type, String key, String val, String def) { + } + + public byte[] getPKCS7(Locale locale, IRequest req) { + return new byte[0]; + } + + public String getUserMessage(Locale locale, String msgID) { + return null; + } + + public String getUserMessage(Locale locale, String msgID, String p[]) { + return null; + } + + public String getUserMessage(Locale locale, String msgID, String p1) { + return null; + } + + public String getUserMessage(Locale locale, String msgID, String p1, String p2) { + return null; + } + + public String getUserMessage(Locale locale, String msgID, String p1, String p2, String p3) { + return null; + } + + public String getLogMessage(String msgID) { + return null; + } + + public String getLogMessage(String msgID, String p[]) { + return null; + } + + public String getLogMessage(String msgID, String p1) { + return null; + } + + public String getLogMessage(String msgID, String p1, String p2) { + return null; + } + + public String getLogMessage(String msgID, String p1, String p2, String p3) { + return null; + } + + public String getLogMessage(String msgID, String p1, String p2, String p3, String p4) { + return null; + } + + public String getLogMessage(String msgID, String p1, String p2, String p3, String p4, String p5) { + return null; + } + + public String getLogMessage(String msgID, String p1, String p2, String p3, String p4, String p5, String p6) { + return null; + } + + public String getLogMessage(String msgID, String p1, String p2, String p3, String p4, String p5, String p6, + String p7) { + return null; + } + + public String getLogMessage(String msgID, String p1, String p2, String p3, String p4, String p5, String p6, + String p7, String p8) { + return null; + } + + public String getLogMessage(String msgID, String p1, String p2, String p3, String p4, String p5, String p6, + String p7, String p8, String p9) { + return null; + } + + public IACL parseACL(String resACLs) throws EACLsException { + return null; + } + + public ICRLIssuingPointRecord createCRLIssuingPointRecord(String id, BigInteger crlNumber, Long crlSize, + Date thisUpdate, Date nextUpdate) { + return null; + } + + public String getCRLIssuingPointRecordName() { + return null; + } + + public String getFingerPrint(Certificate cert) throws CertificateEncodingException, NoSuchAlgorithmException { + return null; + } + + public String getFingerPrints(Certificate cert) throws NoSuchAlgorithmException, CertificateEncodingException { + return null; + }/* + * Returns the finger print of the given certificate. + * + * @param certDer DER byte array of certificate + * @return finger print of certificate + */ + + public String getFingerPrints(byte[] certDer) throws NoSuchAlgorithmException { + return null; + } + + public IRepositoryRecord createRepositoryRecord() { + return null; + } + + public IPKIMessage getHttpPKIMessage() { + return null; + } + + public IRequestEncoder getHttpRequestEncoder() { + return null; + } + + public String BtoA(byte data[]) { + return null; + } + + public byte[] AtoB(String data) { + return new byte[0]; + } + + public String getEncodedCert(X509Certificate cert) { + return null; + } + + public IPrettyPrintFormat getPrettyPrintFormat(String delimiter) { + return null; + } + + public IExtPrettyPrint getExtPrettyPrint(Extension e, int indent) { + return null; + } + + public ICertPrettyPrint getCertPrettyPrint(X509Certificate cert) { + return null; + } + + public ICRLPrettyPrint getCRLPrettyPrint(X509CRL crl) { + return null; + } + + public ICRLPrettyPrint getCRLCachePrettyPrint(ICRLIssuingPoint ip) { + return null; + } + + public ILdapConnInfo getLdapConnInfo(IConfigStore config) throws EBaseException, ELdapException { + return null; + } + + public LDAPSSLSocketFactoryExt getLdapJssSSLSocketFactory(String certNickname) { + return null; + } + + public LDAPSSLSocketFactoryExt getLdapJssSSLSocketFactory() { + return null; + } + + public ILdapAuthInfo getLdapAuthInfo() { + return null; + } + + public ILdapConnFactory getLdapBoundConnFactory() throws ELdapException { + return null; + } + + public LDAPConnection getBoundConnection(String host, int port, int version, LDAPSSLSocketFactoryExt fac, + String bindDN, String bindPW) throws LDAPException { + return null; + } + + public ILdapConnFactory getLdapAnonConnFactory() throws ELdapException { + return null; + } + + public IPasswordCheck getPasswordChecker() { + return null; + } + + public void putPasswordCache(String tag, String pw) { + } + + public PasswordCallback getPasswordCallback() { + return null; + } + + public String getServerCertNickname() { + return null; + } + + public void setServerCertNickname(String tokenName, String nickName) { + } + + public void setServerCertNickname(String newName) { + } + + public String getEEHost() { + return null; + } + + public String getEENonSSLHost() { + return null; + } + + public String getEENonSSLIP() { + return null; + } + + public String getEENonSSLPort() { + return null; + } + + public String getEESSLHost() { + return null; + } + + public String getEESSLIP() { + return null; + } + + public String getEESSLPort() { + return null; + } + + public String getAgentHost() { + return null; + } + + public String getAgentIP() { + return null; + } + + public String getAgentPort() { + return null; + } + + public String getAdminHost() { + return null; + } + + public String getAdminIP() { + return null; + } + + public String getAdminPort() { + return null; + } + + public boolean isSigningCert(X509Certificate cert) { + return false; + } + + public boolean isEncryptionCert(X509Certificate cert) { + return false; + } + + public X509CertInfo getDefaultX509CertInfo() { + return null; + } + + public IEmailFormProcessor getEmailFormProcessor() { + return null; + } + + public IEmailTemplate getEmailTemplate(String path) { + return null; + } + + public IMailNotification getMailNotification() { + return null; + } + + public IEmailResolverKeys getEmailResolverKeys() { + return null; + } + + public IEmailResolver getReqCertSANameEmailResolver() { + return null; + } + + public ObjectIdentifier checkOID(String attrName, String value) throws EBaseException { + return null; + } + + public GeneralName form_GeneralNameAsConstraints(String generalNameChoice, String value) throws EBaseException { + return null; + } + + public GeneralName form_GeneralName(String generalNameChoice, String value) throws EBaseException { + return null; + } + + public IGeneralNamesConfig createGeneralNamesConfig(String name, IConfigStore config, boolean isValueConfigured, + boolean isPolicyEnabled) throws EBaseException { + return null; + } + + public IGeneralNameAsConstraintsConfig createGeneralNameAsConstraintsConfig(String name, IConfigStore config, + boolean isValueConfigured, boolean isPolicyEnabled) throws EBaseException { + return null; + } + + public IGeneralNamesAsConstraintsConfig createGeneralNamesAsConstraintsConfig(String name, IConfigStore config, + boolean isValueConfigured, boolean isPolicyEnabled) throws EBaseException { + return null; + } + + public ISubjAltNameConfig createSubjAltNameConfig(String name, IConfigStore config, boolean isValueConfigured) + throws EBaseException { + return null; + } + + public IHttpConnection getHttpConnection(IRemoteAuthority authority, ISocketFactory factory) { + return null; + } + + public IHttpConnection getHttpConnection(IRemoteAuthority authority, ISocketFactory factory, int timeout) { + return null; + } + + public IResender getResender(IAuthority authority, String nickname, IRemoteAuthority remote, int interval) { + return null; + } + + public ICommandQueue getCommandQueue() { + return null; + } + + public void disableRequests() { + } + + public void terminateRequests() { + } + + public boolean areRequestsDisabled() { + return false; + } + + public IConfigStore createFileConfigStore(String path) throws EBaseException { + return null; + } + + public IArgBlock createArgBlock() { + return null; + } + + public boolean isRevoked(X509Certificate[] certificates) { + return false; + } + + public void setListOfVerifiedCerts(int size, long interval, long unknownStateInterval) { + } + + public void forceShutdown() { + } + + public IPasswordStore getPasswordStore() { + return null; + } + + public ISecurityDomainSessionTable getSecurityDomainSessionTable() { + return null; + } + + public void setConfigSDSessionId(String id) { + } + + public String getConfigSDSessionId() { + return null; + } + + @Override + public String getEEClientAuthSSLPort() { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean verifySystemCerts() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean verifySystemCertByTag(String tag) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean verifySystemCertByNickname(String nickname, + String certificateUsage) { + // TODO Auto-generated method stub + return false; + } + + @Override + public CertificateUsage getCertificateUsage(String certusage) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void getGeneralNameConfigDefaultParams(String name, + boolean isValueConfigured, Vector<String> params) { + // TODO Auto-generated method stub + + } + + @Override + public void getGeneralNamesConfigDefaultParams(String name, + boolean isValueConfigured, Vector<String> params) { + // TODO Auto-generated method stub + + } + + @Override + public void getGeneralNameConfigExtendedPluginInfo(String name, + boolean isValueConfigured, Vector<String> info) { + // TODO Auto-generated method stub + + } + + @Override + public void getGeneralNamesConfigExtendedPluginInfo(String name, + boolean isValueConfigured, Vector<String> info) { + // TODO Auto-generated method stub + + } + + @Override + public void getSubjAltNameConfigDefaultParams(String name, + Vector<String> params) { + // TODO Auto-generated method stub + + } + + @Override + public void getSubjAltNameConfigExtendedPluginInfo(String name, + Vector<String> params) { + // TODO Auto-generated method stub + + } + + @Override + public IArgBlock createArgBlock(String realm, + Hashtable<String, String> httpReq) { + // TODO Auto-generated method stub + return null; + } + + @Override + public IArgBlock createArgBlock(Hashtable<String, String> httpReq) { + // TODO Auto-generated method stub + return null; + } +} diff --git a/base/common/test/com/netscape/certsrv/authentication/AuthTokenTest.java b/base/common/test/com/netscape/certsrv/authentication/AuthTokenTest.java new file mode 100644 index 000000000..c60e93d99 --- /dev/null +++ b/base/common/test/com/netscape/certsrv/authentication/AuthTokenTest.java @@ -0,0 +1,271 @@ +package com.netscape.certsrv.authentication; + +import java.io.IOException; +import java.math.BigInteger; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.util.Date; + +import junit.framework.Test; +import junit.framework.TestSuite; +import netscape.security.util.DerOutputStream; +import netscape.security.x509.BasicConstraintsExtension; +import netscape.security.x509.CertificateExtensions; +import netscape.security.x509.PKIXExtensions; +import netscape.security.x509.X509CertImpl; + +import com.netscape.certsrv.app.CMSEngineDefaultStub; +import com.netscape.certsrv.apps.CMS; +import com.netscape.certsrv.usrgrp.Certificates; +import com.netscape.cmscore.test.CMSBaseTestCase; + +public class AuthTokenTest extends CMSBaseTestCase { + + AuthToken authToken; + CMSMemoryStub cmsStub; + + public AuthTokenTest(String name) { + super(name); + } + + public void cmsTestSetUp() { + authToken = new AuthToken(null); + + // this is needed because of CMS.AtoB/BtoA calls + cmsStub = new CMSMemoryStub(); + CMS.setCMSEngine(cmsStub); + } + + public void cmsTestTearDown() { + } + + public static Test suite() { + return new TestSuite(AuthTokenTest.class); + } + + public void testGetSetString() { + authToken.set("key", "value"); + assertEquals("value", authToken.mAttrs.get("key")); + assertEquals("value", authToken.getInString("key")); + + assertFalse(authToken.set("key", (String) null)); + } + + public void testGetSetByteArray() { + byte[] data = new byte[] { -12, 0, 14, 15 }; + + assertFalse(cmsStub.bToACalled); + authToken.set("key", data); + assertTrue(cmsStub.bToACalled); + + assertFalse(cmsStub.aToBCalled); + byte[] retval = authToken.getInByteArray("key"); + assertEquals(data, retval); + + assertFalse(authToken.set("key2", (byte[]) null)); + } + + public void testGetSetInteger() { + authToken.set("key", Integer.valueOf(432)); + assertEquals("432", authToken.mAttrs.get("key")); + assertEquals(Integer.valueOf(432), authToken.getInInteger("key")); + + assertNull(authToken.getInInteger("notfound")); + + authToken.set("key2", "value"); + assertNull(authToken.getInInteger("key2")); + + assertFalse(authToken.set("key3", (Integer) null)); + } + + public void testGetSetBigIntegerArray() { + BigInteger[] data = new BigInteger[] { + new BigInteger("111111111"), + new BigInteger("222222222"), + new BigInteger("333333333") + }; + authToken.set("key", data); + assertEquals("111111111,222222222,333333333", + authToken.mAttrs.get("key")); + BigInteger[] retval = authToken.getInBigIntegerArray("key"); + assertEquals(3, retval.length); + assertEquals(data[0], retval[0]); + assertEquals(data[1], retval[1]); + assertEquals(data[2], retval[2]); + + authToken.set("key2", "123456"); + retval = authToken.getInBigIntegerArray("key2"); + assertEquals(1, retval.length); + assertEquals(new BigInteger("123456"), retval[0]); + + authToken.set("key3", "oops"); + assertNull(authToken.getInBigIntegerArray("key3")); + + // corner case test + authToken.set("key", ","); + retval = authToken.getInBigIntegerArray("key"); + assertNull(retval); + + assertFalse(authToken.set("key4", (BigInteger[]) null)); + } + + public void testGetSetDate() { + Date value = new Date(); + authToken.set("key", value); + assertEquals(String.valueOf(value.getTime()), + authToken.mAttrs.get("key")); + assertEquals(value, authToken.getInDate("key")); + + authToken.set("key2", "234567"); + Date retval = authToken.getInDate("key2"); + assertEquals(234567L, retval.getTime()); + + authToken.set("key3", "oops"); + assertNull(authToken.getInDate("key3")); + + assertFalse(authToken.set("key4", (Date) null)); + } + + public void testGetSetStringArray() throws IOException { + String[] value = new String[] { + "eenie", "meenie", "miny", "moe" + }; + + assertFalse(cmsStub.bToACalled); + authToken.set("key", value); + assertTrue(cmsStub.bToACalled); + + assertFalse(cmsStub.aToBCalled); + String[] retval = authToken.getInStringArray("key"); + assertTrue(cmsStub.aToBCalled); + assertEquals(4, retval.length); + assertEquals(value[0], retval[0]); + assertEquals(value[1], retval[1]); + assertEquals(value[2], retval[2]); + assertEquals(value[3], retval[3]); + + // illegal value parsing + authToken.set("key2", new byte[] { 1, 2, 3, 4 }); + assertNull(authToken.getInStringArray("key2")); + + DerOutputStream out = new DerOutputStream(); + out.putPrintableString("testing"); + authToken.set("key3", out.toByteArray()); + assertNull(authToken.getInStringArray("key3")); + + assertFalse(authToken.set("key4", (String[]) null)); + } + + public void testGetSetCert() throws CertificateException { + X509CertImpl cert = getFakeCert(); + + assertFalse(cmsStub.bToACalled); + authToken.set("key", cert); + assertTrue(cmsStub.bToACalled); + + assertFalse(cmsStub.aToBCalled); + X509CertImpl retval = authToken.getInCert("key"); + assertTrue(cmsStub.aToBCalled); + assertNotNull(retval); + assertEquals(cert, retval); + + assertFalse(authToken.set("key2", (X509CertImpl) null)); + } + + public void testGetSetCertExts() throws IOException { + CertificateExtensions certExts = new CertificateExtensions(); + BasicConstraintsExtension ext = new BasicConstraintsExtension(false, 1); + + assertTrue(authToken.set("key", certExts)); + assertTrue(authToken.mAttrs.containsKey("key")); + CertificateExtensions retval = authToken.getInCertExts("key"); + assertNotNull(retval); + assertEquals(0, retval.size()); + + certExts.set(PKIXExtensions.BasicConstraints_Id.toString(), ext); + assertTrue(authToken.set("key2", certExts)); + + retval = authToken.getInCertExts("key2"); + assertTrue(authToken.mAttrs.containsKey("key2")); + assertNotNull(retval); + assertEquals(1, retval.size()); + + assertFalse(authToken.set("key3", (CertificateExtensions) null)); + } + + public void testGetSetCertificates() throws CertificateException { + X509CertImpl cert1 = getFakeCert(); + X509CertImpl cert2 = getFakeCert(); + X509CertImpl[] certArray = new X509CertImpl[] { cert1, cert2 }; + Certificates certs = new Certificates(certArray); + + assertFalse(cmsStub.bToACalled); + authToken.set("key", certs); + assertTrue(cmsStub.bToACalled); + + assertFalse(cmsStub.aToBCalled); + Certificates retval = authToken.getInCertificates("key"); + assertTrue(cmsStub.aToBCalled); + assertNotNull(retval); + + X509Certificate[] retCerts = retval.getCertificates(); + assertEquals(2, retCerts.length); + assertEquals(cert1, retCerts[0]); + assertEquals(cert2, retCerts[1]); + + assertFalse(authToken.set("key2", (Certificates) null)); + } + + public void testGetSetByteArrayArray() { + byte[][] value = new byte[][] { + new byte[] { 1, 2, 3, 4 }, + new byte[] { 12, 13, 14 }, + new byte[] { 50, -12, 0, 100 } + }; + + assertFalse(cmsStub.bToACalled); + assertTrue(authToken.set("key", value)); + assertTrue(cmsStub.bToACalled); + + assertFalse(cmsStub.aToBCalled); + byte[][] retval = authToken.getInByteArrayArray("key"); + assertTrue(cmsStub.aToBCalled); + assertNotNull(retval); + assertEquals(value.length, retval.length); + for (int i = 0; i < value.length; i++) { + assertEquals(value[i].length, retval[i].length); + for (int j = 0; j < value[i].length; j++) { + assertEquals(value[i][j], retval[i][j]); + } + } + + assertFalse(authToken.set("key2", (byte[][]) null)); + } + + /** + * CMSMemoryStub + * + * This class is used to help test methods that rely on setting and then + * getting a value out. It assumes BtoA is always called first, stores + * the value passed in, and then returns that value for BtoA. + */ + class CMSMemoryStub extends CMSEngineDefaultStub { + boolean bToACalled = false; + byte[] bToACalledWith = null; + + boolean aToBCalled = false; + String aToBCalledWith = null; + + public String BtoA(byte data[]) { + bToACalled = true; + bToACalledWith = data; + return "garbagetostoreinthehash"; + } + + public byte[] AtoB(String data) { + aToBCalled = true; + aToBCalledWith = data; + return bToACalledWith; + } + } +} diff --git a/base/common/test/com/netscape/certsrv/logging/LoggerDefaultStub.java b/base/common/test/com/netscape/certsrv/logging/LoggerDefaultStub.java new file mode 100644 index 000000000..c136c7feb --- /dev/null +++ b/base/common/test/com/netscape/certsrv/logging/LoggerDefaultStub.java @@ -0,0 +1,71 @@ +package com.netscape.certsrv.logging; + +import java.util.Properties; + +/** + * Default logging stub for testing. + */ +public class LoggerDefaultStub implements ILogger { + public void log(int evtClass, int source, String msg) { + } + + public void log(int evtClass, Properties props, int source, String msg) { + } + + public void log(int evtClass, int source, int level, String msg) { + } + + public void log(int evtClass, Properties props, int source, int level, String msg) { + } + + public void log(int evtClass, int source, int level, String msg, Object param) { + } + + public void log(int evtClass, int source, int level, String msg, Object params[]) { + } + + public void log(int evtClass, Properties props, int source, String msg, Object param) { + } + + public void log(int evtClass, Properties props, int source, int level, String msg, Object param) { + } + + public void log(int evtClass, Properties prop, int source, int level, String msg, Object params[]) { + } + + public void log(int evtClass, int source, String msg, boolean multiline) { + } + + public void log(int evtClass, Properties props, int source, String msg, boolean multiline) { + } + + public void log(int evtClass, int source, int level, String msg, boolean multiline) { + } + + public void log(int evtClass, Properties props, int source, int level, String msg, boolean multiline) { + } + + public void log(int evtClass, int source, int level, String msg, Object param, boolean multiline) { + } + + public void log(int evtClass, Properties props, int source, String msg, Object param, boolean multiline) { + } + + public void log(int evtClass, Properties props, int source, int level, String msg, Object param, boolean multiline) { + } + + public void log(int evtClass, Properties prop, int source, int level, String msg, Object params[], boolean multiline) { + } + + public ILogEvent create(int evtClass, Properties prop, int source, int level, String msg, Object params[], + boolean multiline) { + return null; + } + + public void register(int evtClass, ILogEventFactory f) { + } + + public ILogQueue getLogQueue() { + return null; + } +} diff --git a/base/common/test/com/netscape/certsrv/request/AgentApprovalsTest.java b/base/common/test/com/netscape/certsrv/request/AgentApprovalsTest.java new file mode 100644 index 000000000..e7606951d --- /dev/null +++ b/base/common/test/com/netscape/certsrv/request/AgentApprovalsTest.java @@ -0,0 +1,82 @@ +package com.netscape.certsrv.request; + +import java.util.Vector; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import com.netscape.cmscore.test.CMSBaseTestCase; + +public class AgentApprovalsTest extends CMSBaseTestCase { + + AgentApprovals agentApprovals; + + public AgentApprovalsTest(String name) { + super(name); + } + + public void cmsTestSetUp() { + agentApprovals = new AgentApprovals(); + } + + public void cmsTestTearDown() { + } + + public static Test suite() { + return new TestSuite(AgentApprovalsTest.class); + } + + public void testToFromStringVector() { + AgentApproval approval1 = new AgentApproval("user1"); + AgentApproval approval2 = new AgentApproval("user2"); + AgentApproval approval3 = new AgentApproval(";user4;messy name"); + agentApprovals.mVector.add(approval1); + agentApprovals.mVector.add(approval2); + agentApprovals.mVector.add(approval3); + + Vector<String> stringVector = agentApprovals.toStringVector(); + assertNotNull(stringVector); + assertEquals(3, stringVector.size()); + assertEquals(approval1.getDate().getTime() + ";" + approval1.getUserName(), + stringVector.get(0)); + assertEquals(approval2.getDate().getTime() + ";" + approval2.getUserName(), + stringVector.get(1)); + assertEquals(approval3.getDate().getTime() + ";" + approval3.getUserName(), + stringVector.get(2)); + + AgentApprovals approvals = AgentApprovals.fromStringVector(stringVector); + assertNotNull(approvals); + assertEquals(3, approvals.mVector.size()); + + AgentApproval approval = (AgentApproval) approvals.mVector.get(0); + assertEquals(approval1.getUserName(), approval.getUserName()); + assertEquals(approval1.getDate(), approval.getDate()); + + approval = (AgentApproval) approvals.mVector.get(1); + assertEquals(approval2.getUserName(), approval.getUserName()); + assertEquals(approval2.getDate(), approval.getDate()); + + approval = (AgentApproval) approvals.mVector.get(2); + assertEquals(approval3.getUserName(), approval.getUserName()); + assertEquals(approval3.getDate(), approval.getDate()); + + // test bad data + stringVector = new Vector<String>(); + stringVector.add("foo"); + assertNull(AgentApprovals.fromStringVector(stringVector)); + + stringVector = new Vector<String>(); + stringVector.add(";foo"); + assertNull(AgentApprovals.fromStringVector(stringVector)); + + stringVector = new Vector<String>(); + stringVector.add("bar;foo"); + assertNull(AgentApprovals.fromStringVector(stringVector)); + + stringVector = new Vector<String>(); + stringVector.add("00123b;foo"); + assertNull(AgentApprovals.fromStringVector(stringVector)); + + assertNull(AgentApprovals.fromStringVector(null)); + } +} |