use of org.apache.qpid.tests.http.HttpTestHelper in project qpid-broker-j by apache.
the class HttpPortTest method portDeletion.
@Test
public void portDeletion() throws Exception {
final String portName = getTestName();
final String authenticationProvider = portName + "AuthenticationProvider";
createAnonymousAuthenticationProvider(authenticationProvider);
createPort(portName, authenticationProvider);
String portUrl = "port/" + portName;
Map<String, Object> attributes = getHelper().getJsonAsMap(portUrl);
assertTrue(attributes.containsKey("boundPort"));
assertTrue(attributes.get("boundPort") instanceof Number);
HttpTestHelper helper = new HttpTestHelper(getBrokerAdmin(), null, ((Number) attributes.get("boundPort")).intValue());
try {
helper.submitRequest("port/" + portName, "DELETE", SC_OK);
} catch (ConnectException e) {
// Extra logging to investigate unexpected exception
LOGGER.debug("Unexpected connection exception", e);
Assert.fail("Unexpected exception " + e.getMessage());
}
}
use of org.apache.qpid.tests.http.HttpTestHelper in project qpid-broker-j by apache.
the class PreemptiveAuthenticationTest method configForClientAuth.
private HttpTestHelper configForClientAuth(final String x500Name) throws Exception {
final KeyCertificatePair clientKeyCertPair = getKeyCertPair(x500Name);
final byte[] clientCertificate = clientKeyCertPair.getCertificate().getEncoded();
final String clientKeyStore = createKeyStoreDataUrl(clientKeyCertPair);
final KeyCertificatePair brokerKeyCertPair = getKeyCertPair(x500Name);
final String brokerKeyStore = createKeyStoreDataUrl(brokerKeyCertPair);
final Deque<BaseAction<Void, Exception>> deleteActions = new ArrayDeque<>();
final Map<String, Object> authAttr = new HashMap<>();
authAttr.put(ExternalAuthenticationManager.TYPE, "External");
authAttr.put(ExternalAuthenticationManager.ATTRIBUTE_USE_FULL_DN, false);
getHelper().submitRequest("authenticationprovider/myexternal", "PUT", authAttr, SC_CREATED);
deleteActions.add(object -> getHelper().submitRequest("authenticationprovider/myexternal", "DELETE", SC_OK));
final Map<String, Object> keystoreAttr = new HashMap<>();
keystoreAttr.put(FileKeyStore.TYPE, "FileKeyStore");
keystoreAttr.put(FileKeyStore.STORE_URL, brokerKeyStore);
keystoreAttr.put(FileKeyStore.PASSWORD, STORE_PASSWORD);
keystoreAttr.put(FileKeyStore.KEY_STORE_TYPE, KeyStore.getDefaultType());
getHelper().submitRequest("keystore/mykeystore", "PUT", keystoreAttr, SC_CREATED);
deleteActions.add(object -> getHelper().submitRequest("keystore/mykeystore", "DELETE", SC_OK));
final Map<String, Object> truststoreAttr = new HashMap<>();
truststoreAttr.put(ManagedPeerCertificateTrustStore.TYPE, ManagedPeerCertificateTrustStore.TYPE_NAME);
truststoreAttr.put(ManagedPeerCertificateTrustStore.STORED_CERTIFICATES, Collections.singletonList(Base64.getEncoder().encodeToString(clientCertificate)));
getHelper().submitRequest("truststore/mytruststore", "PUT", truststoreAttr, SC_CREATED);
deleteActions.add(object -> getHelper().submitRequest("truststore/mytruststore", "DELETE", SC_OK));
final Map<String, Object> portAttr = new HashMap<>();
portAttr.put(Port.TYPE, "HTTP");
portAttr.put(Port.PORT, 0);
portAttr.put(Port.AUTHENTICATION_PROVIDER, "myexternal");
portAttr.put(Port.PROTOCOLS, Collections.singleton(Protocol.HTTP));
portAttr.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL));
portAttr.put(Port.NEED_CLIENT_AUTH, true);
portAttr.put(Port.KEY_STORE, "mykeystore");
portAttr.put(Port.TRUST_STORES, Collections.singletonList("mytruststore"));
getHelper().submitRequest("port/myport", "PUT", portAttr, SC_CREATED);
deleteActions.add(object -> getHelper().submitRequest("port/myport", "DELETE", SC_OK));
Map<String, Object> clientAuthPort = getHelper().getJsonAsMap("port/myport");
int boundPort = Integer.parseInt(String.valueOf(clientAuthPort.get("boundPort")));
assertThat(boundPort, is(greaterThan(0)));
_tearDownActions = deleteActions;
HttpTestHelper helper = new HttpTestHelper(getBrokerAdmin(), null, boundPort);
helper.setTls(true);
helper.setKeyStore(clientKeyStore, STORE_PASSWORD);
return helper;
}
use of org.apache.qpid.tests.http.HttpTestHelper in project qpid-broker-j by apache.
the class HttpPortTest method createdPortAcceptsConnections.
@Test
public void createdPortAcceptsConnections() throws Exception {
final String portName = getTestName();
final String authenticationProvider = portName + "AuthenticationProvider";
createAnonymousAuthenticationProvider(authenticationProvider);
createPort(portName, authenticationProvider);
String portUrl = "port/" + portName;
Map<String, Object> attributes = getHelper().getJsonAsMap(portUrl);
assertTrue(attributes.containsKey("boundPort"));
assertTrue(attributes.get("boundPort") instanceof Number);
HttpTestHelper helper = new HttpTestHelper(getBrokerAdmin(), null, ((Number) attributes.get("boundPort")).intValue());
Map<String, Object> ownAttributes = helper.getJsonAsMap(portUrl);
assertEquals(attributes, ownAttributes);
}
use of org.apache.qpid.tests.http.HttpTestHelper in project qpid-broker-j by apache.
the class OperationTest method invokeOperationReturningVoid.
@Test
public void invokeOperationReturningVoid() throws Exception {
final HttpTestHelper brokerHelper = new HttpTestHelper(getBrokerAdmin());
final Void response = brokerHelper.postJson("broker/performGC", Collections.emptyMap(), new TypeReference<Void>() {
}, SC_OK);
assertThat(response, is(nullValue()));
}
use of org.apache.qpid.tests.http.HttpTestHelper in project qpid-broker-j by apache.
the class OperationTest method invokeOperationWithReservedParameter.
@Test
public void invokeOperationWithReservedParameter() throws Exception {
final HttpTestHelper brokerHelper = new HttpTestHelper(getBrokerAdmin());
final byte[] response = brokerHelper.getBytes("broker/getThreadStackTraces?contentDispositionAttachmentFilename=stack-traces.txt&appendToLog=false");
assertThat(response, is(notNullValue()));
assertThat(new String(response, UTF_8).contains("Full thread dump captured"), is(equalTo(true)));
}
Aggregations