Search in sources :

Example 6 with HttpTestHelper

use of org.apache.qpid.tests.http.HttpTestHelper in project qpid-broker-j by apache.

the class PreemptiveAuthenticationTest method anonymousTest.

@Test
public void anonymousTest() throws Exception {
    HttpTestHelper helper = configForAnonymous();
    String userId = helper.getJson("broker/getUser", STRING_TYPE_REF, SC_OK);
    assertThat(userId, startsWith("ANONYMOUS@"));
}
Also used : HttpTestHelper(org.apache.qpid.tests.http.HttpTestHelper) Test(org.junit.Test)

Example 7 with HttpTestHelper

use of org.apache.qpid.tests.http.HttpTestHelper in project qpid-broker-j by apache.

the class StatisticsReportingTest method virtualHostConnectionStatistics.

@Test
public void virtualHostConnectionStatistics() throws Exception {
    String hostLogDownloadUrl = configureLogger(true);
    HttpTestHelper brokerHelper = new HttpTestHelper(getBrokerAdmin());
    Connection conn = getConnection();
    try {
        final Map<String, String> args = new HashMap<>();
        args.put("name", "qpid.connection.statisticsReportPattern");
        args.put("value", "${ancestor:connection:principal}: messagesIn=${messagesIn}, lastIoTime=${lastIoTime:datetime}");
        brokerHelper.submitRequest("broker/setContextVariable", "POST", args, SC_OK);
        getBrokerAdmin().createQueue(QUEUE1_NAME);
        Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
        // Enable Virtual Host Statistics Reporting
        final Map<String, Object> arguments = new HashMap<>();
        arguments.put(QueueManagingVirtualHost.STATISTICS_REPORTING_PERIOD, STATISTICS_REPORTING_PERIOD_IN_SEC);
        Map<String, String> context = singletonMap("qpid.connection.statisticsReportPattern", "${ancestor:connection:principal}: " + "messagesIn=${messagesIn}, " + "lastIoTime=${lastIoTime:datetime}");
        arguments.put(ConfiguredObject.CONTEXT, context);
        getHelper().submitRequest("virtualhost", "POST", arguments, SC_OK);
        assertThat("Pre-enqueue connection statistics report not found", countLogFileMatches(hostLogDownloadUrl, String.format("%s: messagesIn=0", getBrokerAdmin().getValidUsername()), LOG_TIMEOUT_IN_MS), is(greaterThan(0)));
        // Enqueue a single message to queue 1
        Utils.sendMessages(session, session.createQueue(QUEUE1_NAME), 1);
        assertThat("Post-enqueue connection statistics report not found", countLogFileMatches(hostLogDownloadUrl, String.format("%s: messagesIn=1", getBrokerAdmin().getValidUsername()), LOG_TIMEOUT_IN_MS), is(greaterThan(0)));
    } finally {
        brokerHelper.submitRequest("broker/removeContextVariable", "POST", singletonMap("name", "qpid.connection.statisticsReportPattern"), SC_OK);
        conn.close();
    }
}
Also used : HashMap(java.util.HashMap) HttpTestHelper(org.apache.qpid.tests.http.HttpTestHelper) HttpURLConnection(java.net.HttpURLConnection) Connection(javax.jms.Connection) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Session(javax.jms.Session) Test(org.junit.Test)

Example 8 with HttpTestHelper

use of org.apache.qpid.tests.http.HttpTestHelper in project qpid-broker-j by apache.

the class BrokerMetricsAuthenticationTest method testBrokerMetricsForUnauthenticatedUser.

@Test
public void testBrokerMetricsForUnauthenticatedUser() throws Exception {
    final HttpTestHelper helper = new HttpTestHelper(getBrokerAdmin(), null);
    helper.setUserName(null);
    helper.setPassword(null);
    helper.submitRequest("/metrics", "GET", HttpServletResponse.SC_UNAUTHORIZED);
}
Also used : HttpTestHelper(org.apache.qpid.tests.http.HttpTestHelper) Test(org.junit.Test)

Example 9 with HttpTestHelper

use of org.apache.qpid.tests.http.HttpTestHelper in project qpid-broker-j by apache.

the class UnifiedPortTest method doTestSlowConnect.

private void doTestSlowConnect(final boolean useTls) throws Exception {
    final int port = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.HTTP).getPort();
    try (TCPTunneler tunneler = new TCPTunneler(0, "localhost", port, 1, 2)) {
        // Hopes to exercise the code path where too few bytes arrive with Jetty for it to make an PLAIN/TLS
        // determination and needs to await more bytes.
        tunneler.addClientListener(new PreambleDelayingListener());
        tunneler.start();
        HttpTestHelper _restTestHelper = new HttpTestHelper(getBrokerAdmin(), null, tunneler.getLocalPort());
        _restTestHelper.setTls(useTls);
        Map<String, Object> metadata = _restTestHelper.getJsonAsMap("broker/getConnectionMetaData");
        String transport = String.valueOf(metadata.get("transport"));
        final String expected = useTls ? "SSL" : "TCP";
        assertThat("Unexpected protocol", transport, CoreMatchers.is(equalTo(expected)));
    }
}
Also used : TCPTunneler(org.apache.qpid.test.utils.TCPTunneler) HttpTestHelper(org.apache.qpid.tests.http.HttpTestHelper)

