summaryrefslogtreecommitdiffstats
path: root/base/common/test
diff options
context:
space:
mode:
authorEndi Sukma Dewata <edewata@redhat.com>2012-03-24 02:27:47 -0500
committerEndi Sukma Dewata <edewata@redhat.com>2012-03-26 11:43:54 -0500
commit621d9e5c413e561293d7484b93882d985b3fe15f (patch)
tree638f3d75761c121d9a8fb50b52a12a6686c5ac5c /base/common/test
parent40d3643b8d91886bf210aa27f711731c81a11e49 (diff)
downloadpki-621d9e5c413e561293d7484b93882d985b3fe15f.tar.gz
pki-621d9e5c413e561293d7484b93882d985b3fe15f.tar.xz
pki-621d9e5c413e561293d7484b93882d985b3fe15f.zip
Removed unnecessary pki folder.
Previously the source code was located inside a pki folder. This folder was created during svn migration and is no longer needed. This folder has now been removed and the contents have been moved up one level. Ticket #131
Diffstat (limited to 'base/common/test')
-rw-r--r--base/common/test/CMakeLists.txt103
-rw-r--r--base/common/test/com/netscape/certsrv/app/CMSEngineDefaultStub.java632
-rw-r--r--base/common/test/com/netscape/certsrv/authentication/AuthTokenTest.java271
-rw-r--r--base/common/test/com/netscape/certsrv/logging/LoggerDefaultStub.java71
-rw-r--r--base/common/test/com/netscape/certsrv/request/AgentApprovalsTest.java82
-rw-r--r--base/common/test/com/netscape/cmscore/dbs/CertRecordListTest.java87
-rw-r--r--base/common/test/com/netscape/cmscore/dbs/DBRegistryDefaultStub.java79
-rw-r--r--base/common/test/com/netscape/cmscore/dbs/DBRegistryTest.java175
-rw-r--r--base/common/test/com/netscape/cmscore/dbs/DBSSessionDefaultStub.java79
-rw-r--r--base/common/test/com/netscape/cmscore/dbs/DBSubsystemDefaultStub.java172
-rw-r--r--base/common/test/com/netscape/cmscore/dbs/DBVirtualListDefaultStub.java87
-rw-r--r--base/common/test/com/netscape/cmscore/dbs/RequestRecordDefaultStub.java44
-rw-r--r--base/common/test/com/netscape/cmscore/request/DBDynAttrMapperDefaultStub.java33
-rw-r--r--base/common/test/com/netscape/cmscore/request/ExtAttrDynMapperTest.java278
-rw-r--r--base/common/test/com/netscape/cmscore/request/ExtDataHashtableTest.java81
-rw-r--r--base/common/test/com/netscape/cmscore/request/RequestDefaultStub.java269
-rw-r--r--base/common/test/com/netscape/cmscore/request/RequestModDefaultStub.java21
-rw-r--r--base/common/test/com/netscape/cmscore/request/RequestQueueTest.java60
-rw-r--r--base/common/test/com/netscape/cmscore/request/RequestRecordTest.java168
-rw-r--r--base/common/test/com/netscape/cmscore/request/RequestTest.java649
-rw-r--r--base/common/test/com/netscape/cmscore/test/CMSBaseTestCase.java99
-rw-r--r--base/common/test/com/netscape/cmscore/test/TestHelper.java30
22 files changed, 3570 insertions, 0 deletions
diff --git a/base/common/test/CMakeLists.txt b/base/common/test/CMakeLists.txt
new file mode 100644
index 000000000..2f7b4fa4e
--- /dev/null
+++ b/base/common/test/CMakeLists.txt
@@ -0,0 +1,103 @@
+project(pki-common-test Java)
+
+find_file(PKI_CERTSRV_JAR
+ NAMES
+ pki-certsrv.jar
+ PATHS
+ ${JAVA_JAR_INSTALL_DIR}/pki
+)
+
+find_file(PKI_CMS_JAR
+ NAMES
+ pki-cms
+ PATHS
+ ${JAVA_JAR_INSTALL_DIR}/pki
+)
+
+find_file(PKI_CMSCORE_JAR
+ NAMES
+ pki-cmscore
+ PATHS
+ ${JAVA_JAR_INSTALL_DIR}/pki
+)
+
+find_file(PKI_CMSBUNDLE_JAR
+ NAMES
+ pki-cmsbundle
+ PATHS
+ ${JAVA_JAR_INSTALL_DIR}/pki
+)
+
+# TODO: create CMake function to find all Java files
+set(pki-common-test_SRCS
+ com/netscape/certsrv/app/CMSEngineDefaultStub.java
+ com/netscape/certsrv/authentication/AuthTokenTest.java
+ com/netscape/certsrv/logging/LoggerDefaultStub.java
+ com/netscape/certsrv/request/AgentApprovalsTest.java
+ com/netscape/cmscore/dbs/CertRecordListTest.java
+ com/netscape/cmscore/dbs/DBRegistryDefaultStub.java
+ com/netscape/cmscore/dbs/DBRegistryTest.java
+ com/netscape/cmscore/dbs/DBSSessionDefaultStub.java
+ com/netscape/cmscore/dbs/DBSubsystemDefaultStub.java
+ com/netscape/cmscore/dbs/DBVirtualListDefaultStub.java
+ com/netscape/cmscore/dbs/RequestRecordDefaultStub.java
+ com/netscape/cmscore/request/DBDynAttrMapperDefaultStub.java
+ com/netscape/cmscore/request/ExtAttrDynMapperTest.java
+ com/netscape/cmscore/request/ExtDataHashtableTest.java
+ com/netscape/cmscore/request/RequestDefaultStub.java
+ com/netscape/cmscore/request/RequestModDefaultStub.java
+ com/netscape/cmscore/request/RequestQueueTest.java
+ com/netscape/cmscore/request/RequestRecordTest.java
+ com/netscape/cmscore/request/RequestTest.java
+ com/netscape/cmscore/test/CMSBaseTestCase.java
+ com/netscape/cmscore/test/TestHelper.java
+)
+
+set(CMAKE_JAVA_INCLUDE_PATH
+ ${PKI_NSUTIL_JAR} ${PKI_CMSUTIL_JAR}
+ ${PKI_CERTSRV_JAR} ${PKI_CMS_JAR} ${PKI_CMSCORE_JAR} ${PKI_CMSBUNDLE_JAR}
+ ${LDAPJDK_JAR} ${SERVLET_JAR} ${VELOCITY_JAR} ${XALAN_JAR} ${XERCES_JAR}
+ ${JSS_JAR} ${COMMONS_CODEC_JAR} ${SYMKEY_JAR}
+ ${PKI_TEST_JAR} ${JUNIT_JAR}
+)
+
+set(CMAKE_JAVA_TARGET_VERSION ${APPLICATION_VERSION})
+
+# build test jar file
+# TODO: create CMake function to compile without building jar file
+# TODO: build test only when the test is invoked
+set(CMAKE_JAR_CLASSES_PREFIX com/netscape)
+add_jar(pki-common-test ${pki-common-test_SRCS})
+add_dependencies(pki-common-test
+ pki-nsutil pki-cmsutil
+ pki-certsrv pki-cms pki-cmscore pki-cmsbundle
+ pki-test
+)
+
+# create test target
+# do not include xalan and xerces in class path
+# TODO: create CMake function to find all JUnit test classes
+add_junit_test(test-pki-common
+ CLASSPATH
+ ${pki-common-test_JAR_FILE}
+ ${PKI_NSUTIL_JAR} ${PKI_CMSUTIL_JAR}
+ ${PKI_CERTSRV_JAR} ${PKI_CMS_JAR} ${PKI_CMSCORE_JAR} ${PKI_CMSBUNDLE_JAR}
+ ${LDAPJDK_JAR} ${SERVLET_JAR} ${VELOCITY_JAR}
+ ${JSS_JAR} ${COMMONS_CODEC_JAR} ${SYMKEY_JAR}
+ ${PKI_TEST_JAR} ${JUNIT_JAR}
+ TESTS
+ com.netscape.certsrv.authentication.AuthTokenTest
+ com.netscape.certsrv.request.AgentApprovalsTest
+ com.netscape.cmscore.dbs.CertRecordListTest
+ com.netscape.cmscore.dbs.DBRegistryTest
+ com.netscape.cmscore.request.ExtAttrDynMapperTest
+ com.netscape.cmscore.request.ExtDataHashtableTest
+ com.netscape.cmscore.request.RequestQueueTest
+ com.netscape.cmscore.request.RequestRecordTest
+ com.netscape.cmscore.request.RequestTest
+ REPORTS_DIR
+ reports
+)
+
+# include test into the main test
+add_dependencies(test test-pki-common)
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));
+ }
+}
diff --git a/base/common/test/com/netscape/cmscore/dbs/CertRecordListTest.java b/base/common/test/com/netscape/cmscore/dbs/CertRecordListTest.java
new file mode 100644
index 000000000..d3177f62c
--- /dev/null
+++ b/base/common/test/com/netscape/cmscore/dbs/CertRecordListTest.java
@@ -0,0 +1,87 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2007 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+package com.netscape.cmscore.dbs;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import com.netscape.certsrv.base.EBaseException;
+import com.netscape.certsrv.dbs.IElementProcessor;
+import com.netscape.certsrv.dbs.certdb.ICertRecord;
+import com.netscape.cmscore.test.CMSBaseTestCase;
+
+public class CertRecordListTest extends CMSBaseTestCase {
+
+ public CertRecordListTest(String name) {
+ super(name);
+ }
+
+ public void cmsTestSetUp() {
+ }
+
+ public void cmsTestTearDown() {
+ }
+
+ public static Test suite() {
+ return new TestSuite(CertRecordListTest.class);
+ }
+
+ public void testProcessCertRecordsUsesSize() throws EBaseException {
+ DBVirtualListStub<ICertRecord> dbList = new DBVirtualListStub<ICertRecord>();
+ dbList.size = 5;
+
+ CertRecordList certList = new CertRecordList(dbList);
+
+ assertEquals(5, dbList.size);
+ assertEquals(0, dbList.getElementAtCallCount);
+ assertEquals(0, dbList.lastIndexGetElementAtCalledWith);
+
+ certList.processCertRecords(0, 4, new ElementProcessorStub());
+
+ assertEquals(8, dbList.size);
+ assertEquals(8, dbList.getElementAtCallCount);
+ assertEquals(7, dbList.lastIndexGetElementAtCalledWith);
+ }
+
+ public class DBVirtualListStub<T> extends DBVirtualListDefaultStub<T> {
+ public int size = 0;
+ public int getElementAtCallCount = 0;
+ public int lastIndexGetElementAtCalledWith = 0;
+
+ public T getElementAt(int index) {
+ getElementAtCallCount++;
+ lastIndexGetElementAtCalledWith = index;
+
+ // This simulates the size changing in the middle of
+ // processing
+ if (index == 3) {
+ size = 8;
+ }
+ return null;
+ }
+
+ public int getSize() {
+ return size;
+ }
+ }
+
+ public class ElementProcessorStub implements IElementProcessor {
+ public void process(Object o) throws EBaseException {
+ }
+ }
+}
diff --git a/base/common/test/com/netscape/cmscore/dbs/DBRegistryDefaultStub.java b/base/common/test/com/netscape/cmscore/dbs/DBRegistryDefaultStub.java
new file mode 100644
index 000000000..9635129f4
--- /dev/null
+++ b/base/common/test/com/netscape/cmscore/dbs/DBRegistryDefaultStub.java
@@ -0,0 +1,79 @@
+package com.netscape.cmscore.dbs;
+
+import netscape.ldap.LDAPAttributeSet;
+
+import com.netscape.certsrv.base.EBaseException;
+import com.netscape.certsrv.base.IConfigStore;
+import com.netscape.certsrv.base.ISubsystem;
+import com.netscape.certsrv.dbs.EDBException;
+import com.netscape.certsrv.dbs.IDBAttrMapper;
+import com.netscape.certsrv.dbs.IDBDynAttrMapper;
+import com.netscape.certsrv.dbs.IDBObj;
+import com.netscape.certsrv.dbs.IDBRegistry;
+import com.netscape.certsrv.dbs.IFilterConverter;
+
+/**
+ * A default stub ojbect for tests to extend.
+ */
+public class DBRegistryDefaultStub implements IDBRegistry {
+
+ public void registerObjectClass(String className, String ldapNames[]) throws EDBException {
+ }
+
+ public boolean isObjectClassRegistered(String className) {
+ return false;
+ }
+
+ public void registerAttribute(String ufName, IDBAttrMapper mapper) throws EDBException {
+ }
+
+ public boolean isAttributeRegistered(String ufName) {
+ return false;
+ }
+
+ public void registerDynamicMapper(IDBDynAttrMapper mapper) {
+ }
+
+ public String getFilter(String filter) throws EBaseException {
+ return null;
+ }
+
+ public String getFilter(String filter, IFilterConverter c) throws EBaseException {
+ return null;
+ }
+
+ public void mapObject(IDBObj parent, String name, Object obj, LDAPAttributeSet attrs) throws EBaseException {
+ }
+
+ public String[] getLDAPAttributes(String attrs[]) throws EBaseException {
+ return new String[0];
+ }
+
+ public LDAPAttributeSet createLDAPAttributeSet(IDBObj obj) throws EBaseException {
+ return null;
+ }
+
+ public IDBObj createObject(LDAPAttributeSet attrs) throws EBaseException {
+ return null;
+ }
+
+ 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;
+ }
+}
diff --git a/base/common/test/com/netscape/cmscore/dbs/DBRegistryTest.java b/base/common/test/com/netscape/cmscore/dbs/DBRegistryTest.java
new file mode 100644
index 000000000..c74f66ba1
--- /dev/null
+++ b/base/common/test/com/netscape/cmscore/dbs/DBRegistryTest.java
@@ -0,0 +1,175 @@
+package com.netscape.cmscore.dbs;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import netscape.ldap.LDAPAttribute;
+import netscape.ldap.LDAPAttributeSet;
+
+import com.netscape.certsrv.base.EBaseException;
+import com.netscape.certsrv.dbs.EDBException;
+import com.netscape.certsrv.dbs.IDBObj;
+import com.netscape.certsrv.dbs.IDBRegistry;
+import com.netscape.certsrv.request.IRequestRecord;
+import com.netscape.cmscore.request.DBDynAttrMapperDefaultStub;
+import com.netscape.cmscore.test.CMSBaseTestCase;
+import com.netscape.cmscore.test.TestHelper;
+
+public class DBRegistryTest extends CMSBaseTestCase {
+
+ DBSubsystemStub db;
+ DBRegistry registry;
+ DBDynAttrMapperStub extAttrMapper;
+ RequestRecordStub requestRecordStub = new RequestRecordStub();
+
+ public DBRegistryTest(String name) {
+ super(name);
+ }
+
+ public void cmsTestSetUp() {
+ db = new DBSubsystemStub();
+ registry = new DBRegistry();
+ db.registry = registry;
+
+ // Emulate the registration of mappers.
+ // Normally RequestRepository calls RequestRecord.register() as part
+ // of a long chain of initialization calls.
+ extAttrMapper = new DBDynAttrMapperStub();
+ try {
+ registry.registerObjectClass(requestRecordStub.getClass().getName(),
+ new String[] { "ocvalue" });
+ registry.registerAttribute(IRequestRecord.ATTR_EXT_DATA, extAttrMapper);
+ registry.registerAttribute(IRequestRecord.ATTR_SOURCE_ID,
+ new StringMapper("sourceIdOut"));
+ registry.registerDynamicMapper(extAttrMapper);
+ } catch (EDBException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void cmsTestTearDown() {
+ }
+
+ public static Test suite() {
+ return new TestSuite(DBRegistryTest.class);
+ }
+
+ public void testMapObject() throws EBaseException {
+ assertFalse(extAttrMapper.mapObjectCalled);
+ registry.mapObject(null, IRequestRecord.ATTR_EXT_DATA, null,
+ new LDAPAttributeSet());
+ assertTrue(extAttrMapper.mapObjectCalled);
+ }
+
+ public void testGetLDAPAttributesForExtData() throws EBaseException {
+ String inAttrs[] = new String[] {
+ "extData-foo",
+ "extData-foo12",
+ "EXTDATA-bar;baz",
+ IRequestRecord.ATTR_SOURCE_ID
+ };
+ String outAttrs[] = registry.getLDAPAttributes(inAttrs);
+
+ assertTrue(TestHelper.contains(outAttrs, inAttrs[0]));
+ assertTrue(TestHelper.contains(outAttrs, inAttrs[1]));
+ assertTrue(TestHelper.contains(outAttrs, inAttrs[2]));
+ assertTrue(TestHelper.contains(outAttrs, "sourceIdOut"));
+
+ try {
+ registry.getLDAPAttributes(new String[] { "badattr" });
+ fail("Should not be able to map badattr");
+ } catch (EBaseException e) { /* good */
+ }
+ }
+
+ public void testCreateLDAPAttributeSet() throws EBaseException {
+ assertFalse(extAttrMapper.mapObjectCalled);
+
+ registry.createLDAPAttributeSet(requestRecordStub);
+ assertTrue(requestRecordStub.getCalled);
+ assertEquals(requestRecordStub.getCalledWith,
+ IRequestRecord.ATTR_EXT_DATA);
+
+ // This asserts that mapObject() is called and makes it down to the
+ // extDataDynAttrMapper.mapObjectToLDAPAttributeSet() call.
+ assertTrue(extAttrMapper.mapObjectCalled);
+ }
+
+ public void testCreateObject() throws EBaseException {
+ LDAPAttributeSet attrs = new LDAPAttributeSet();
+ attrs.add(new LDAPAttribute("objectclass", "ocvalue"));
+ attrs.add(new LDAPAttribute("extdata-foo"));
+
+ assertFalse(extAttrMapper.mapLDAPAttrsCalled);
+
+ registry.createObject(attrs);
+
+ assertTrue(extAttrMapper.mapLDAPAttrsCalled);
+ }
+
+ class DBSubsystemStub extends DBSubsystemDefaultStub {
+ DBRegistry registry;
+
+ public IDBRegistry getRegistry() {
+ return registry;
+ }
+ }
+
+ class DBDynAttrMapperStub extends DBDynAttrMapperDefaultStub {
+ boolean mapObjectCalled = false;
+ Object mapObjectCalledWithObject = null;
+ boolean mapLDAPAttrsCalled = false;
+
+ public boolean supportsLDAPAttributeName(String attrName) {
+ return (attrName != null) &&
+ attrName.toLowerCase().startsWith("extdata-");
+ }
+
+ public void mapLDAPAttributeSetToObject(LDAPAttributeSet attrs, String name, IDBObj parent)
+ throws EBaseException {
+ mapLDAPAttrsCalled = true;
+ }
+
+ public void mapObjectToLDAPAttributeSet(IDBObj parent, String name,
+ Object obj,
+ LDAPAttributeSet attrs)
+ throws EBaseException {
+ mapObjectCalled = true;
+ mapObjectCalledWithObject = obj;
+ }
+ }
+
+}
+
+/*
+ * This class is purposefully placed outside the test because
+ * DBRegistry.createObject() calls Class.newInstance() to create
+ * this stub. This fails if the class is nested.
+ */
+class RequestRecordStub extends RequestRecordDefaultStub {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 2155124580267335995L;
+
+ String[] attrs = new String[] { IRequestRecord.ATTR_EXT_DATA };
+
+ boolean getCalled = false;
+ String getCalledWith = null;
+ boolean getSerializedAttrNamesCalled = false;
+
+ public Object get(String name) {
+ getCalled = true;
+ getCalledWith = name;
+ return "foo";
+ }
+
+ public Enumeration<String> getSerializableAttrNames() {
+ getSerializedAttrNamesCalled = true;
+ return Collections.enumeration(Arrays.asList(attrs));
+ }
+}
diff --git a/base/common/test/com/netscape/cmscore/dbs/DBSSessionDefaultStub.java b/base/common/test/com/netscape/cmscore/dbs/DBSSessionDefaultStub.java
new file mode 100644
index 000000000..09a2e1498
--- /dev/null
+++ b/base/common/test/com/netscape/cmscore/dbs/DBSSessionDefaultStub.java
@@ -0,0 +1,79 @@
+package com.netscape.cmscore.dbs;
+
+import netscape.ldap.LDAPSearchResults;
+
+import com.netscape.certsrv.base.EBaseException;
+import com.netscape.certsrv.base.ISubsystem;
+import com.netscape.certsrv.dbs.EDBException;
+import com.netscape.certsrv.dbs.IDBObj;
+import com.netscape.certsrv.dbs.IDBSSession;
+import com.netscape.certsrv.dbs.IDBSearchResults;
+import com.netscape.certsrv.dbs.IDBVirtualList;
+import com.netscape.certsrv.dbs.ModificationSet;
+
+/**
+ * A default stub ojbect for tests to extend.
+ */
+public class DBSSessionDefaultStub implements IDBSSession {
+
+ public ISubsystem getDBSubsystem() {
+ return null;
+ }
+
+ public void close() throws EDBException {
+ }
+
+ public void add(String name, IDBObj obj) throws EBaseException {
+ }
+
+ public IDBObj read(String name) throws EBaseException {
+ return null;
+ }
+
+ public IDBObj read(String name, String attrs[]) throws EBaseException {
+ return null;
+ }
+
+ public void delete(String name) throws EBaseException {
+ }
+
+ public void modify(String name, ModificationSet mods) throws EBaseException {
+ }
+
+ public IDBSearchResults search(String base, String filter) throws EBaseException {
+ return null;
+ }
+
+ public IDBSearchResults search(String base, String filter, int maxSize) throws EBaseException {
+ return null;
+ }
+
+ public IDBSearchResults search(String base, String filter, int maxSize, int timeLimit) throws EBaseException {
+ return null;
+ }
+
+ public IDBSearchResults search(String base, String filter, String attrs[]) throws EBaseException {
+ return null;
+ }
+
+ public <T> IDBVirtualList<T> createVirtualList(String base, String filter, String attrs[]) throws EBaseException {
+ return null;
+ }
+
+ public LDAPSearchResults persistentSearch(String base, String filter, String attrs[]) throws EBaseException {
+ return null;
+ }
+
+ public void abandon(LDAPSearchResults results) throws EBaseException {
+ }
+
+ public <T> IDBVirtualList<T> createVirtualList(String base, String filter, String attrs[], String sortKey, int pageSize)
+ throws EBaseException {
+ return null;
+ }
+
+ public <T> IDBVirtualList<T> createVirtualList(String base, String filter, String attrs[], String startFrom,
+ String sortKey, int pageSize) throws EBaseException {
+ return null;
+ }
+}
diff --git a/base/common/test/com/netscape/cmscore/dbs/DBSubsystemDefaultStub.java b/base/common/test/com/netscape/cmscore/dbs/DBSubsystemDefaultStub.java
new file mode 100644
index 000000000..fe19159d5
--- /dev/null
+++ b/base/common/test/com/netscape/cmscore/dbs/DBSubsystemDefaultStub.java
@@ -0,0 +1,172 @@
+package com.netscape.cmscore.dbs;
+
+import java.math.BigInteger;
+
+import netscape.ldap.LDAPConnection;
+
+import com.netscape.certsrv.base.EBaseException;
+import com.netscape.certsrv.base.IConfigStore;
+import com.netscape.certsrv.base.ISubsystem;
+import com.netscape.certsrv.dbs.EDBException;
+import com.netscape.certsrv.dbs.IDBRegistry;
+import com.netscape.certsrv.dbs.IDBSSession;
+import com.netscape.certsrv.dbs.IDBSubsystem;
+
+/**
+ * A default stub ojbect for tests to extend.
+ */
+public class DBSubsystemDefaultStub implements IDBSubsystem {
+
+ public String getBaseDN() {
+ return null;
+ }
+
+ public IDBRegistry getRegistry() {
+ return null;
+ }
+
+ public IDBSSession createSession() throws EDBException {
+ return null;
+ }
+
+ public boolean enableSerialNumberRecovery() {
+ return false;
+ }
+
+ public void setNextSerialConfig(BigInteger serial) throws EBaseException {
+ }
+
+ public BigInteger getNextSerialConfig() {
+ return null;
+ }
+
+ public void setMaxSerialConfig(String serial) throws EBaseException {
+ }
+
+ public String getMinSerialConfig() {
+ return null;
+ }
+
+ public String getMaxSerialConfig() {
+ return null;
+ }
+
+ public String getMinRequestConfig() {
+ return null;
+ }
+
+ public String getMaxRequestConfig() {
+ return null;
+ }
+
+ public void returnConn(LDAPConnection conn) {
+ }
+
+ 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;
+ }
+
+ @Override
+ public void setMaxSerialConfig(int repo, String serial)
+ throws EBaseException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setMinSerialConfig(int repo, String serial)
+ throws EBaseException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setNextMaxSerialConfig(int repo, String serial)
+ throws EBaseException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setNextMinSerialConfig(int repo, String serial)
+ throws EBaseException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public String getMinSerialConfig(int repo) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getMaxSerialConfig(int repo) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getNextMaxSerialConfig(int repo) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getNextMinSerialConfig(int repo) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getLowWaterMarkConfig(int repo) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getIncrementConfig(int repo) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getNextRange(int repo) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean hasRangeConflict(int repo) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean getEnableSerialMgmt() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void setEnableSerialMgmt(boolean value) throws EBaseException {
+ // TODO Auto-generated method stub
+
+ }
+}
diff --git a/base/common/test/com/netscape/cmscore/dbs/DBVirtualListDefaultStub.java b/base/common/test/com/netscape/cmscore/dbs/DBVirtualListDefaultStub.java
new file mode 100644
index 000000000..d674bd6a6
--- /dev/null
+++ b/base/common/test/com/netscape/cmscore/dbs/DBVirtualListDefaultStub.java
@@ -0,0 +1,87 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2007 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+package com.netscape.cmscore.dbs;
+
+import com.netscape.certsrv.base.EBaseException;
+import com.netscape.certsrv.dbs.IDBVirtualList;
+import com.netscape.certsrv.dbs.IElementProcessor;
+
+/**
+ * A default stub ojbect for tests to extend.
+ * This class helps test avoid the problem of test stubs having to
+ * implement a new stub method every time the interface changes.
+ * It also makes the tests clearer by not cluttered them with empty methods.
+ *
+ * Do not put any behaviour in this class.
+ */
+public class DBVirtualListDefaultStub<T> implements IDBVirtualList<T> {
+
+ public void setPageSize(int size) {
+ }
+
+ public void setSortKey(String sortKey) throws EBaseException {
+ }
+
+ public void setSortKey(String[] sortKeys) throws EBaseException {
+ }
+
+ public int getSize() {
+ return 0;
+ }
+
+ public int getSizeBeforeJumpTo() {
+ return 0;
+ }
+
+ public int getSizeAfterJumpTo() {
+ return 0;
+ }
+
+ public int getCurrentIndex() {
+ return 0;
+ }
+
+ public boolean getPage(int first) {
+ return false;
+ }
+
+ public boolean getPage(String text) {
+ return false;
+ }
+
+ public T getElementAt(int index) {
+ return null;
+ }
+
+ public T getJumpToElementAt(int i) {
+ return null;
+ }
+
+ public void processElements(int startidx, int endidx, IElementProcessor ep)
+ throws EBaseException {
+ }
+
+ public int getSelectedIndex() {
+ return 0;
+ }
+
+ public int getFirstIndex() {
+ return 0;
+ }
+
+}
diff --git a/base/common/test/com/netscape/cmscore/dbs/RequestRecordDefaultStub.java b/base/common/test/com/netscape/cmscore/dbs/RequestRecordDefaultStub.java
new file mode 100644
index 000000000..1814c90d6
--- /dev/null
+++ b/base/common/test/com/netscape/cmscore/dbs/RequestRecordDefaultStub.java
@@ -0,0 +1,44 @@
+package com.netscape.cmscore.dbs;
+
+import java.util.Enumeration;
+
+import com.netscape.certsrv.base.EBaseException;
+import com.netscape.certsrv.dbs.IDBObj;
+import com.netscape.certsrv.request.IRequestRecord;
+import com.netscape.certsrv.request.RequestId;
+
+/**
+ * Default stub for RequestRecord tests.
+ */
+public class RequestRecordDefaultStub implements IRequestRecord, IDBObj {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 3486144284074519531L;
+
+ public RequestId getRequestId() {
+ return null;
+ }
+
+ public Enumeration<String> getAttrNames() {
+ return null;
+ }
+
+ public Object get(String name) {
+ return null;
+ }
+
+ public void set(String name, Object o) {
+ }
+
+ public void delete(String name) throws EBaseException {
+ }
+
+ public Enumeration<String> getElements() {
+ return null;
+ }
+
+ public Enumeration<String> getSerializableAttrNames() {
+ return null;
+ }
+}
diff --git a/base/common/test/com/netscape/cmscore/request/DBDynAttrMapperDefaultStub.java b/base/common/test/com/netscape/cmscore/request/DBDynAttrMapperDefaultStub.java
new file mode 100644
index 000000000..cccbe600f
--- /dev/null
+++ b/base/common/test/com/netscape/cmscore/request/DBDynAttrMapperDefaultStub.java
@@ -0,0 +1,33 @@
+package com.netscape.cmscore.request;
+
+import java.util.Enumeration;
+
+import netscape.ldap.LDAPAttributeSet;
+
+import com.netscape.certsrv.base.EBaseException;
+import com.netscape.certsrv.dbs.IDBDynAttrMapper;
+import com.netscape.certsrv.dbs.IDBObj;
+
+/**
+ * Default testing stub for the IRequest interface.
+ */
+public class DBDynAttrMapperDefaultStub implements IDBDynAttrMapper {
+ public boolean supportsLDAPAttributeName(String attrName) {
+ return false;
+ }
+
+ public Enumeration<String> getSupportedLDAPAttributeNames() {
+ return null;
+ }
+
+ public void mapObjectToLDAPAttributeSet(IDBObj parent, String name, Object obj, LDAPAttributeSet attrs)
+ throws EBaseException {
+ }
+
+ public void mapLDAPAttributeSetToObject(LDAPAttributeSet attrs, String name, IDBObj parent) throws EBaseException {
+ }
+
+ public String mapSearchFilter(String name, String op, String value) throws EBaseException {
+ return null;
+ }
+}
diff --git a/base/common/test/com/netscape/cmscore/request/ExtAttrDynMapperTest.java b/base/common/test/com/netscape/cmscore/request/ExtAttrDynMapperTest.java
new file mode 100644
index 000000000..a0ad0a8a3
--- /dev/null
+++ b/base/common/test/com/netscape/cmscore/request/ExtAttrDynMapperTest.java
@@ -0,0 +1,278 @@
+package com.netscape.cmscore.request;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import netscape.ldap.LDAPAttribute;
+import netscape.ldap.LDAPAttributeSet;
+
+import com.netscape.certsrv.base.EBaseException;
+import com.netscape.certsrv.request.IRequestRecord;
+import com.netscape.certsrv.request.RequestId;
+import com.netscape.cmscore.dbs.RequestRecordDefaultStub;
+import com.netscape.cmscore.test.CMSBaseTestCase;
+
+public class ExtAttrDynMapperTest extends CMSBaseTestCase {
+
+ ExtAttrDynMapper mapper;
+
+ public ExtAttrDynMapperTest(String name) {
+ super(name);
+ }
+
+ public void cmsTestSetUp() {
+ mapper = new ExtAttrDynMapper();
+ }
+
+ public void cmsTestTearDown() {
+ }
+
+ public static Test suite() {
+ return new TestSuite(ExtAttrDynMapperTest.class);
+ }
+
+ public void testSupportLDAPAttributeName() {
+ assertNotNull(mapper);
+
+ assertTrue(mapper.supportsLDAPAttributeName("extData-green"));
+ assertTrue(mapper.supportsLDAPAttributeName("EXTDATA-green"));
+ assertTrue(mapper.supportsLDAPAttributeName("extData-foo;0"));
+ assertTrue(mapper.supportsLDAPAttributeName("extData-bar;baz"));
+
+ assertFalse(mapper.supportsLDAPAttributeName("extDatagreen"));
+ assertFalse(mapper.supportsLDAPAttributeName("extDatafoo;0"));
+ assertFalse(mapper.supportsLDAPAttributeName("extDatabar;baz"));
+
+ assertFalse(mapper.supportsLDAPAttributeName(";extData"));
+ assertFalse(mapper.supportsLDAPAttributeName("fooextData"));
+ assertFalse(mapper.supportsLDAPAttributeName("foo-extData"));
+
+ assertFalse(mapper.supportsLDAPAttributeName(""));
+ assertFalse(mapper.supportsLDAPAttributeName(null));
+ }
+
+ public void testGetSupportedLdapAttributesNames() {
+ Enumeration<String> attrs = mapper.getSupportedLDAPAttributeNames();
+ ArrayList<String> attrsList = new ArrayList<String>();
+ while (attrs.hasMoreElements()) {
+ attrsList.add(attrs.nextElement());
+ }
+
+ assertEquals(1, attrsList.size());
+ assertEquals(Schema.LDAP_ATTR_EXT_ATTR, attrsList.get(0));
+ }
+
+ public void testIsAlphaNum() {
+ assertTrue(mapper.isAlphaNum('a'));
+ assertTrue(mapper.isAlphaNum('l'));
+ assertTrue(mapper.isAlphaNum('z'));
+ assertTrue(mapper.isAlphaNum('A'));
+ assertTrue(mapper.isAlphaNum('K'));
+ assertTrue(mapper.isAlphaNum('Z'));
+ assertTrue(mapper.isAlphaNum('0'));
+ assertTrue(mapper.isAlphaNum('5'));
+ assertTrue(mapper.isAlphaNum('9'));
+
+ assertFalse(mapper.isAlphaNum('!'));
+ assertFalse(mapper.isAlphaNum('-'));
+ assertFalse(mapper.isAlphaNum('\u00ef'));
+ }
+
+ public void testEncodeDecodeKey() {
+ // ; is 003b
+ // $ is 0024
+ // % is 0025
+ // - is 002d
+
+ String decoded = ";a$c%d-";
+ String encoded = "--003ba--0024c--0025d-";
+ assertEquals(encoded, mapper.encodeKey(decoded));
+ assertEquals(decoded, mapper.decodeKey(encoded));
+
+ decoded = ";-a-";
+ encoded = "--003b--002da-";
+ assertEquals(encoded, mapper.encodeKey(decoded));
+ assertEquals(decoded, mapper.decodeKey(encoded));
+
+ decoded = "-ab;ab";
+ encoded = "-ab--003bab";
+ assertEquals(encoded, mapper.encodeKey(decoded));
+ assertEquals(decoded, mapper.decodeKey(encoded));
+
+ decoded = "--a--b-a-b-";
+ encoded = "--002d--002da--002d--002db-a-b-";
+ assertEquals(encoded, mapper.encodeKey(decoded));
+ assertEquals(decoded, mapper.decodeKey(encoded));
+
+ decoded = "--a;-";
+ encoded = "--002d--002da--003b--002d";
+ assertEquals(encoded, mapper.encodeKey(decoded));
+ assertEquals(decoded, mapper.decodeKey(encoded));
+ }
+
+ public void testMapObjectToLDAPAttributeSet() throws EBaseException {
+ LDAPAttributeSet attrs = new LDAPAttributeSet();
+
+ // test with a key-value entry.
+ Hashtable<String, Serializable> extAttrsHash = new Hashtable<String, Serializable>();
+ extAttrsHash.put("foo;", "bar");
+
+ mapper.mapObjectToLDAPAttributeSet(null, null, extAttrsHash, attrs);
+ assertEquals(1, attrs.size());
+ assertEquals(ExtAttrDynMapper.extAttrPrefix + "foo--003b",
+ attrs.elementAt(0).getName());
+ String vals[] = attrs.elementAt(0).getStringValueArray();
+ assertEquals(1, vals.length);
+ assertEquals("bar", vals[0]);
+
+ // test with a sub-hash.
+ // this is used by vector/arrays and hashtables
+ Hashtable<String, String> extAttrsValueHash = new Hashtable<String, String>();
+ extAttrsValueHash.put("Baz", "Val1");
+ extAttrsValueHash.put("bi;m", "val2");
+
+ extAttrsHash.clear();
+ extAttrsHash.put("top;key", extAttrsValueHash);
+
+ attrs = new LDAPAttributeSet();
+ mapper.mapObjectToLDAPAttributeSet(null, null, extAttrsHash, attrs);
+ assertEquals(2, attrs.size());
+ LDAPAttribute attrBaz = attrs.elementAt(0);
+ LDAPAttribute attrBim = attrs.elementAt(1);
+ // swap attributes if necessary
+ if (attrBaz.getName().equals(ExtAttrDynMapper.extAttrPrefix +
+ "top--003bkey;bi--003bm")) {
+ attrBaz = attrs.elementAt(1);
+ attrBim = attrs.elementAt(0);
+ }
+
+ assertEquals(ExtAttrDynMapper.extAttrPrefix + "top--003bkey;Baz",
+ attrBaz.getName());
+ vals = attrBaz.getStringValueArray();
+ assertEquals(1, vals.length);
+ assertEquals("Val1", vals[0]);
+ assertTrue(attrBaz.hasSubtype("Baz"));
+
+ assertEquals(ExtAttrDynMapper.extAttrPrefix + "top--003bkey;bi--003bm",
+ attrBim.getName());
+ vals = attrBim.getStringValueArray();
+ assertEquals(1, vals.length);
+ assertEquals("val2", vals[0]);
+ assertTrue(attrBim.hasSubtype("bi--003bm"));
+ }
+
+ public void testMapLDAPAttributeSetToObject() throws EBaseException {
+ //
+ // Test simple key-value pairs
+ //
+ LDAPAttributeSet attrs = new LDAPAttributeSet();
+ attrs.add(new LDAPAttribute(
+ ExtAttrDynMapper.extAttrPrefix + "o--003bkey1", "val1"));
+ attrs.add(new LDAPAttribute("junk", "junkval"));
+ attrs.add(new LDAPAttribute(
+ ExtAttrDynMapper.extAttrPrefix + "okey2", "val2"));
+
+ RequestRecordStub requestRecord = new RequestRecordStub();
+
+ mapper.mapLDAPAttributeSetToObject(attrs, IRequestRecord.ATTR_EXT_DATA,
+ requestRecord);
+
+ assertEquals(1, requestRecord.setCallCounter);
+ Hashtable<?, ?> extData = (Hashtable<?, ?>) requestRecord.extAttrData.get(
+ IRequestRecord.ATTR_EXT_DATA);
+ assertNotNull(extData);
+
+ assertEquals(2, extData.keySet().size());
+ assertTrue(extData.containsKey("o;key1"));
+ assertEquals("val1", extData.get("o;key1"));
+ assertTrue(extData.containsKey("okey2"));
+ assertEquals("val2", extData.get("okey2"));
+
+ //
+ // Test subkeys
+ //
+ attrs = new LDAPAttributeSet();
+ attrs.add(new LDAPAttribute(
+ ExtAttrDynMapper.extAttrPrefix + "o--003bkey1;i--003bkey11", "val11"));
+ attrs.add(new LDAPAttribute(
+ ExtAttrDynMapper.extAttrPrefix.toUpperCase() + "o--003bkey1;ikey12", "val12"));
+ attrs.add(new LDAPAttribute(
+ ExtAttrDynMapper.extAttrPrefix + "o--003bkey1;ikey13", "val13"));
+ attrs.add(new LDAPAttribute(
+ ExtAttrDynMapper.extAttrPrefix + "okey2;ikey21", "val21"));
+ attrs.add(new LDAPAttribute(
+ ExtAttrDynMapper.extAttrPrefix + "okey2;ikey22", "val22"));
+ attrs.add(new LDAPAttribute("foo", "bar"));
+
+ requestRecord = new RequestRecordStub();
+
+ mapper.mapLDAPAttributeSetToObject(attrs, IRequestRecord.ATTR_EXT_DATA,
+ requestRecord);
+
+ assertEquals(1, requestRecord.setCallCounter);
+ extData = (Hashtable<?, ?>) requestRecord.extAttrData.get(
+ IRequestRecord.ATTR_EXT_DATA);
+ assertNotNull(extData);
+
+ assertTrue(extData.containsKey("o;key1"));
+ Hashtable<?, ?> okey1Data = (Hashtable<?, ?>) extData.get("o;key1");
+ assertEquals(3, okey1Data.keySet().size());
+ assertTrue(okey1Data.containsKey("i;key11"));
+ assertEquals("val11", (String) okey1Data.get("i;key11"));
+ assertTrue(okey1Data.containsKey("ikey12"));
+ assertEquals("val12", (String) okey1Data.get("ikey12"));
+ assertTrue(okey1Data.containsKey("ikey13"));
+ assertEquals("val13", (String) okey1Data.get("ikey13"));
+
+ assertTrue(extData.containsKey("okey2"));
+ Hashtable<?, ?> okey2Data = (Hashtable<?, ?>) extData.get("okey2");
+ assertEquals(2, okey2Data.keySet().size());
+ assertTrue(okey2Data.containsKey("ikey21"));
+ assertEquals("val21", (String) okey2Data.get("ikey21"));
+ assertTrue(okey2Data.containsKey("ikey22"));
+ assertEquals("val22", (String) okey2Data.get("ikey22"));
+
+ assertFalse(extData.containsKey("foo"));
+
+ //
+ // test illegal data combination
+ //
+ attrs = new LDAPAttributeSet();
+ attrs.add(new LDAPAttribute(
+ ExtAttrDynMapper.extAttrPrefix + "okey1", "val11"));
+ attrs.add(new LDAPAttribute(
+ ExtAttrDynMapper.extAttrPrefix + "okey1;ikey12", "val12"));
+
+ requestRecord = new RequestRecordStub();
+
+ try {
+ mapper.mapLDAPAttributeSetToObject(attrs, IRequestRecord.ATTR_EXT_DATA,
+ requestRecord);
+ fail("Should have thrown EBaseException on illegal data");
+ } catch (EBaseException e) {
+ // good
+ }
+
+ }
+
+ class RequestRecordStub extends RequestRecordDefaultStub {
+ private static final long serialVersionUID = 4106967075497999274L;
+ Hashtable<String, Object> extAttrData = new Hashtable<String, Object>();
+ int setCallCounter = 0;
+
+ public void set(String name, Object o) {
+ setCallCounter++;
+ if (IRequestRecord.ATTR_EXT_DATA.equals(name)) {
+ extAttrData.put(name, o);
+ }
+ }
+
+ public RequestId getRequestId() {
+ return new RequestId("1");
+ }
+ }
+}
diff --git a/base/common/test/com/netscape/cmscore/request/ExtDataHashtableTest.java b/base/common/test/com/netscape/cmscore/request/ExtDataHashtableTest.java
new file mode 100644
index 000000000..c349b73d0
--- /dev/null
+++ b/base/common/test/com/netscape/cmscore/request/ExtDataHashtableTest.java
@@ -0,0 +1,81 @@
+package com.netscape.cmscore.request;
+
+import java.util.Hashtable;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import com.netscape.cmscore.test.CMSBaseTestCase;
+
+public class ExtDataHashtableTest extends CMSBaseTestCase {
+
+ ExtDataHashtable<String> hash;
+
+ public ExtDataHashtableTest(String name) {
+ super(name);
+ }
+
+ public void cmsTestSetUp() {
+ hash = new ExtDataHashtable<String>();
+ }
+
+ public void cmsTestTearDown() {
+ }
+
+ public static Test suite() {
+ return new TestSuite(ExtDataHashtableTest.class);
+ }
+
+ public void testContainsKey() {
+ hash.put("FOO", "bar");
+ assertTrue(hash.containsKey("foo"));
+ assertTrue(hash.containsKey("Foo"));
+ }
+
+ public void testGet() {
+ hash.put("FOO", "bar");
+ assertEquals("bar", hash.get("foo"));
+ assertEquals("bar", hash.get("fOO"));
+ }
+
+ public void testPut() {
+ hash.put("FOO", "bar");
+ hash.put("foo", "bar2");
+ assertEquals(1, hash.keySet().size());
+ assertEquals("bar2", hash.get("foo"));
+ }
+
+ public void testPutAll() {
+ Hashtable<String, String> hash2 = new Hashtable<String, String>();
+ hash2.put("KEY1", "VAL1");
+ hash2.put("KEY2", "val2");
+
+ hash.putAll(hash2);
+
+ assertTrue(hash.containsKey("key1"));
+ assertEquals("VAL1", hash.get("key1"));
+ assertEquals("val2", hash.get("Key2"));
+ }
+
+ public void testRemove() {
+ hash.put("foo", "bar");
+ hash.put("one", "two");
+
+ hash.remove("FOO");
+ assertFalse(hash.containsKey("foo"));
+ assertTrue(hash.containsKey("one"));
+ }
+
+ public void testMapConstructor() {
+ Hashtable<String, String> hash2 = new Hashtable<String, String>();
+ hash2.put("KEY1", "VAL1");
+ hash2.put("KEY2", "val2");
+
+ hash = new ExtDataHashtable<String>(hash2);
+
+ assertTrue(hash.containsKey("key1"));
+ assertEquals("VAL1", hash.get("key1"));
+ assertEquals("val2", hash.get("Key2"));
+ }
+
+}
diff --git a/base/common/test/com/netscape/cmscore/request/RequestDefaultStub.java b/base/common/test/com/netscape/cmscore/request/RequestDefaultStub.java
new file mode 100644
index 000000000..fd53c2ea9
--- /dev/null
+++ b/base/common/test/com/netscape/cmscore/request/RequestDefaultStub.java
@@ -0,0 +1,269 @@
+package com.netscape.cmscore.request;
+
+import java.math.BigInteger;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Locale;
+import java.util.Vector;
+
+import netscape.security.x509.CertificateExtensions;
+import netscape.security.x509.CertificateSubjectName;
+import netscape.security.x509.RevokedCertImpl;
+import netscape.security.x509.X509CertImpl;
+import netscape.security.x509.X509CertInfo;
+
+import com.netscape.certsrv.authentication.IAuthToken;
+import com.netscape.certsrv.base.IAttrSet;
+import com.netscape.certsrv.request.IRequest;
+import com.netscape.certsrv.request.RequestId;
+import com.netscape.certsrv.request.RequestStatus;
+
+/**
+ * Default testing stub for the IRequest interface.
+ */
+public class RequestDefaultStub implements IRequest {
+ public RequestId getRequestId() {
+ return null;
+ }
+
+ public RequestStatus getRequestStatus() {
+ return null;
+ }
+
+ public String getSourceId() {
+ return null;
+ }
+
+ public void setSourceId(String id) {
+ }
+
+ public String getRequestOwner() {
+ return null;
+ }
+
+ public void setRequestOwner(String owner) {
+ }
+
+ public String getRequestType() {
+ return null;
+ }
+
+ public void setRequestType(String type) {
+ }
+
+ public String getRequestVersion() {
+ return null;
+ }
+
+ public Date getCreationTime() {
+ return null;
+ }
+
+ public Date getModificationTime() {
+ return null;
+ }
+
+ public void set(String type, Object value) {
+ }
+
+ public Object get(String type) {
+ return null;
+ }
+
+ public Enumeration<String> getAttrNames() {
+ return null;
+ }
+
+ public void deleteExtData(String type) {
+ }
+
+ public void copyContents(IRequest req) {
+ }
+
+ public String getContext() {
+ return null;
+ }
+
+ public void setContext(String ctx) {
+ }
+
+ public void setRequestStatus(RequestStatus s) {
+ }
+
+ public boolean isSuccess() {
+ return false;
+ }
+
+ public String getError(Locale locale) {
+ return null;
+ }
+
+ public boolean setExtData(String key, String value) {
+ return false;
+ }
+
+ public boolean setExtData(String key, Hashtable<String, String> value) {
+ return false;
+ }
+
+ public boolean isSimpleExtDataValue(String key) {
+ return false;
+ }
+
+ public String getExtDataInString(String key) {
+ return null;
+ }
+
+ public Hashtable<String, String> getExtDataInHashtable(String key) {
+ return null;
+ }
+
+ public Enumeration<String> getExtDataKeys() {
+ return null;
+ }
+
+ public boolean setExtData(String key, String[] values) {
+ return false;
+ }
+
+ public String[] getExtDataInStringArray(String key) {
+ return new String[0];
+ }
+
+ public boolean setExtData(String key, String subkey, String value) {
+ return false;
+ }
+
+ public String getExtDataInString(String key, String subkey) {
+ return null;
+ }
+
+ public boolean setExtData(String key, Integer value) {
+ return false;
+ }
+
+ public Integer getExtDataInInteger(String key) {
+ return null;
+ }
+
+ public boolean setExtData(String key, Integer[] values) {
+ return false;
+ }
+
+ public Integer[] getExtDataInIntegerArray(String key) {
+ return new Integer[0];
+ }
+
+ public boolean setExtData(String key, BigInteger value) {
+ return false;
+ }
+
+ public BigInteger getExtDataInBigInteger(String key) {
+ return null;
+ }
+
+ public boolean setExtData(String key, BigInteger[] values) {
+ return false;
+ }
+
+ public BigInteger[] getExtDataInBigIntegerArray(String key) {
+ return new BigInteger[0];
+ }
+
+ public boolean setExtData(String key, Throwable e) {
+ return false;
+ }
+
+ public boolean setExtData(String key, byte[] data) {
+ return false;
+ }
+
+ public byte[] getExtDataInByteArray(String key) {
+ return new byte[0];
+ }
+
+ public boolean setExtData(String key, X509CertImpl data) {
+ return false;
+ }
+
+ public X509CertImpl getExtDataInCert(String key) {
+ return null;
+ }
+
+ public boolean setExtData(String key, X509CertImpl[] data) {
+ return false;
+ }
+
+ public X509CertImpl[] getExtDataInCertArray(String key) {
+ return new X509CertImpl[0];
+ }
+
+ public boolean setExtData(String key, X509CertInfo data) {
+ return false;
+ }
+
+ public X509CertInfo getExtDataInCertInfo(String key) {
+ return null;
+ }
+
+ public boolean setExtData(String key, X509CertInfo[] data) {
+ return false;
+ }
+
+ public X509CertInfo[] getExtDataInCertInfoArray(String key) {
+ return new X509CertInfo[0];
+ }
+
+ public boolean setExtData(String key, RevokedCertImpl[] data) {
+ return false;
+ }
+
+ public RevokedCertImpl[] getExtDataInRevokedCertArray(String key) {
+ return new RevokedCertImpl[0];
+ }
+
+ public boolean setExtData(String key, Vector<?> data) {
+ return false;
+ }
+
+ public Vector<String> getExtDataInStringVector(String key) {
+ return null;
+ }
+
+ public boolean getExtDataInBoolean(String type, boolean defVal) {
+ return false;
+ }
+
+ public boolean getExtDataInBoolean(String prefix, String type, boolean defVal) {
+ return false;
+ }
+
+ public boolean setExtData(String key, IAuthToken data) {
+ return false;
+ }
+
+ public IAuthToken getExtDataInAuthToken(String key) {
+ return null;
+ }
+
+ public boolean setExtData(String key, CertificateExtensions data) {
+ return false;
+ }
+
+ public CertificateExtensions getExtDataInCertExts(String key) {
+ return null;
+ }
+
+ public boolean setExtData(String key, CertificateSubjectName data) {
+ return false;
+ }
+
+ public CertificateSubjectName getExtDataInCertSubjectName(String key) {
+ return null;
+ }
+
+ public IAttrSet asIAttrSet() {
+ return null;
+ }
+}
diff --git a/base/common/test/com/netscape/cmscore/request/RequestModDefaultStub.java b/base/common/test/com/netscape/cmscore/request/RequestModDefaultStub.java
new file mode 100644
index 000000000..730928bdb
--- /dev/null
+++ b/base/common/test/com/netscape/cmscore/request/RequestModDefaultStub.java
@@ -0,0 +1,21 @@
+package com.netscape.cmscore.request;
+
+import java.util.Date;
+
+import com.netscape.certsrv.request.IRequest;
+import com.netscape.certsrv.request.RequestStatus;
+import com.netscape.certsrv.request.ldap.IRequestMod;
+
+/**
+ * Default testing stub for the IRequest interface.
+ */
+public class RequestModDefaultStub implements IRequestMod {
+ public void modRequestStatus(IRequest r, RequestStatus s) {
+ }
+
+ public void modCreationTime(IRequest r, Date d) {
+ }
+
+ public void modModificationTime(IRequest r, Date d) {
+ }
+}
diff --git a/base/common/test/com/netscape/cmscore/request/RequestQueueTest.java b/base/common/test/com/netscape/cmscore/request/RequestQueueTest.java
new file mode 100644
index 000000000..a66326d03
--- /dev/null
+++ b/base/common/test/com/netscape/cmscore/request/RequestQueueTest.java
@@ -0,0 +1,60 @@
+package com.netscape.cmscore.request;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import com.netscape.certsrv.base.EBaseException;
+import com.netscape.cmscore.test.CMSBaseTestCase;
+
+public class RequestQueueTest extends CMSBaseTestCase {
+ RequestStub request;
+ RequestQueue queue;
+
+ public RequestQueueTest(String name) {
+ super(name);
+ }
+
+ public void cmsTestSetUp() {
+ request = new RequestStub();
+ try {
+ queue = new RequestQueue("", 1, null, null, null, null);
+ } catch (EBaseException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void cmsTestTearDown() {
+ }
+
+ public static Test suite() {
+ return new TestSuite(RequestQueueTest.class);
+ }
+
+ public void testAddRequest() throws EBaseException {
+ assertFalse(request.getExtDataKeysCalled);
+ queue.addRequest(request);
+ assertTrue(request.getExtDataKeysCalled);
+ }
+
+ class RequestStub extends RequestDefaultStub {
+ String[] keys = new String[] { "key1", "key2" };
+ boolean getExtDataKeysCalled = false;
+
+ public Enumeration<String> getExtDataKeys() {
+ getExtDataKeysCalled = true;
+ return Collections.enumeration(Arrays.asList(keys));
+ }
+
+ public boolean isSimpleExtDataValue(String key) {
+ return true;
+ }
+
+ public String getExtDataInString(String key) {
+ return "";
+ }
+ }
+}
diff --git a/base/common/test/com/netscape/cmscore/request/RequestRecordTest.java b/base/common/test/com/netscape/cmscore/request/RequestRecordTest.java
new file mode 100644
index 000000000..0ebf3beab
--- /dev/null
+++ b/base/common/test/com/netscape/cmscore/request/RequestRecordTest.java
@@ -0,0 +1,168 @@
+package com.netscape.cmscore.request;
+
+import java.util.Hashtable;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import com.netscape.certsrv.base.EBaseException;
+import com.netscape.certsrv.dbs.EDBException;
+import com.netscape.certsrv.dbs.IDBAttrMapper;
+import com.netscape.certsrv.dbs.IDBDynAttrMapper;
+import com.netscape.certsrv.dbs.IDBRegistry;
+import com.netscape.certsrv.dbs.ModificationSet;
+import com.netscape.certsrv.request.IRequestRecord;
+import com.netscape.certsrv.request.RequestId;
+import com.netscape.cmscore.dbs.DBRegistryDefaultStub;
+import com.netscape.cmscore.dbs.DBSubsystemDefaultStub;
+import com.netscape.cmscore.test.CMSBaseTestCase;
+import com.netscape.cmscore.test.TestHelper;
+
+public class RequestRecordTest extends CMSBaseTestCase {
+
+ RequestRecord requestRecord;
+ Request request;
+
+ public RequestRecordTest(String name) {
+ super(name);
+ }
+
+ public void cmsTestSetUp() {
+ requestRecord = new RequestRecord();
+ request = new Request(new RequestId("0xabcdef"));
+ }
+
+ public void cmsTestTearDown() {
+ }
+
+ public static Test suite() {
+ return new TestSuite(RequestRecordTest.class);
+ }
+
+ public void testGetExtData() {
+ Hashtable<String, Object> hash = new Hashtable<String, Object>();
+
+ assertNotSame(hash, requestRecord.get(IRequestRecord.ATTR_EXT_DATA));
+ requestRecord.mExtData = hash;
+ assertSame(hash, requestRecord.get(IRequestRecord.ATTR_EXT_DATA));
+ }
+
+ public void testSetExtData() {
+ Hashtable<String, Object> hash = new Hashtable<String, Object>();
+
+ assertNotSame(requestRecord.mExtData, hash);
+ requestRecord.set(IRequestRecord.ATTR_EXT_DATA, hash);
+ assertSame(requestRecord.mExtData, hash);
+ }
+
+ public void testGetElements() {
+ assertTrue(TestHelper.enumerationContains(requestRecord.getElements(),
+ IRequestRecord.ATTR_EXT_DATA));
+ }
+
+ public void testAddExtData() throws EBaseException {
+ request.setExtData("foo", "bar");
+ Hashtable<String, String> requestHashValue = new Hashtable<String, String>();
+ requestHashValue.put("red", "rum");
+ requestHashValue.put("blue", "gin");
+ request.setExtData("hashkey", requestHashValue);
+
+ requestRecord.add(request);
+
+ assertEquals(request.mExtData, requestRecord.mExtData);
+ assertNotSame(request.mExtData, requestRecord.mExtData);
+ }
+
+ public void testReadExtData() throws EBaseException {
+ Hashtable<String, Object> extData = new Hashtable<String, Object>();
+ extData.put("foo", "bar");
+ Hashtable<String, String> extDataHashValue = new Hashtable<String, String>();
+ extDataHashValue.put("red", "rum");
+ extDataHashValue.put("blue", "gin");
+ extData.put("hashkey", extDataHashValue);
+ requestRecord.set(IRequestRecord.ATTR_EXT_DATA, extData);
+ requestRecord.mRequestType = "foo";
+
+ requestRecord.read(new RequestModDefaultStub(), request);
+
+ // the request stores other attributes inside its mExtData when some
+ // of its setters are called, so we have to compare manually.
+ assertEquals("bar", request.mExtData.get("foo"));
+ assertEquals(extDataHashValue, request.mExtData.get("hashkey"));
+ assertNotSame(requestRecord.mExtData, request.mExtData);
+ }
+
+ public void testModExtData() throws EBaseException {
+ ModificationSetStub mods = new ModificationSetStub();
+ request.setExtData("foo", "bar");
+
+ RequestRecord.mod(mods, request);
+
+ assertTrue(mods.addCalledWithExtData);
+ assertEquals(mods.addExtDataObject, request.mExtData);
+ }
+
+ public void testRegister() throws EDBException {
+ DBSubsystemStub db = new DBSubsystemStub();
+
+ RequestRecord.register(db);
+
+ assertTrue(db.registry.registerCalledWithExtAttr);
+ assertTrue(db.registry.extAttrMapper instanceof ExtAttrDynMapper);
+
+ assertTrue(db.registry.registerObjectClassCalled);
+ assertTrue(TestHelper.contains(db.registry.registerObjectClassLdapNames,
+ "extensibleObject"));
+
+ assertTrue(db.registry.registerDynamicMapperCalled);
+ assertTrue(db.registry.dynamicMapper instanceof ExtAttrDynMapper);
+ }
+
+ class ModificationSetStub extends ModificationSet {
+ public boolean addCalledWithExtData = false;
+ public Object addExtDataObject = null;
+
+ public void add(String name, int op, Object value) {
+ if (IRequestRecord.ATTR_EXT_DATA.equals(name)) {
+ addCalledWithExtData = true;
+ addExtDataObject = value;
+ }
+ }
+ }
+
+ class DBSubsystemStub extends DBSubsystemDefaultStub {
+ DBRegistryStub registry = new DBRegistryStub();
+
+ public IDBRegistry getRegistry() {
+ return registry;
+ }
+ }
+
+ class DBRegistryStub extends DBRegistryDefaultStub {
+ boolean registerCalledWithExtAttr = false;
+ IDBAttrMapper extAttrMapper = null;
+
+ boolean registerObjectClassCalled = false;
+ String[] registerObjectClassLdapNames = null;
+
+ private boolean registerDynamicMapperCalled = false;
+ private IDBDynAttrMapper dynamicMapper;
+
+ public void registerObjectClass(String className, String ldapNames[]) throws EDBException {
+ registerObjectClassCalled = true;
+ registerObjectClassLdapNames = ldapNames;
+ }
+
+ public void registerAttribute(String ufName, IDBAttrMapper mapper) throws EDBException {
+ if (IRequestRecord.ATTR_EXT_DATA.equals(ufName)) {
+ registerCalledWithExtAttr = true;
+ extAttrMapper = mapper;
+ }
+ }
+
+ public void registerDynamicMapper(IDBDynAttrMapper mapper) {
+ registerDynamicMapperCalled = true;
+ dynamicMapper = mapper;
+ }
+ }
+}
diff --git a/base/common/test/com/netscape/cmscore/request/RequestTest.java b/base/common/test/com/netscape/cmscore/request/RequestTest.java
new file mode 100644
index 000000000..5832f6af5
--- /dev/null
+++ b/base/common/test/com/netscape/cmscore/request/RequestTest.java
@@ -0,0 +1,649 @@
+package com.netscape.cmscore.request;
+
+import java.io.IOException;
+import java.math.BigInteger;
+import java.security.cert.CRLException;
+import java.security.cert.CertificateEncodingException;
+import java.security.cert.CertificateException;
+import java.util.Hashtable;
+import java.util.Vector;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import netscape.security.x509.BasicConstraintsExtension;
+import netscape.security.x509.CertificateExtensions;
+import netscape.security.x509.CertificateSubjectName;
+import netscape.security.x509.PKIXExtensions;
+import netscape.security.x509.RevokedCertImpl;
+import netscape.security.x509.X500Name;
+import netscape.security.x509.X509CertImpl;
+import netscape.security.x509.X509CertInfo;
+
+import com.netscape.certsrv.app.CMSEngineDefaultStub;
+import com.netscape.certsrv.apps.CMS;
+import com.netscape.certsrv.authentication.AuthToken;
+import com.netscape.certsrv.authentication.IAuthToken;
+import com.netscape.certsrv.base.EBaseException;
+import com.netscape.certsrv.request.RequestId;
+import com.netscape.cmscore.test.CMSBaseTestCase;
+import com.netscape.cmscore.test.TestHelper;
+
+public class RequestTest extends CMSBaseTestCase {
+
+ Request request;
+ CMSMemoryStub cmsStub;
+
+ public RequestTest(String name) {
+ super(name);
+ }
+
+ public void cmsTestSetUp() {
+ // this is needed because of CMS.AtoB/BtoA calls
+ cmsStub = new CMSMemoryStub();
+ CMS.setCMSEngine(cmsStub);
+
+ request = new Request(new RequestId("0xabcdef"));
+ }
+
+ public void cmsTestTearDown() {
+ }
+
+ public static Test suite() {
+ return new TestSuite(RequestTest.class);
+ }
+
+ public void testIsValidKey() {
+ assertTrue(request.isValidExtDataKey("foo"));
+ assertTrue(request.isValidExtDataKey("BARBAZ"));
+ assertTrue(request.isValidExtDataKey("1122"));
+ assertTrue(request.isValidExtDataKey("-"));
+ assertTrue(request.isValidExtDataKey("1a-22"));
+ assertTrue(request.isValidExtDataKey("a;b"));
+ assertTrue(request.isValidExtDataKey("_"));
+ assertTrue(request.isValidExtDataKey("this.is.encoded"));
+ assertTrue(request.isValidExtDataKey("spaces are too"));
+
+ assertFalse(request.isValidExtDataKey(null));
+ assertFalse(request.isValidExtDataKey(""));
+ }
+
+ public void testIsSimpleExtDataValue() {
+ request.mExtData.put("simple1", "foo");
+ request.mExtData.put("complex1", new Hashtable<String, Object>());
+
+ assertTrue(request.isSimpleExtDataValue("simple1"));
+ assertFalse(request.isSimpleExtDataValue("complex1"));
+ assertFalse(request.isSimpleExtDataValue("doesn't exist"));
+ }
+
+ public void testSetExtStringData() {
+ request.setExtData("foo", "bar");
+ request.setExtData("foo2", "bar2");
+ assertEquals("bar", request.mExtData.get("foo"));
+ assertEquals("bar2", request.mExtData.get("foo2"));
+
+ request.setExtData("foo", "newvalue");
+ assertEquals("newvalue", request.mExtData.get("foo"));
+
+ request.setExtData("UPPER", "CASE");
+ assertEquals("CASE", request.mExtData.get("upper"));
+
+ assertFalse(request.setExtData("key", (String) null));
+ }
+
+ public void testVerifyValidExtDataHashtable() {
+ Hashtable<String, String> valueHash = new Hashtable<String, String>();
+
+ valueHash.put("key1", "val1");
+ valueHash.put("key;2", "val2");
+ assertTrue(request.isValidExtDataHashtableValue(valueHash));
+
+ valueHash.clear();
+ valueHash.put("", "bar");
+ assertFalse(request.isValidExtDataHashtableValue(valueHash));
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public void testSetExtHashtableData() {
+ Hashtable<String, String> valueHash = new Hashtable<String, String>();
+
+ valueHash.put("key1", "val1");
+ valueHash.put("KEY2", "val2");
+
+ request.setExtData("TOPKEY", valueHash);
+
+ Hashtable<String, String> out = request.getExtDataInHashtable("topkey");
+ assertNotNull(out);
+
+ assertTrue(out.containsKey("key1"));
+ assertEquals("val1", out.get("key1"));
+
+ assertTrue(out.containsKey("key2"));
+ assertEquals("val2", out.get("key2"));
+
+ valueHash.put("", "value");
+ assertFalse(request.setExtData("topkey2", valueHash));
+
+ assertFalse(request.setExtData("topkey3", (Hashtable) null));
+ }
+
+ public void testGetExtDataInString() {
+ request.mExtData.put("strkey", "strval");
+ Hashtable<String, String> hashValue = new Hashtable<String, String>();
+ hashValue.put("uh", "oh");
+ request.mExtData.put("hashkey", hashValue);
+
+ assertEquals("strval", request.getExtDataInString("strkey"));
+ assertEquals("strval", request.getExtDataInString("STRKEY"));
+ assertEquals(null, request.getExtDataInString("notfound"));
+
+ assertNull(request.getExtDataInString("hashkey"));
+ }
+
+ public void testGetExtDataInHashtable() {
+ request.mExtData.put("strkey", "strval");
+ Hashtable<String, String> hashValue = new Hashtable<String, String>();
+ hashValue.put("uh", "oh");
+ request.mExtData.put("hashkey", hashValue);
+
+ Hashtable<String, String> out = request.getExtDataInHashtable("HASHKEY");
+ assertNotNull(out);
+ assertNull(request.getExtDataInHashtable("notfound"));
+ assertNull(request.getExtDataInHashtable("strkey"));
+
+ // Check the bevaiour of the returned hash
+ assertEquals("oh", out.get("UH"));
+
+ // check that we can't change the ExtData by altering the Hashtable
+ hashValue = request.getExtDataInHashtable("hashkey");
+ hashValue.put("newhashkey", "newhashvalue");
+ hashValue = request.getExtDataInHashtable("hashkey");
+ assertFalse(hashValue.containsKey("newhashkey"));
+ }
+
+ public void testGetExtDataKeys() {
+ request.setExtData("FOO", "val1");
+ request.setExtData("bar", new Hashtable<String, String>());
+
+ assertTrue(TestHelper.enumerationContains(request.getExtDataKeys(), "foo"));
+ assertTrue(TestHelper.enumerationContains(request.getExtDataKeys(), "bar"));
+ }
+
+ public void testSetExtDataSubkeyValue() {
+ // creates hashtable first time
+ assertNull(request.getExtDataInHashtable("topkey"));
+ request.setExtData("TOPKEY", "SUBKEY", "value");
+ Hashtable<String, String> value = request.getExtDataInHashtable("topkey");
+ assertNotNull(value);
+ assertTrue(value.containsKey("subkey"));
+ assertEquals("value", value.get("subkey"));
+
+ // adds to existing hashtable
+ assertNull(request.getExtDataInHashtable("topkey2"));
+ value = new Hashtable<String, String>();
+ value.put("subkey2", "value2");
+ request.setExtData("topkey2", value);
+ request.setExtData("TOPKEY2", "subkey3", "value3");
+ value = request.getExtDataInHashtable("topkey2");
+ assertNotNull(value);
+ assertTrue(value.containsKey("subkey2"));
+ assertTrue(value.containsKey("subkey3"));
+ assertEquals("value3", value.get("subkey3"));
+
+ // can't sneak a bad topkey or subkey in this way
+ assertFalse(request.setExtData("", "value", "value"));
+ assertNull(request.getExtDataInHashtable(""));
+
+ assertFalse(request.setExtData("key", "", "value"));
+ assertNull(request.getExtDataInHashtable("key"));
+
+ // can't sneak into an existing hashtable
+ // this key was added above
+ assertFalse(request.setExtData("topkey", "", "value"));
+ value = request.getExtDataInHashtable("topkey");
+ assertNotNull(value);
+ assertFalse(value.containsKey(""));
+
+ // Illegal values
+ assertFalse(request.setExtData((String) null, "b", "c"));
+ assertFalse(request.setExtData("a", (String) null, "c"));
+ assertFalse(request.setExtData("a", "b", (String) null));
+ }
+
+ public void testGetExtDataSubkeyValue() {
+ Hashtable<String, String> value = new Hashtable<String, String>();
+ value.put("subkey", "value");
+
+ request.setExtData("topkey", value);
+
+ assertEquals("value", request.getExtDataInString("topkey", "SUBKEY"));
+ assertNull(request.getExtDataInString("badkey", "subkey"));
+ assertNull(request.getExtDataInString("topkey", "badkey"));
+ }
+
+ public void testGetSetExtDataInteger() {
+ request.setExtData("foo", new Integer(234));
+
+ assertNotNull(request.mExtData.get("foo"));
+ assertEquals("234", request.mExtData.get("foo"));
+
+ assertEquals(new Integer(234),
+ request.getExtDataInInteger("foo"));
+
+ request.setExtData("strkey", "bar");
+ assertNull(request.getExtDataInInteger("strkey"));
+ assertNull(request.getExtDataInInteger("notfound"));
+
+ assertFalse(request.setExtData("key", (Integer) null));
+ }
+
+ public void testGetSetExtDataIntegerArray() {
+ Integer[] data = new Integer[] {
+ new Integer(5),
+ new Integer(23),
+ new Integer(12)
+ };
+ assertTrue(request.setExtData("topkey1", data));
+ Integer[] retval = request.getExtDataInIntegerArray("topkey1");
+ assertEquals(3, retval.length);
+ assertEquals(data[0], retval[0]);
+ assertEquals(data[1], retval[1]);
+ assertEquals(data[2], retval[2]);
+
+ // invalid conversion
+ Hashtable<String, String> hashValue = new Hashtable<String, String>();
+ hashValue.put("0", "5");
+ hashValue.put("1", "bar");
+ request.setExtData("topkey2", hashValue);
+ assertNull(request.getExtDataInIntegerArray("topkey2"));
+
+ assertFalse(request.setExtData("key", (Integer[]) null));
+ }
+
+ public void testGetSetExtDataBigInteger() {
+ request.setExtData("foo", new BigInteger("234234234234"));
+
+ assertNotNull(request.mExtData.get("foo"));
+ assertEquals("234234234234", request.mExtData.get("foo"));
+
+ assertEquals(new BigInteger("234234234234"),
+ request.getExtDataInBigInteger("foo"));
+
+ request.setExtData("strkey", "bar");
+ assertNull(request.getExtDataInBigInteger("strkey"));
+ assertNull(request.getExtDataInBigInteger("notfound"));
+
+ assertFalse(request.setExtData("key", (BigInteger) null));
+ }
+
+ public void testGetSetExtDataBigIntegerArray() {
+ BigInteger[] data = new BigInteger[] {
+ new BigInteger("111111111"),
+ new BigInteger("222222222"),
+ new BigInteger("333333333")
+ };
+ assertTrue(request.setExtData("topkey1", data));
+ BigInteger[] retval = request.getExtDataInBigIntegerArray("topkey1");
+ assertEquals(3, retval.length);
+ assertEquals(data[0], retval[0]);
+ assertEquals(data[1], retval[1]);
+ assertEquals(data[2], retval[2]);
+
+ // invalid conversion
+ Hashtable<String, String> hashValue = new Hashtable<String, String>();
+ hashValue.put("0", "5");
+ hashValue.put("1", "bar");
+ request.setExtData("topkey2", hashValue);
+ assertNull(request.getExtDataInBigIntegerArray("topkey2"));
+
+ assertFalse(request.setExtData("key", (BigInteger[]) null));
+ }
+
+ public void testSetExtDataThrowable() {
+ EBaseException e = new EBaseException("This is an error");
+
+ request.setExtData("key", e);
+
+ assertEquals(e.toString(), request.mExtData.get("key"));
+
+ assertFalse(request.setExtData("key", (Throwable) null));
+ }
+
+ public void testGetSetByteArray() {
+ byte[] data = new byte[] { 112, 96, 0, -12 };
+
+ assertFalse(cmsStub.bToACalled);
+ request.setExtData("key", data);
+ assertTrue(cmsStub.bToACalled);
+ assertEquals(data, cmsStub.bToACalledWith);
+
+ assertFalse(cmsStub.aToBCalled);
+ byte[] out = request.getExtDataInByteArray("key");
+ assertTrue(cmsStub.aToBCalled);
+ assertEquals(data, out);
+
+ assertFalse(request.setExtData("key", (byte[]) null));
+ }
+
+ public void testGetSetCert() throws CertificateException {
+ X509CertImpl cert = getFakeCert();
+
+ assertFalse(cmsStub.bToACalled);
+ assertTrue(request.setExtData("key", cert));
+ assertTrue(cmsStub.bToACalled);
+
+ assertFalse(cmsStub.aToBCalled);
+ X509CertImpl retval = request.getExtDataInCert("key");
+ assertTrue(cmsStub.aToBCalled);
+ assertEquals(cert, retval);
+
+ assertFalse(request.setExtData("key", (X509CertImpl) null));
+ }
+
+ public void testGetSetCertArray() throws CertificateException {
+ // this test is also pretty weak, but fortunately relies on the
+ // building blocks.
+ X509CertImpl[] vals = new X509CertImpl[] {
+ getFakeCert(),
+ getFakeCert()
+ };
+
+ assertTrue(request.setExtData("key", vals));
+ Hashtable<?, ?> hashVals = (Hashtable<?, ?>) request.mExtData.get("key");
+ assertEquals(2, hashVals.keySet().size());
+
+ assertFalse(cmsStub.aToBCalled);
+ X509CertImpl[] retval = request.getExtDataInCertArray("key");
+ assertTrue(cmsStub.aToBCalled);
+
+ assertEquals(2, retval.length);
+ assertEquals(vals[0], retval[0]);
+ assertEquals(vals[1], retval[1]);
+
+ assertFalse(request.setExtData("key", (X509CertImpl[]) null));
+ }
+
+ public void testGetSetStringArray() {
+ String[] value = new String[] { "blue", "green", "red", "orange" };
+ assertTrue(request.setExtData("key", value));
+
+ assertTrue(request.mExtData.containsKey("key"));
+ @SuppressWarnings("unchecked")
+ Hashtable<String, String> hashValue = (Hashtable<String, String>) request.mExtData.get("key");
+ assertTrue(hashValue.containsKey("0"));
+ assertTrue(hashValue.containsKey("1"));
+ assertTrue(hashValue.containsKey("2"));
+ assertTrue(hashValue.containsKey("3"));
+ assertEquals("blue", hashValue.get("0"));
+ assertEquals("green", hashValue.get("1"));
+ assertEquals("red", hashValue.get("2"));
+ assertEquals("orange", hashValue.get("3"));
+
+ String[] retval = request.getExtDataInStringArray("key");
+ assertEquals(4, retval.length);
+ assertEquals("blue", retval[0]);
+ assertEquals("green", retval[1]);
+ assertEquals("red", retval[2]);
+ assertEquals("orange", retval[3]);
+
+ // Try with sparse input
+ hashValue = new Hashtable<String, String>();
+ hashValue.put("0", "square");
+ hashValue.put("4", "triangle");
+ hashValue.put("6", "octogon");
+ request.setExtData("kevin", hashValue);
+
+ retval = request.getExtDataInStringArray("kevin");
+ assertEquals(7, retval.length);
+ assertEquals("square", retval[0]);
+ assertNull(retval[1]);
+ assertNull(retval[2]);
+ assertNull(retval[3]);
+ assertEquals("triangle", retval[4]);
+ assertNull(retval[5]);
+ assertEquals("octogon", retval[6]);
+
+ // invalid conversion
+ hashValue = new Hashtable<String, String>();
+ hashValue.put("0", "foo");
+ hashValue.put("badkey", "bar");
+ request.setExtData("cory", hashValue);
+ assertNull(request.getExtDataInStringArray("cory"));
+
+ assertFalse(request.setExtData("key", (String[]) null));
+
+ }
+
+ public void testGetSetStringVector() {
+ Vector<String> stringVector = new Vector<String>();
+ stringVector.add("blue");
+ stringVector.add("green");
+ stringVector.add("red");
+ stringVector.add("orange");
+
+ assertTrue(request.setExtData("key", stringVector));
+
+ assertTrue(request.mExtData.containsKey("key"));
+ @SuppressWarnings("unchecked")
+ Hashtable<String, String> hashValue = (Hashtable<String, String>) request.mExtData.get("key");
+ assertTrue(hashValue.containsKey("0"));
+ assertTrue(hashValue.containsKey("1"));
+ assertTrue(hashValue.containsKey("2"));
+ assertTrue(hashValue.containsKey("3"));
+ assertEquals("blue", hashValue.get("0"));
+ assertEquals("green", hashValue.get("1"));
+ assertEquals("red", hashValue.get("2"));
+ assertEquals("orange", hashValue.get("3"));
+
+ Vector<String> retval = request.getExtDataInStringVector("key");
+ assertEquals(4, retval.size());
+ assertEquals("blue", retval.elementAt(0));
+ assertEquals("green", retval.elementAt(1));
+ assertEquals("red", retval.elementAt(2));
+ assertEquals("orange", retval.elementAt(3));
+
+ // invalid conversion
+ hashValue = new Hashtable<String, String>();
+ hashValue.put("0", "foo");
+ hashValue.put("badkey", "bar");
+ request.setExtData("cory", hashValue);
+ assertNull(request.getExtDataInStringVector("cory"));
+
+ assertFalse(request.setExtData("key", (Vector<?>) null));
+ }
+
+ public void testGetSetCertInfo() {
+ X509CertInfoStub cert = new X509CertInfoStub();
+
+ assertFalse(cmsStub.bToACalled);
+ assertFalse(cert.getEncodedCalled);
+ assertTrue(request.setExtData("key", cert));
+ assertTrue(cmsStub.bToACalled);
+ assertTrue(cert.getEncodedCalled);
+
+ // this is a pretty weak test, but it's hard to assert much here
+ assertFalse(cmsStub.aToBCalled);
+ request.getExtDataInCertInfo("key");
+ assertTrue(cmsStub.aToBCalled);
+
+ assertFalse(request.setExtData("key", (X509CertInfo) null));
+ }
+
+ public void testGetSetCertInfoArray() {
+ X509CertInfo[] vals = new X509CertInfoStub[] {
+ new X509CertInfoStub(),
+ new X509CertInfoStub()
+ };
+
+ assertTrue(request.setExtData("key", vals));
+ Hashtable<?, ?> hashVals = (Hashtable<?, ?>) request.mExtData.get("key");
+ assertEquals(2, hashVals.keySet().size());
+
+ assertFalse(cmsStub.aToBCalled);
+ request.getExtDataInCertInfoArray("key");
+ assertTrue(cmsStub.aToBCalled);
+
+ assertFalse(request.setExtData("key", (X509CertInfo[]) null));
+ }
+
+ public void testGetBoolean() {
+ Hashtable<String, String> hashValue = new Hashtable<String, String>();
+ hashValue.put("one", "false");
+ hashValue.put("two", "true");
+ hashValue.put("three", "on");
+ hashValue.put("four", "off");
+ request.mExtData.put("hashkey", hashValue);
+
+ assertFalse(request.getExtDataInBoolean("hashkey", "one", true));
+ assertTrue(request.getExtDataInBoolean("hashkey", "two", false));
+ assertTrue(request.getExtDataInBoolean("hashkey", "three", false));
+ assertFalse(request.getExtDataInBoolean("hashkey", "four", true));
+
+ assertTrue(request.getExtDataInBoolean("notfound", "nope", true));
+ assertTrue(request.getExtDataInBoolean("hashkey", "notfound", true));
+
+ assertFalse(request.getExtDataInBoolean("notfound", "nope", false));
+ assertFalse(request.getExtDataInBoolean("hashkey", "notfound", false));
+
+ request.mExtData.put("one", "false");
+ request.mExtData.put("two", "true");
+ request.mExtData.put("three", "on");
+ request.mExtData.put("four", "off");
+
+ assertFalse(request.getExtDataInBoolean("one", true));
+ assertTrue(request.getExtDataInBoolean("two", false));
+ assertTrue(request.getExtDataInBoolean("three", false));
+ assertFalse(request.getExtDataInBoolean("four", true));
+
+ assertTrue(request.getExtDataInBoolean("notfound", true));
+ assertFalse(request.getExtDataInBoolean("notfound", false));
+ }
+
+ public void testGetSetRevokedCertArray() {
+ RevokedCertImpl[] vals = new RevokedCertImplStub[] {
+ new RevokedCertImplStub(),
+ new RevokedCertImplStub()
+ };
+
+ assertTrue(request.setExtData("key", vals));
+ Hashtable<?, ?> hashVals = (Hashtable<?, ?>) request.mExtData.get("key");
+ assertEquals(2, hashVals.keySet().size());
+
+ assertFalse(cmsStub.aToBCalled);
+ request.getExtDataInCertInfoArray("key");
+ assertTrue(cmsStub.aToBCalled);
+
+ assertFalse(request.setExtData("key", (RevokedCertImpl[]) null));
+ }
+
+ public void testGetSetCertExts() throws IOException {
+ CertificateExtensions exts = new CertificateExtensions();
+ BasicConstraintsExtension ext = new BasicConstraintsExtension(false, 1);
+
+ // check if empty CertificateExtensions work
+ assertTrue(request.setExtData("key", exts));
+ CertificateExtensions retval = request.getExtDataInCertExts("key");
+ assertNotNull(retval);
+ assertEquals(0, retval.size());
+
+ exts.set(PKIXExtensions.BasicConstraints_Id.toString(), ext);
+ assertTrue(request.setExtData("key2", exts));
+ assertTrue(request.mExtData.containsKey("key2"));
+
+ retval = request.getExtDataInCertExts("key2");
+ assertNotNull(retval);
+ assertEquals(1, retval.size());
+
+ assertFalse(request.setExtData("key", (CertificateExtensions) null));
+ }
+
+ public void testGetSetCertSubjectName() throws IOException {
+ CertificateSubjectName name = new CertificateSubjectName(
+ new X500Name("cn=kevin"));
+ assertTrue(request.setExtData("key", name));
+ assertTrue(request.mExtData.containsKey("key"));
+
+ CertificateSubjectName retval = request.getExtDataInCertSubjectName("key");
+ assertNotNull(retval);
+ // the 'CN=' is uppercased at some point
+ assertEquals("cn=kevin",
+ retval.get(CertificateSubjectName.DN_NAME).toString().toLowerCase());
+
+ assertFalse(request.setExtData("key", (CertificateSubjectName) null));
+ }
+
+ public void testGetSetAuthToken() {
+ AuthToken token = new AuthToken(null);
+ token.set("key1", "val1");
+ token.set("key2", "val2");
+ token.set("key3", Integer.valueOf(5));
+
+ assertTrue(request.setExtData("key", token));
+
+ IAuthToken retval = request.getExtDataInAuthToken("key");
+ assertNotNull(retval);
+
+ assertEquals(token.getInString("key1"), retval.getInString("key1"));
+ assertEquals(token.getInString("key2"), retval.getInString("key2"));
+ assertEquals(token.getInInteger("key3"), retval.getInInteger("key3"));
+
+ assertFalse(request.setExtData("key", (AuthToken) 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;
+ }
+ }
+
+ class X509CertInfoStub extends X509CertInfo {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -821992386369710423L;
+ boolean getEncodedCalled = false;
+
+ public X509CertInfoStub() {
+ }
+
+ public byte[] getEncodedInfo(boolean ignoreCache) throws CertificateEncodingException {
+ getEncodedCalled = true;
+ return new byte[] {};
+ }
+ }
+
+ class RevokedCertImplStub extends RevokedCertImpl {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -9088436260566619005L;
+ boolean getEncodedCalled = false;
+
+ public byte[] getEncoded() throws CRLException {
+ getEncodedCalled = true;
+ return new byte[] {};
+ }
+ }
+
+}
diff --git a/base/common/test/com/netscape/cmscore/test/CMSBaseTestCase.java b/base/common/test/com/netscape/cmscore/test/CMSBaseTestCase.java
new file mode 100644
index 000000000..d3971afd4
--- /dev/null
+++ b/base/common/test/com/netscape/cmscore/test/CMSBaseTestCase.java
@@ -0,0 +1,99 @@
+package com.netscape.cmscore.test;
+
+import java.security.cert.CertificateException;
+
+import junit.framework.TestCase;
+import netscape.security.x509.X509CertImpl;
+
+import com.netscape.certsrv.app.CMSEngineDefaultStub;
+import com.netscape.certsrv.apps.CMS;
+import com.netscape.certsrv.dbs.EDBException;
+import com.netscape.certsrv.dbs.IDBRegistry;
+import com.netscape.certsrv.dbs.IDBSSession;
+import com.netscape.certsrv.logging.ILogger;
+import com.netscape.certsrv.logging.LoggerDefaultStub;
+import com.netscape.cmscore.dbs.DBRegistryDefaultStub;
+import com.netscape.cmscore.dbs.DBSSessionDefaultStub;
+import com.netscape.cmscore.dbs.DBSubsystem;
+import com.netscape.cmscore.dbs.DBSubsystemDefaultStub;
+
+/**
+ * The base class for all CMS unit tests. This sets up some basic stubs
+ * that allow unit tests to work without bumping into uninitialized subsystems
+ * (like the CMS logging system).
+ */
+public abstract class CMSBaseTestCase extends TestCase {
+ CMSEngineStub engine;
+ LoggerDefaultStub logger;
+ DBSubsystemStub db;
+ DBRegistryDefaultStub registry;
+ DBSSessionDefaultStub session;
+
+ public CMSBaseTestCase(String name) {
+ super(name);
+ }
+
+ public final void setUp() {
+ engine = new CMSEngineStub();
+ logger = new LoggerDefaultStub();
+ db = new DBSubsystemStub();
+ registry = new DBRegistryDefaultStub();
+ session = new DBSSessionDefaultStub();
+
+ CMS.setCMSEngine(engine);
+ DBSubsystem.setInstance(db);
+
+ cmsTestSetUp();
+ }
+
+ public final void tearDown() {
+ cmsTestTearDown();
+ }
+
+ public abstract void cmsTestSetUp();
+
+ public abstract void cmsTestTearDown();
+
+ public X509CertImpl getFakeCert() throws CertificateException {
+ byte[] certData = new byte[] {
+ 48, -126, 1, 18, 48, -127, -67, -96, 3, 2, 1, 2, 2, 1,
+ 1, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 4,
+ 5, 0, 48, 18, 49, 16, 48, 14, 6, 3, 85, 4, 3, 19,
+ 7, 116, 101, 115, 116, 105, 110, 103, 48, 30, 23, 13, 48, 55,
+ 48, 55, 49, 50, 49, 55, 51, 56, 51, 52, 90, 23, 13, 48,
+ 55, 49, 48, 49, 50, 49, 55, 51, 56, 51, 52, 90, 48, 18,
+ 49, 16, 48, 14, 6, 3, 85, 4, 3, 19, 7, 116, 101, 115,
+ 116, 105, 110, 103, 48, 92, 48, 13, 6, 9, 42, -122, 72, -122,
+ -9, 13, 1, 1, 1, 5, 0, 3, 75, 0, 48, 72, 2, 65,
+ 0, -65, 121, -119, -59, 105, 66, -122, -78, -30, -64, 63, -47, 44,
+ -48, -104, 103, -47, -108, 42, -38, 46, -8, 32, 49, -29, -26, -112,
+ -29, -86, 71, 24, -104, 78, -31, -75, -128, 90, -92, -34, -51, -125,
+ -13, 80, 101, -78, 39, -119, -38, 117, 28, 67, -19, -71, -124, -85,
+ 105, -53, -103, -59, -67, -38, -83, 118, 65, 2, 3, 1, 0, 1,
+ 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 4, 5,
+ 0, 3, 65, 0, -97, -62, 79, -28, 124, -81, 98, 119, -85, -49,
+ 62, -81, 46, -25, -29, 78, -40, 118, -2, 114, -128, 74, -47, -68,
+ 52, 11, -14, 30, -46, -95, -26, -108, -19, 110, -63, -70, 61, -75,
+ 64, 74, -33, -65, -96, 120, -109, 37, 77, -76, 38, -114, 58, -80,
+ -122, -39, -65, -31, 37, -30, -126, 126, 17, -82, 92, 64,
+ };
+
+ return new X509CertImpl(certData);
+ }
+
+ class CMSEngineStub extends CMSEngineDefaultStub {
+ public ILogger getLogger() {
+ return logger;
+ }
+ }
+
+ class DBSubsystemStub extends DBSubsystemDefaultStub {
+ public IDBSSession createSession() throws EDBException {
+ return session;
+ }
+
+ public IDBRegistry getRegistry() {
+ return registry;
+ }
+ }
+}
diff --git a/base/common/test/com/netscape/cmscore/test/TestHelper.java b/base/common/test/com/netscape/cmscore/test/TestHelper.java
new file mode 100644
index 000000000..55d2ac7f7
--- /dev/null
+++ b/base/common/test/com/netscape/cmscore/test/TestHelper.java
@@ -0,0 +1,30 @@
+package com.netscape.cmscore.test;
+
+import java.util.Enumeration;
+
+/**
+ * Testing helper methods
+ */
+public class TestHelper {
+
+ public static boolean enumerationContains(Enumeration<?> enumeration,
+ Object element) {
+ while (enumeration.hasMoreElements()) {
+ if (enumeration.nextElement().equals(element)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static boolean contains(String[] list, String element) {
+ for (int index = 0; index < list.length; index++) {
+ if (list[index].equals(element)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+}