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)));
}
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
}
}
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@"));
}
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;
}
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);
}
}
Aggregations