summaryrefslogtreecommitdiff
path: root/qpid/java/systests/src
diff options
context:
space:
mode:
authorAndrew MacBean <macbean@apache.org>2015-01-14 10:38:04 +0000
committerAndrew MacBean <macbean@apache.org>2015-01-14 10:38:04 +0000
commit9b1d37a0cbef71478b58c6acee4f72a2474a9f7d (patch)
tree3ee1529447ca2606eed37d1d6d0293b86f3c2e58 /qpid/java/systests/src
parentf457cc314c6bc692731a87e8fed86d049e7c66c6 (diff)
downloadqpid-python-9b1d37a0cbef71478b58c6acee4f72a2474a9f7d.tar.gz
QPID-6304: [Java Broker] Allow truststore and keystore (JKS) files to be stored as a data:// URL inside the config
* Added truststore/keystore unit tests too to cover both new and (most of) the existing functionality, retiring the equivilent slower REST system tests. * Added single REST test exercising the creation of a keystore/teststore from data:// URL. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1651615 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/systests/src')
-rw-r--r--qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/KeyStoreRestTest.java172
-rw-r--r--qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/TrustStoreRestTest.java147
2 files changed, 72 insertions, 247 deletions
diff --git a/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/KeyStoreRestTest.java b/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/KeyStoreRestTest.java
index 169ece986e..03b0a7a304 100644
--- a/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/KeyStoreRestTest.java
+++ b/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/KeyStoreRestTest.java
@@ -20,23 +20,20 @@
*/
package org.apache.qpid.systest.rest;
-import java.io.IOException;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.codehaus.jackson.JsonGenerationException;
-import org.codehaus.jackson.JsonParseException;
-import org.codehaus.jackson.map.JsonMappingException;
+import javax.servlet.http.HttpServletResponse;
+
import org.apache.qpid.server.model.AbstractConfiguredObject;
import org.apache.qpid.server.model.KeyStore;
-import org.apache.qpid.server.model.Port;
-import org.apache.qpid.server.model.Transport;
import org.apache.qpid.server.security.FileKeyStore;
import org.apache.qpid.test.utils.TestBrokerConfiguration;
import org.apache.qpid.test.utils.TestSSLConstants;
+import org.apache.qpid.util.DataUrlUtils;
+import org.apache.qpid.util.FileUtils;
public class KeyStoreRestTest extends QpidRestTestCase
{
@@ -67,7 +64,7 @@ public class KeyStoreRestTest extends QpidRestTestCase
String certAlias = "app2";
assertNumberOfKeyStores(1);
- createKeyStore(name, certAlias);
+ createKeyStore(name, certAlias, TestSSLConstants.KEYSTORE, TestSSLConstants.KEYSTORE_PASSWORD);
assertNumberOfKeyStores(2);
List<Map<String, Object>> keyStores = getRestTestHelper().getJsonAsList("keystore/" + name);
@@ -76,161 +73,72 @@ public class KeyStoreRestTest extends QpidRestTestCase
assertKeyStoreAttributes(keyStores.get(0), name, TestSSLConstants.KEYSTORE, certAlias);
}
- public void testDelete() throws Exception
+ public void testCreateWithDataUrl() throws Exception
{
super.setUp();
String name = getTestName();
- String certAlias = "app2";
+ byte[] keystoreAsBytes = FileUtils.readFileAsBytes(TestSSLConstants.KEYSTORE);
+ String dataUrlForKeyStore = DataUrlUtils.getDataUrlForBytes(keystoreAsBytes);
assertNumberOfKeyStores(1);
- createKeyStore(name, certAlias);
- assertNumberOfKeyStores(2);
-
- int responseCode = getRestTestHelper().submitRequest("keystore/" + name , "DELETE");
- assertEquals("Unexpected response code for provider deletion", 200, responseCode);
-
- List<Map<String, Object>> keyStore = getRestTestHelper().getJsonAsList("keystore/" + name);
- assertNotNull("details should not be null", keyStore);
- assertTrue("details should be empty as the keystore no longer exists", keyStore.isEmpty());
-
- //check only the default systests key store remains
- List<Map<String, Object>> keyStores = assertNumberOfKeyStores(1);
- Map<String, Object> keystore = keyStores.get(0);
- assertKeyStoreAttributes(keystore, TestBrokerConfiguration.ENTRY_NAME_SSL_KEYSTORE,
- QPID_HOME + "/../" + TestSSLConstants.BROKER_KEYSTORE, null);
- }
-
- public void testDeleteFailsWhenKeyStoreInUse() throws Exception
- {
- String name = "testDeleteFailsWhenKeyStoreInUse";
-
- //add a new key store config to use
- Map<String, Object> sslKeyStoreAttributes = new HashMap<String, Object>();
- sslKeyStoreAttributes.put(KeyStore.NAME, name);
- sslKeyStoreAttributes.put(FileKeyStore.PATH, TestSSLConstants.BROKER_KEYSTORE);
- sslKeyStoreAttributes.put(FileKeyStore.PASSWORD, TestSSLConstants.BROKER_KEYSTORE_PASSWORD);
- getBrokerConfiguration().addObjectConfiguration(KeyStore.class,sslKeyStoreAttributes);
-
- //add the SSL port using it
- Map<String, Object> sslPortAttributes = new HashMap<String, Object>();
- sslPortAttributes.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL));
- sslPortAttributes.put(Port.PORT, DEFAULT_SSL_PORT);
- sslPortAttributes.put(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_SSL_PORT);
- sslPortAttributes.put(Port.AUTHENTICATION_PROVIDER, TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER);
- sslPortAttributes.put(Port.KEY_STORE, name);
- getBrokerConfiguration().addObjectConfiguration(Port.class,sslPortAttributes);
-
- super.setUp();
-
- //verify the keystore is there
+ createKeyStore(name, null, dataUrlForKeyStore, TestSSLConstants.KEYSTORE_PASSWORD);
assertNumberOfKeyStores(2);
- List<Map<String, Object>> keyStore = getRestTestHelper().getJsonAsList("keystore/" + name);
- assertNotNull("details should not be null", keyStore);
- assertKeyStoreAttributes(keyStore.get(0), name, TestSSLConstants.BROKER_KEYSTORE, null);
-
- //try to delete it, which should fail as it is in use
- int responseCode = getRestTestHelper().submitRequest("keystore/" + name , "DELETE");
- assertEquals("Unexpected response code for provider deletion", 409, responseCode);
+ List<Map<String, Object>> keyStores = getRestTestHelper().getJsonAsList("keystore/" + name);
+ assertNotNull("details cannot be null", keyStores);
- //check its still there
- assertNumberOfKeyStores(2);
- keyStore = getRestTestHelper().getJsonAsList("keystore/" + name);
- assertNotNull("details should not be null", keyStore);
- assertKeyStoreAttributes(keyStore.get(0), name, TestSSLConstants.BROKER_KEYSTORE, null);
+ assertKeyStoreAttributes(keyStores.get(0), name, dataUrlForKeyStore, null);
}
- public void testUpdateWithGoodPathSucceeds() throws Exception
+ public void testDelete() throws Exception
{
super.setUp();
String name = getTestName();
+ String certAlias = "app2";
assertNumberOfKeyStores(1);
- createKeyStore(name, null);
+ createKeyStore(name, certAlias, TestSSLConstants.KEYSTORE, TestSSLConstants.KEYSTORE_PASSWORD);
assertNumberOfKeyStores(2);
- Map<String, Object> attributes = new HashMap<String, Object>();
- attributes.put(KeyStore.NAME, name);
- attributes.put(FileKeyStore.PATH, TestSSLConstants.UNTRUSTED_KEYSTORE);
-
- int responseCode = getRestTestHelper().submitRequest("keystore/" + name , "PUT", attributes);
- assertEquals("Unexpected response code for keystore update", 200, responseCode);
+ getRestTestHelper().submitRequest("keystore/" + name, "DELETE", HttpServletResponse.SC_OK);
List<Map<String, Object>> keyStore = getRestTestHelper().getJsonAsList("keystore/" + name);
assertNotNull("details should not be null", keyStore);
+ assertTrue("details should be empty as the keystore no longer exists", keyStore.isEmpty());
- assertKeyStoreAttributes(keyStore.get(0), name, TestSSLConstants.UNTRUSTED_KEYSTORE, null);
+ //check only the default systests key store remains
+ List<Map<String, Object>> keyStores = assertNumberOfKeyStores(1);
+ Map<String, Object> keystore = keyStores.get(0);
+ assertKeyStoreAttributes(keystore, TestBrokerConfiguration.ENTRY_NAME_SSL_KEYSTORE,
+ QPID_HOME + "/../" + TestSSLConstants.BROKER_KEYSTORE, null);
}
- public void testUpdateWithNonExistentPathFails() throws Exception
+ public void testUpdate() throws Exception
{
super.setUp();
String name = getTestName();
assertNumberOfKeyStores(1);
- createKeyStore(name, null);
+ createKeyStore(name, null, TestSSLConstants.KEYSTORE, TestSSLConstants.KEYSTORE_PASSWORD);
assertNumberOfKeyStores(2);
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put(KeyStore.NAME, name);
- attributes.put(FileKeyStore.PATH, "does.not.exist");
+ attributes.put(FileKeyStore.PATH, TestSSLConstants.UNTRUSTED_KEYSTORE);
- int responseCode = getRestTestHelper().submitRequest("keystore/" + name , "PUT", attributes);
- assertEquals("Unexpected response code for keystore update", 409, responseCode);
+ getRestTestHelper().submitRequest("keystore/" + name, "PUT", attributes, HttpServletResponse.SC_OK);
List<Map<String, Object>> keyStore = getRestTestHelper().getJsonAsList("keystore/" + name);
assertNotNull("details should not be null", keyStore);
- //verify the details remain unchanged
- assertKeyStoreAttributes(keyStore.get(0), name, TestSSLConstants.KEYSTORE, null);
+ assertKeyStoreAttributes(keyStore.get(0), name, TestSSLConstants.UNTRUSTED_KEYSTORE, null);
}
- public void testUpdateCertificateAlias() throws Exception
- {
- super.setUp();
-
- String name = getTestName();
-
- assertNumberOfKeyStores(1);
- createKeyStore(name, "app1");
- assertNumberOfKeyStores(2);
-
- List<Map<String, Object>> keyStore = getRestTestHelper().getJsonAsList("keystore/" + name);
- assertNotNull("details should not be null", keyStore);
- assertKeyStoreAttributes(keyStore.get(0), name, TestSSLConstants.KEYSTORE, "app1");
-
- //Update the certAlias from app1 to app2
- Map<String, Object> attributes = new HashMap<String, Object>();
- attributes.put(KeyStore.NAME, name);
- attributes.put(FileKeyStore.CERTIFICATE_ALIAS, "app2");
-
- int responseCode = getRestTestHelper().submitRequest("keystore/" + name , "PUT", attributes);
- assertEquals("Unexpected response code for keystore update", 200, responseCode);
-
- keyStore = getRestTestHelper().getJsonAsList("keystore/" + name);
- assertNotNull("details should not be null", keyStore);
-
- assertKeyStoreAttributes(keyStore.get(0), name, TestSSLConstants.KEYSTORE, "app2");
-
- //Update the certAlias to clear it (i.e go from from app1 to null)
- attributes = new HashMap<String, Object>();
- attributes.put(KeyStore.NAME, name);
- attributes.put(FileKeyStore.CERTIFICATE_ALIAS, null);
-
- responseCode = getRestTestHelper().submitRequest("keystore/" + name , "PUT", attributes);
- assertEquals("Unexpected response code for keystore update", 200, responseCode);
- keyStore = getRestTestHelper().getJsonAsList("keystore/" + name);
- assertNotNull("details should not be null", keyStore);
-
- assertKeyStoreAttributes(keyStore.get(0), name, TestSSLConstants.KEYSTORE, null);
- }
-
- private List<Map<String, Object>> assertNumberOfKeyStores(int numberOfKeystores) throws IOException,
- JsonParseException, JsonMappingException
+ private List<Map<String, Object>> assertNumberOfKeyStores(int numberOfKeystores) throws Exception
{
List<Map<String, Object>> keyStores = getRestTestHelper().getJsonAsList("keystore");
assertNotNull("keystores should not be null", keyStores);
@@ -239,16 +147,18 @@ public class KeyStoreRestTest extends QpidRestTestCase
return keyStores;
}
- private void createKeyStore(String name, String certAlias) throws IOException, JsonGenerationException, JsonMappingException
+ private void createKeyStore(String name, String certAlias, final String keyStorePath, final String keystorePassword) throws Exception
{
- Map<String, Object> keyStoreAttributes = new HashMap<String, Object>();
+ Map<String, Object> keyStoreAttributes = new HashMap<>();
keyStoreAttributes.put(KeyStore.NAME, name);
- keyStoreAttributes.put(FileKeyStore.PATH, TestSSLConstants.KEYSTORE);
- keyStoreAttributes.put(FileKeyStore.PASSWORD, TestSSLConstants.KEYSTORE_PASSWORD);
- keyStoreAttributes.put(FileKeyStore.CERTIFICATE_ALIAS, certAlias);
+ keyStoreAttributes.put(FileKeyStore.PATH, keyStorePath);
+ keyStoreAttributes.put(FileKeyStore.PASSWORD, keystorePassword);
+ if (certAlias != null)
+ {
+ keyStoreAttributes.put(FileKeyStore.CERTIFICATE_ALIAS, certAlias);
+ }
- int responseCode = getRestTestHelper().submitRequest("keystore/" + name, "PUT", keyStoreAttributes);
- assertEquals("Unexpected response code", 201, responseCode);
+ getRestTestHelper().submitRequest("keystore/" + name, "PUT", keyStoreAttributes, HttpServletResponse.SC_CREATED);
}
private void assertKeyStoreAttributes(Map<String, Object> keystore, String name, String path, String certAlias)
@@ -261,12 +171,16 @@ public class KeyStoreRestTest extends QpidRestTestCase
AbstractConfiguredObject.SECURED_STRING_VALUE, keystore.get(FileKeyStore.PASSWORD));
assertEquals("unexpected type of default systests key store",
java.security.KeyStore.getDefaultType(), keystore.get(FileKeyStore.KEY_STORE_TYPE));
- assertEquals("unexpected certificateAlias value",
- certAlias, keystore.get(FileKeyStore.CERTIFICATE_ALIAS));
if(certAlias == null)
{
assertFalse("should not be a certificateAlias attribute",
keystore.containsKey(FileKeyStore.CERTIFICATE_ALIAS));
}
+ else
+ {
+ assertEquals("unexpected certificateAlias value",
+ certAlias, keystore.get(FileKeyStore.CERTIFICATE_ALIAS));
+
+ }
}
}
diff --git a/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/TrustStoreRestTest.java b/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/TrustStoreRestTest.java
index 1aac22d0aa..6cca3fc12c 100644
--- a/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/TrustStoreRestTest.java
+++ b/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/TrustStoreRestTest.java
@@ -20,23 +20,19 @@
*/
package org.apache.qpid.systest.rest;
-import java.io.IOException;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.codehaus.jackson.JsonGenerationException;
-import org.codehaus.jackson.JsonParseException;
-import org.codehaus.jackson.map.JsonMappingException;
+import javax.servlet.http.HttpServletResponse;
import org.apache.qpid.server.model.AbstractConfiguredObject;
-import org.apache.qpid.server.model.Port;
-import org.apache.qpid.server.model.Transport;
import org.apache.qpid.server.model.TrustStore;
import org.apache.qpid.server.security.FileTrustStore;
import org.apache.qpid.test.utils.TestBrokerConfiguration;
import org.apache.qpid.test.utils.TestSSLConstants;
+import org.apache.qpid.util.DataUrlUtils;
+import org.apache.qpid.util.FileUtils;
public class TrustStoreRestTest extends QpidRestTestCase
{
@@ -66,7 +62,7 @@ public class TrustStoreRestTest extends QpidRestTestCase
String name = getTestName();
assertNumberOfTrustStores(1);
- createTrustStore(name, true);
+ createTrustStore(name, true, TestSSLConstants.TRUSTSTORE, TestSSLConstants.TRUSTSTORE_PASSWORD);
assertNumberOfTrustStores(2);
List<Map<String, Object>> trustStores = getRestTestHelper().getJsonAsList("truststore/" + name);
@@ -75,157 +71,73 @@ public class TrustStoreRestTest extends QpidRestTestCase
assertTrustStoreAttributes(trustStores.get(0), name, TestSSLConstants.TRUSTSTORE, true);
}
- public void testDelete() throws Exception
+ public void testCreateUsingDataUrl() throws Exception
{
super.setUp();
String name = getTestName();
+ byte[] trustStoreAsBytes = FileUtils.readFileAsBytes(TestSSLConstants.TRUSTSTORE);
+ String dataUrlForTruststore = DataUrlUtils.getDataUrlForBytes(trustStoreAsBytes);
assertNumberOfTrustStores(1);
- createTrustStore(name, false);
- assertNumberOfTrustStores(2);
-
- int responseCode = getRestTestHelper().submitRequest("truststore/" + name , "DELETE");
- assertEquals("Unexpected response code for provider deletion", 200, responseCode);
-
- List<Map<String, Object>> trustStore = getRestTestHelper().getJsonAsList("truststore/" + name);
- assertNotNull("details should not be null", trustStore);
- assertTrue("details should be empty as the truststore no longer exists", trustStore.isEmpty());
-
- //check only the default systests trust store remains
- List<Map<String, Object>> trustStores = assertNumberOfTrustStores(1);
- Map<String, Object> truststore = trustStores.get(0);
- assertTrustStoreAttributes(truststore, TestBrokerConfiguration.ENTRY_NAME_SSL_TRUSTSTORE,
- QPID_HOME + "/../" + TestSSLConstants.BROKER_TRUSTSTORE, false);
- }
- public void testDeleteFailsWhenTrustStoreInUse() throws Exception
- {
- String name = "testDeleteFailsWhenTrustStoreInUse";
-
- //add a new trust store config to use
- Map<String, Object> sslTrustStoreAttributes = new HashMap<String, Object>();
- sslTrustStoreAttributes.put(TrustStore.NAME, name);
- sslTrustStoreAttributes.put(FileTrustStore.PATH, TestSSLConstants.TRUSTSTORE);
- sslTrustStoreAttributes.put(FileTrustStore.PASSWORD, TestSSLConstants.TRUSTSTORE_PASSWORD);
- getBrokerConfiguration().addObjectConfiguration(TrustStore.class,sslTrustStoreAttributes);
-
- //add the SSL port using it
- Map<String, Object> sslPortAttributes = new HashMap<String, Object>();
- sslPortAttributes.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL));
- sslPortAttributes.put(Port.PORT, DEFAULT_SSL_PORT);
- sslPortAttributes.put(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_SSL_PORT);
- sslPortAttributes.put(Port.AUTHENTICATION_PROVIDER, TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER);
- sslPortAttributes.put(Port.KEY_STORE, TestBrokerConfiguration.ENTRY_NAME_SSL_KEYSTORE);
- sslPortAttributes.put(Port.TRUST_STORES, Collections.singleton(name));
- getBrokerConfiguration().addObjectConfiguration(Port.class, sslPortAttributes);
+ createTrustStore(name, false, dataUrlForTruststore, TestSSLConstants.TRUSTSTORE_PASSWORD);
- super.setUp();
-
- //verify the truststore is there
assertNumberOfTrustStores(2);
- List<Map<String, Object>> trustStore = getRestTestHelper().getJsonAsList("truststore/" + name);
- assertNotNull("details should not be null", trustStore);
- assertTrustStoreAttributes(trustStore.get(0), name, TestSSLConstants.TRUSTSTORE, false);
-
- //try to delete it, which should fail as it is in use
- int responseCode = getRestTestHelper().submitRequest("truststore/" + name , "DELETE");
- assertEquals("Unexpected response code for provider deletion", 409, responseCode);
+ List<Map<String, Object>> trustStores = getRestTestHelper().getJsonAsList("truststore/" + name);
+ assertNotNull("details cannot be null", trustStores);
- //check its still there
- assertNumberOfTrustStores(2);
- trustStore = getRestTestHelper().getJsonAsList("truststore/" + name);
- assertNotNull("details should not be null", trustStore);
- assertTrustStoreAttributes(trustStore.get(0), name, TestSSLConstants.TRUSTSTORE, false);
+ assertTrustStoreAttributes(trustStores.get(0), name, dataUrlForTruststore, false);
}
- public void testUpdateWithGoodPathSucceeds() throws Exception
+ public void testDelete() throws Exception
{
super.setUp();
String name = getTestName();
assertNumberOfTrustStores(1);
- createTrustStore(name, false);
+ createTrustStore(name, false, TestSSLConstants.TRUSTSTORE, TestSSLConstants.TRUSTSTORE_PASSWORD);
assertNumberOfTrustStores(2);
- Map<String, Object> attributes = new HashMap<String, Object>();
- attributes.put(TrustStore.NAME, name);
- attributes.put(FileTrustStore.PATH, TestSSLConstants.TRUSTSTORE);
-
- int responseCode = getRestTestHelper().submitRequest("truststore/" + name , "PUT", attributes);
- assertEquals("Unexpected response code for truststore update", 200, responseCode);
+ getRestTestHelper().submitRequest("truststore/" + name , "DELETE", HttpServletResponse.SC_OK);
List<Map<String, Object>> trustStore = getRestTestHelper().getJsonAsList("truststore/" + name);
assertNotNull("details should not be null", trustStore);
+ assertTrue("details should be empty as the truststore no longer exists", trustStore.isEmpty());
- assertTrustStoreAttributes(trustStore.get(0), name, TestSSLConstants.TRUSTSTORE, false);
+ //check only the default systests trust store remains
+ List<Map<String, Object>> trustStores = assertNumberOfTrustStores(1);
+ Map<String, Object> truststore = trustStores.get(0);
+ assertTrustStoreAttributes(truststore, TestBrokerConfiguration.ENTRY_NAME_SSL_TRUSTSTORE,
+ QPID_HOME + "/../" + TestSSLConstants.BROKER_TRUSTSTORE, false);
}
- public void testUpdateWithNonExistentPathFails() throws Exception
- {
- super.setUp();
-
- String name = getTestName();
-
- assertNumberOfTrustStores(1);
- createTrustStore(name, false);
- assertNumberOfTrustStores(2);
- Map<String, Object> attributes = new HashMap<String, Object>();
- attributes.put(TrustStore.NAME, name);
- attributes.put(FileTrustStore.PATH, "does.not.exist");
-
- int responseCode = getRestTestHelper().submitRequest("truststore/" + name , "PUT", attributes);
- assertEquals("Unexpected response code for trust store update", 409, responseCode);
-
- List<Map<String, Object>> trustStore = getRestTestHelper().getJsonAsList("truststore/" + name);
- assertNotNull("details should not be null", trustStore);
-
- //verify the details remain unchanged
- assertTrustStoreAttributes(trustStore.get(0), name, TestSSLConstants.TRUSTSTORE, false);
- }
-
- public void testUpdatePeersOnly() throws Exception
+ public void testUpdate() throws Exception
{
super.setUp();
String name = getTestName();
assertNumberOfTrustStores(1);
- createTrustStore(name, false);
+ createTrustStore(name, false, TestSSLConstants.TRUSTSTORE, TestSSLConstants.TRUSTSTORE_PASSWORD);
assertNumberOfTrustStores(2);
- //update the peersOnly attribute from false to true
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put(TrustStore.NAME, name);
- attributes.put(FileTrustStore.PEERS_ONLY, true);
+ attributes.put(FileTrustStore.PATH, TestSSLConstants.TRUSTSTORE);
- int responseCode = getRestTestHelper().submitRequest("truststore/" + name , "PUT", attributes);
- assertEquals("Unexpected response code for trust store update", 200, responseCode);
+ getRestTestHelper().submitRequest("truststore/" + name , "PUT", attributes, HttpServletResponse.SC_OK);
List<Map<String, Object>> trustStore = getRestTestHelper().getJsonAsList("truststore/" + name);
assertNotNull("details should not be null", trustStore);
- assertTrustStoreAttributes(trustStore.get(0), name, TestSSLConstants.TRUSTSTORE, true);
-
- //Update peersOnly to clear it (i.e go from from true to null, which will default to false)
- attributes = new HashMap<String, Object>();
- attributes.put(TrustStore.NAME, name);
- attributes.put(FileTrustStore.PEERS_ONLY, null);
-
- responseCode = getRestTestHelper().submitRequest("truststore/" + name , "PUT", attributes);
- assertEquals("Unexpected response code for trust store update", 200, responseCode);
-
- trustStore = getRestTestHelper().getJsonAsList("truststore/" + name);
- assertNotNull("details should not be null", trustStore);
-
assertTrustStoreAttributes(trustStore.get(0), name, TestSSLConstants.TRUSTSTORE, false);
}
- private List<Map<String, Object>> assertNumberOfTrustStores(int numberOfTrustStores) throws IOException,
- JsonParseException, JsonMappingException
+ private List<Map<String, Object>> assertNumberOfTrustStores(int numberOfTrustStores) throws Exception
{
List<Map<String, Object>> trustStores = getRestTestHelper().getJsonAsList("truststore");
assertNotNull("trust stores should not be null", trustStores);
@@ -234,17 +146,16 @@ public class TrustStoreRestTest extends QpidRestTestCase
return trustStores;
}
- private void createTrustStore(String name, boolean peersOnly) throws IOException, JsonGenerationException, JsonMappingException
+ private void createTrustStore(String name, boolean peersOnly, final String truststorePath, final String truststorePassword) throws Exception
{
Map<String, Object> trustStoreAttributes = new HashMap<String, Object>();
trustStoreAttributes.put(TrustStore.NAME, name);
//deliberately using the client trust store to differentiate from the one we are already for broker
- trustStoreAttributes.put(FileTrustStore.PATH, TestSSLConstants.TRUSTSTORE);
- trustStoreAttributes.put(FileTrustStore.PASSWORD, TestSSLConstants.TRUSTSTORE_PASSWORD);
+ trustStoreAttributes.put(FileTrustStore.PATH, truststorePath);
+ trustStoreAttributes.put(FileTrustStore.PASSWORD, truststorePassword);
trustStoreAttributes.put(FileTrustStore.PEERS_ONLY, peersOnly);
- int responseCode = getRestTestHelper().submitRequest("truststore/" + name, "PUT", trustStoreAttributes);
- assertEquals("Unexpected response code", 201, responseCode);
+ getRestTestHelper().submitRequest("truststore/" + name, "PUT", trustStoreAttributes, HttpServletResponse.SC_CREATED);
}
private void assertTrustStoreAttributes(Map<String, Object> truststore, String name, String path, boolean peersOnly)