summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAde Lee <alee@redhat.com>2012-01-20 09:32:39 -0500
committerAde Lee <alee@redhat.com>2012-02-08 16:03:25 -0500
commit0e00119c8947c65997505d36b6732df72867f868 (patch)
tree1471a37e30f5f22fd3ea070143cd755b72976f9f
parent4b474730b874f159ff5af4c897c0fb3d0226508d (diff)
downloadpki-0e00119c8947c65997505d36b6732df72867f868.tar.gz
pki-0e00119c8947c65997505d36b6732df72867f868.tar.xz
pki-0e00119c8947c65997505d36b6732df72867f868.zip
Fix test client errors
Added ClientResponse annotation to SystemCertificateResource. Added Consumes annotation to KeyResource, KeyRequestResource Added checks for empty search results to test client, as well as stripping header, trailer from transport cert.
-rw-r--r--pki/base/common/src/com/netscape/cms/servlet/admin/SystemCertificateResource.java6
-rw-r--r--pki/base/common/src/com/netscape/cms/servlet/base/CMSResourceService.java4
-rw-r--r--pki/base/common/src/com/netscape/cms/servlet/key/KeyResource.java1
-rw-r--r--pki/base/common/src/com/netscape/cms/servlet/key/KeysResourceService.java2
-rw-r--r--pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestResource.java2
-rw-r--r--pki/base/kra/functional/src/com/netscape/cms/servlet/test/DRMRestClient.java9
-rw-r--r--pki/base/kra/functional/src/com/netscape/cms/servlet/test/DRMTest.java56
7 files changed, 52 insertions, 28 deletions
diff --git a/pki/base/common/src/com/netscape/cms/servlet/admin/SystemCertificateResource.java b/pki/base/common/src/com/netscape/cms/servlet/admin/SystemCertificateResource.java
index 6c4c0bc54..d4cfcd296 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/admin/SystemCertificateResource.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/admin/SystemCertificateResource.java
@@ -6,6 +6,10 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import org.jboss.resteasy.annotations.ClientResponseType;
+
+import com.netscape.cms.servlet.cert.model.CertificateData;
+
@Path("/config/cert")
public interface SystemCertificateResource {
@@ -14,7 +18,7 @@ public interface SystemCertificateResource {
*/
@GET
@Path("/transport")
- //@ClientResponseType(CertificateData.class)
+ @ClientResponseType(entityType=CertificateData.class)
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_XML })
public Response getTransportCert();
diff --git a/pki/base/common/src/com/netscape/cms/servlet/base/CMSResourceService.java b/pki/base/common/src/com/netscape/cms/servlet/base/CMSResourceService.java
index 74d847d0a..acddba559 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/base/CMSResourceService.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/base/CMSResourceService.java
@@ -35,8 +35,8 @@ import com.netscape.cms.servlet.cert.model.CertificateData;
*
*/
public class CMSResourceService {
- protected static final String HEADER = "-----BEGIN NEW CERTIFICATE REQUEST-----";
- protected static final String TRAILER = "-----END NEW CERTIFICATE REQUEST-----";
+ public static final String HEADER = "-----BEGIN NEW CERTIFICATE REQUEST-----";
+ public static final String TRAILER = "-----END NEW CERTIFICATE REQUEST-----";
// caching parameters
protected static final int DEFAULT_LONG_CACHE_LIFETIME = 1000;
diff --git a/pki/base/common/src/com/netscape/cms/servlet/key/KeyResource.java b/pki/base/common/src/com/netscape/cms/servlet/key/KeyResource.java
index c6ddda698..a47c46d86 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/key/KeyResource.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/key/KeyResource.java
@@ -28,5 +28,6 @@ public interface KeyResource {
@POST
@Path("retrieve")
@Produces(MediaType.TEXT_XML)
+ @Consumes({ MediaType.APPLICATION_FORM_URLENCODED})
public KeyData retrieveKey(MultivaluedMap<String, String> form);
}
diff --git a/pki/base/common/src/com/netscape/cms/servlet/key/KeysResourceService.java b/pki/base/common/src/com/netscape/cms/servlet/key/KeysResourceService.java
index b5032fa86..471abc161 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/key/KeysResourceService.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/key/KeysResourceService.java
@@ -76,7 +76,7 @@ public class KeysResourceService extends CMSResourceService implements KeysResou
}
if (clientID != null) {
- filter += "(clientID=" + clientID + ")";
+ filter += "(clientID=\'" + clientID + "\')";
matches ++;
}
diff --git a/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestResource.java b/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestResource.java
index 0a476c49c..146b03d89 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestResource.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/request/KeyRequestResource.java
@@ -27,6 +27,7 @@ public interface KeyRequestResource {
@POST
@Path("archive")
@Produces({ MediaType.TEXT_XML })
+ @Consumes({ MediaType.APPLICATION_FORM_URLENCODED})
public KeyRequestInfo archiveKey(MultivaluedMap<String, String> form);
@POST
@@ -39,6 +40,7 @@ public interface KeyRequestResource {
@POST
@Path("recover")
@Produces({ MediaType.TEXT_XML })
+ @Consumes({ MediaType.APPLICATION_FORM_URLENCODED})
public KeyRequestInfo recoverKey(MultivaluedMap<String, String> form);
@POST
diff --git a/pki/base/kra/functional/src/com/netscape/cms/servlet/test/DRMRestClient.java b/pki/base/kra/functional/src/com/netscape/cms/servlet/test/DRMRestClient.java
index 412df39a9..06d5d961f 100644
--- a/pki/base/kra/functional/src/com/netscape/cms/servlet/test/DRMRestClient.java
+++ b/pki/base/kra/functional/src/com/netscape/cms/servlet/test/DRMRestClient.java
@@ -3,10 +3,8 @@ package com.netscape.cms.servlet.test;
import java.util.Collection;
import java.util.Iterator;
-import javax.ws.rs.core.Response;
-
+import org.jboss.resteasy.client.ClientResponse;
import org.jboss.resteasy.client.ProxyFactory;
-
import com.netscape.cms.servlet.admin.SystemCertificateResource;
import com.netscape.cms.servlet.cert.model.CertificateData;
import com.netscape.cms.servlet.key.KeyResource;
@@ -38,8 +36,9 @@ public class DRMRestClient {
}
public String getTransportCert() {
- Response response = systemCertClient.getTransportCert();
- CertificateData certData = (CertificateData) response.getEntity();
+ @SuppressWarnings("unchecked")
+ ClientResponse<CertificateData> response = (ClientResponse<CertificateData>) systemCertClient.getTransportCert();
+ CertificateData certData = response.getEntity();
String transportCert = certData.getB64();
return transportCert;
}
diff --git a/pki/base/kra/functional/src/com/netscape/cms/servlet/test/DRMTest.java b/pki/base/kra/functional/src/com/netscape/cms/servlet/test/DRMTest.java
index dbe7e7d79..a8560dc2e 100644
--- a/pki/base/kra/functional/src/com/netscape/cms/servlet/test/DRMTest.java
+++ b/pki/base/kra/functional/src/com/netscape/cms/servlet/test/DRMTest.java
@@ -59,6 +59,8 @@ import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
+
+import com.netscape.cms.servlet.base.CMSResourceService;
import com.netscape.cms.servlet.key.model.KeyData;
import com.netscape.cms.servlet.key.model.KeyDataInfo;
import com.netscape.cms.servlet.request.model.KeyRequestInfo;
@@ -76,12 +78,14 @@ public class DRMTest {
String host = null;
String port = null;
String token_pwd = null;
+ String db_dir = "./";
// parse command line arguments
Options options = new Options();
options.addOption("h", true, "Hostname of the DRM");
options.addOption("p", true, "Port of the DRM");
options.addOption("w", true, "Token password");
+ options.addOption("d", true, "Directory for tokendb");
try {
CommandLineParser parser = new PosixParser();
@@ -108,6 +112,10 @@ public class DRMTest {
usage(options);
}
+ if (cmd.hasOption("d")) {
+ db_dir = cmd.getOptionValue("d");
+ }
+
} catch (ParseException e) {
System.err.println("Error in parsing command line options: " + e.getMessage());
usage(options);
@@ -120,35 +128,34 @@ public class DRMTest {
CryptoManager manager = null;
CryptoToken token = null;
KeyGenerator kg1 = null;
- String db_dir = "./";
-
+
// used for wrapping to send data to DRM
String transportCert = null;
-
+
// Data to be archived
SymmetricKey vek = null;
String passphrase = null;
-
+
// Session keys and passphrases for recovery
SymmetricKey recoveryKey = null;
byte[] wrappedRecoveryKey = null;
String recoveryPassphrase = null;
byte[] wrappedRecoveryPassphrase = null;
-
+
// retrieved data (should match archived data)
String wrappedRecoveredKey = null;
String recoveredKey = null;
-
+
// various ids used in recovery/archival operations
String keyId = null;
String clientId = null;
String recoveryRequestId = null;
-
+
// Variables for data structures from calls
KeyRequestInfo requestInfo = null;
KeyData keyData = null;
KeyDataInfo keyInfo = null;
-
+
// Initialize token
try {
CryptoManager.initialize(db_dir);
@@ -175,31 +182,42 @@ public class DRMTest {
} catch (Exception e) {
log("Exception in logging into token:" + e.toString());
}
-
+
// Set base URI and get client
- String baseUri = "http://" + host + ":" + port + "/pki";
+ String baseUri = "http://" + host + ":" + port + "/kra/pki";
DRMRestClient client = new DRMRestClient(baseUri);
// Test 1: Get transport certificate from DRM
transportCert = client.getTransportCert();
+ transportCert = transportCert.substring(CMSResourceService.HEADER.length(),
+ transportCert.indexOf(CMSResourceService.TRAILER));
+
log("Transport Cert retrieved from DRM: " + transportCert);
// Test 2: Get list of completed key archival requests
log("\n\nList of completed archival requests");
- Collection<KeyRequestInfo> list = client.listRequests("complete", "enrolment");
- Iterator<KeyRequestInfo> iter = list.iterator();
- while (iter.hasNext()) {
- KeyRequestInfo info = iter.next();
- printRequestInfo(info);
+ Collection<KeyRequestInfo> list = client.listRequests("complete", "enrollment");
+ if (list == null) {
+ log("No requests found");
+ } else {
+ Iterator<KeyRequestInfo> iter = list.iterator();
+ while (iter.hasNext()) {
+ KeyRequestInfo info = iter.next();
+ printRequestInfo(info);
+ }
}
// Test 3: Get list of key recovery requests
log("\n\nList of completed recovery requests");
Collection<KeyRequestInfo> list2 = client.listRequests("complete", "recovery");
- Iterator<KeyRequestInfo> iter2 = list2.iterator();
- while (iter2.hasNext()) {
- KeyRequestInfo info = iter2.next();
- printRequestInfo(info);
+ if (list2 == null) {
+ log("No requests found");
+ } else {
+ Iterator<KeyRequestInfo> iter2 = list2.iterator();
+ while (iter2.hasNext()) {
+ KeyRequestInfo info = iter2.next();
+ printRequestInfo(info);
+ }
}
// Test 4: Generate and archive a symmetric key