Search in sources :

Example 1 with HttpTestHelper

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

the class PreemptiveAuthenticationTest method clientAuthenticationWebManagementConsole.

@Test
public void clientAuthenticationWebManagementConsole() throws Exception {
    HttpTestHelper helper = configForClientAuth("CN=foo");
    HttpURLConnection authenticateConnection = helper.openManagementConnection(HttpManagement.DEFAULT_LOGIN_URL, "GET");
    authenticateConnection.setInstanceFollowRedirects(false);
    int status = authenticateConnection.getResponseCode();
    final String cookies = authenticateConnection.getHeaderField("Set-Cookie");
    authenticateConnection.disconnect();
    assertThat(status, is(equalTo(HttpURLConnection.HTTP_MOVED_TEMP)));
    authenticateConnection = helper.openManagementConnection(HttpManagement.DEFAULT_LOGIN_URL, "GET");
    authenticateConnection.setRequestProperty("Cookie", cookies);
    status = authenticateConnection.getResponseCode();
    authenticateConnection.disconnect();
    assertThat(status, is(equalTo(HttpURLConnection.HTTP_OK)));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) HttpTestHelper(org.apache.qpid.tests.http.HttpTestHelper) Test(org.junit.Test)

Example 2 with HttpTestHelper

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

the class PreemptiveAuthenticationTest method clientAuthUnrecognisedCert.

@Test
public void clientAuthUnrecognisedCert() throws Exception {
    HttpTestHelper helper = configForClientAuth("CN=foo");
    String keyStore = createKeyStoreDataUrl(getKeyCertPair("CN=bar"));
    helper.setKeyStore(keyStore, STORE_PASSWORD);
    try {
        helper.getJson("broker/getUser", STRING_TYPE_REF, SC_OK);
        fail("Exception not thrown");
    } catch (IOException e) {
    // PASS
    }
}
Also used : HttpTestHelper(org.apache.qpid.tests.http.HttpTestHelper) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with HttpTestHelper

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

the class PreemptiveAuthenticationTest method clientAuthSuccess.

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

Example 4 with HttpTestHelper

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

the class PreemptiveAuthenticationTest method configForAnonymous.

private HttpTestHelper configForAnonymous() throws Exception {
    final Deque<BaseAction<Void, Exception>> deleteActions = new ArrayDeque<>();
    final Map<String, Object> authAttr = new HashMap<>();
    authAttr.put(AnonymousAuthenticationManager.TYPE, AnonymousAuthenticationManager.PROVIDER_TYPE);
    getHelper().submitRequest("authenticationprovider/myanon", "PUT", authAttr, SC_CREATED);
    deleteActions.add(object -> getHelper().submitRequest("authenticationprovider/myanon", "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, "myanon");
    portAttr.put(Port.PROTOCOLS, Collections.singleton(Protocol.HTTP));
    portAttr.put(Port.TRANSPORTS, Collections.singleton(Transport.TCP));
    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.setPassword(null);
    helper.setUserName(null);
    return helper;
}
Also used : HashMap(java.util.HashMap) HttpTestHelper(org.apache.qpid.tests.http.HttpTestHelper) BaseAction(org.apache.qpid.server.util.BaseAction) ArrayDeque(java.util.ArrayDeque)

Example 5 with HttpTestHelper

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

the class PreemptiveAuthenticationTest method doBasicAuthDisabledTest.

private void doBasicAuthDisabledTest(final boolean tls) throws Exception {
    HttpTestHelper configHelper = new HttpTestHelper(getBrokerAdmin());
    configHelper.setTls(!tls);
    final String authEnabledAttrName = tls ? HttpManagement.HTTPS_BASIC_AUTHENTICATION_ENABLED : HttpManagement.HTTP_BASIC_AUTHENTICATION_ENABLED;
    try {
        HttpTestHelper helper = new HttpTestHelper(getBrokerAdmin());
        helper.setTls(tls);
        assertThat(helper.submitRequest("broker", "GET"), is(equalTo(SC_OK)));
        configHelper.submitRequest("plugin/httpManagement", "POST", Collections.<String, Object>singletonMap(authEnabledAttrName, Boolean.FALSE), SC_OK);
        assertThat(helper.submitRequest("broker", "GET"), is(equalTo(SC_UNAUTHORIZED)));
    } finally {
        configHelper.submitRequest("plugin/httpManagement", "POST", Collections.<String, Object>singletonMap(authEnabledAttrName, Boolean.TRUE), SC_OK);
    }
}
Also used : HttpTestHelper(org.apache.qpid.tests.http.HttpTestHelper)

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