Search in sources :

Example 11 with HttpTestHelper

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());
    }
}
Also used : HttpTestHelper(org.apache.qpid.tests.http.HttpTestHelper) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConnectException(java.net.ConnectException) Test(org.junit.Test)

Example 12 with HttpTestHelper

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;
}
Also used : KeyCertificatePair(org.apache.qpid.test.utils.tls.KeyCertificatePair) HashMap(java.util.HashMap) HttpTestHelper(org.apache.qpid.tests.http.HttpTestHelper) BaseAction(org.apache.qpid.server.util.BaseAction) ArrayDeque(java.util.ArrayDeque)

Example 13 with HttpTestHelper

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);
}
Also used : HttpTestHelper(org.apache.qpid.tests.http.HttpTestHelper) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Test(org.junit.Test)

Example 14 with HttpTestHelper

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()));
}
Also used : HttpTestHelper(org.apache.qpid.tests.http.HttpTestHelper) Test(org.junit.Test)

Example 15 with HttpTestHelper

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)));
}
Also used : HttpTestHelper(org.apache.qpid.tests.http.HttpTestHelper) Test(org.junit.Test)

Aggregations

HttpTestHelper (org.apache.qpid.tests.http.HttpTestHelper)16 Test (org.junit.Test)12 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)4 HashMap (java.util.HashMap)3 HttpURLConnection (java.net.HttpURLConnection)2 ArrayDeque (java.util.ArrayDeque)2 BaseAction (org.apache.qpid.server.util.BaseAction)2 File (java.io.File)1 IOException (java.io.IOException)1 ConnectException (java.net.ConnectException)1 List (java.util.List)1 Map (java.util.Map)1 Connection (javax.jms.Connection)1 Session (javax.jms.Session)1 TCPTunneler (org.apache.qpid.test.utils.TCPTunneler)1 KeyCertificatePair (org.apache.qpid.test.utils.tls.KeyCertificatePair)1