Example 10 with HttpTestHelper

use of org.apache.qpid.tests.http.HttpTestHelper in project qpid-broker-j by apache.

the class StructureTest method testGet.

@SuppressWarnings("unchecked")
@Test
public void testGet() throws Exception {
    String nodeName = getVirtualHostNode();
    String hostName = getVirtualHost();
    HttpTestHelper helper = getHelper();
    Map<String, Object> structure = helper.getJsonAsMap("/service/structure");
    assertNotNull("Structure data cannot be null", structure);
    assertEquals("Unexpected name", "Broker", structure.get("name"));
    assertNotNull("Unexpected id", structure.get("id"));
    List<Map<String, Object>> virtualhostnodes = (List<Map<String, Object>>) structure.get("virtualhostnodes");
    assertNotNull("Virtual host nodes not present", virtualhostnodes);
    Map<String, Object> testNode = assertPresent(nodeName, virtualhostnodes);
    List<Map<String, Object>> virtualhosts = (List<Map<String, Object>>) testNode.get("virtualhosts");
    assertNotNull("Virtual host not present", virtualhosts);
    assertEquals(String.format("VH %s not found", hostName), 1, virtualhosts.size());
    Map<String, Object> testHost = assertPresent(hostName, virtualhosts);
    List<Map<String, Object>> exchanges = (List<Map<String, Object>>) testHost.get("exchanges");
    assertNotNull("Exchanges not present", exchanges);
    assertPresent("Exchange amq.direct is not found", "amq.direct", exchanges);
    assertPresent("Exchange amq.topic is not found", "amq.topic", exchanges);
    assertPresent("Exchange amq.fanout is not found", "amq.fanout", exchanges);
    assertPresent("Exchange amq.match is not found", "amq.match", exchanges);
    List<Map<String, Object>> queues = (List<Map<String, Object>>) testHost.get("queues");
    assertNull("Unexpected queues", queues);
    List<Map<String, Object>> ports = (List<Map<String, Object>>) structure.get("ports");
    assertNotNull("Ports not present", ports);
    Map<String, Object> amqpPort = assertPresent("AMQP", ports);
    assertNotNull("Port AMQP is not found", amqpPort);
    assertPresent("Port ANONYMOUS_AMQP is not found", "ANONYMOUS_AMQP", ports);
    assertPresent("Port HTTP is not found", "HTTP", ports);
    List<Map<String, Object>> aliases = (List<Map<String, Object>>) amqpPort.get("virtualhostaliases");
    assertNotNull("Virtual host aliases not found", aliases);
    assertPresent("Alias defaultAlias is not found", "defaultAlias", aliases);
    assertPresent("Alias hostnameAlias is not found", "hostnameAlias", aliases);
    assertPresent("Alias nameAlias is not found", "nameAlias", aliases);
    List<Map<String, Object>> providers = (List<Map<String, Object>>) structure.get("authenticationproviders");
    assertNotNull("Authentication providers not present", providers);
    assertPresent("Authentication provider 'anon' is not found", "anon", providers);
    assertPresent("Authentication provider 'plain' is not found", "plain", providers);
    Map<String, Object> plainProvider = assertPresent("plain", providers);
    List<Map<String, Object>> users = (List<Map<String, Object>>) plainProvider.get("users");
    assertNotNull("Authentication provider users not present", users);
    assertPresent("User 'admin' not found", "admin", users);
    assertPresent("User 'guest' not found", "guest", users);
    List<Map<String, Object>> keystores = (List<Map<String, Object>>) structure.get("keystores");
    assertNotNull("Key stores not present", keystores);
    assertPresent("systestsKeyStore not found", "systestsKeyStore", keystores);
    List<Map<String, Object>> plugins = (List<Map<String, Object>>) structure.get("plugins");
    assertNotNull("Plugins not present", plugins);
    assertPresent("httpManagement not found", "httpManagement", plugins);
    String queueName = getTestName() + "Queue";
    helper.submitRequest(String.format("queue/%s/%s/%s", nodeName, hostName, queueName), "PUT", Collections.singletonMap("name", queueName));
    structure = helper.getJsonAsMap("/service/structure");
    virtualhostnodes = (List<Map<String, Object>>) structure.get("virtualhostnodes");
    assertNotNull("Virtual host nodes not present", virtualhostnodes);
    testNode = assertPresent(hostName, virtualhostnodes);
    virtualhosts = (List<Map<String, Object>>) testNode.get("virtualhosts");
    assertNotNull("Virtual host not present", virtualhosts);
    assertEquals(String.format("VH %s not found", hostName), 1, virtualhosts.size());
    testHost = assertPresent(hostName, virtualhosts);
    queues = (List<Map<String, Object>>) testHost.get("queues");
    assertNotNull("Queues not present", queues);
    assertPresent(String.format("Queue %s not found", queueName), queueName, queues);
}
Also used : HttpTestHelper(org.apache.qpid.tests.http.HttpTestHelper) List(java.util.List) Map(java.util.Map) 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