use of io.apiman.gateway.engine.IApiConnection in project apiman by apiman.
the class CipherAndProtocolSelectionTest method shouldFailWhenRemoteCiphersAreExcluded.
/**
* Scenario:
* - Only allowed protocol is one that is disallowed by remote end
* @throws Exception any exception
*/
@Test
public void shouldFailWhenRemoteCiphersAreExcluded() throws Exception {
String preferredCipher = getPrefferedCipher();
config.put(TLSOptions.TLS_TRUSTSTORE, getResourcePath("2waytest/mutual_trust_via_ca/common_ts.jks"));
config.put(TLSOptions.TLS_TRUSTSTOREPASSWORD, "changeme");
config.put(TLSOptions.TLS_ALLOWANYHOST, "true");
config.put(TLSOptions.TLS_ALLOWSELFSIGNED, "false");
config.put(TLSOptions.TLS_DISALLOWEDCIPHERS, preferredCipher);
jettySslContextFactory.setIncludeCipherSuites(preferredCipher);
server.start();
HttpConnectorFactory factory = new HttpConnectorFactory(config);
IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.DEFAULT, false, new ConnectorConfigImpl());
IApiConnection connection = connector.connect(request, new IAsyncResultHandler<IApiConnectionResponse>() {
@Override
public void handle(IAsyncResult<IApiConnectionResponse> result) {
Assert.assertTrue(result.isError());
System.out.println(result.getError());
Assert.assertTrue(result.getError().getCause() instanceof javax.net.ssl.SSLHandshakeException);
}
});
connection.end();
}
use of io.apiman.gateway.engine.IApiConnection in project apiman by apiman.
the class CipherAndProtocolSelectionTest method shouldFailWhenNoValidProtocolAllowed.
/**
* Scenario:
* - Only allowed cipher is one that is disallowed by remote end
* @throws Exception any exception
*/
@Test
public void shouldFailWhenNoValidProtocolAllowed() throws Exception {
config.put(TLSOptions.TLS_TRUSTSTORE, getResourcePath("2waytest/mutual_trust_via_ca/common_ts.jks"));
config.put(TLSOptions.TLS_TRUSTSTOREPASSWORD, "changeme");
config.put(TLSOptions.TLS_ALLOWANYHOST, "true");
config.put(TLSOptions.TLS_ALLOWSELFSIGNED, "false");
config.put(TLSOptions.TLS_ALLOWEDPROTOCOLS, "SSLv3");
jettySslContextFactory.setExcludeProtocols("SSLv3");
server.start();
HttpConnectorFactory factory = new HttpConnectorFactory(config);
IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.DEFAULT, false, new ConnectorConfigImpl());
IApiConnection connection = connector.connect(request, new IAsyncResultHandler<IApiConnectionResponse>() {
@Override
public void handle(IAsyncResult<IApiConnectionResponse> result) {
Assert.assertTrue(result.isError());
System.out.println(result.getError());
// result.getError().printStackTrace();
Assert.assertTrue(result.getError().getCause() instanceof java.net.UnknownServiceException);
}
});
connection.end();
}
use of io.apiman.gateway.engine.IApiConnection in project apiman by apiman.
the class StandardTLSTest method shouldFailWithNoSettings.
/**
* Scenario:
* - No settings whatsoever.
* - Will fail, as defaults are relatively safe,
* and API certificate will not be recognised.
*/
@Test
public void shouldFailWithNoSettings() {
HttpConnectorFactory factory = new HttpConnectorFactory(config);
IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.DEFAULT, false, new ConnectorConfigImpl());
IApiConnection connection = connector.connect(request, new IAsyncResultHandler<IApiConnectionResponse>() {
@Override
public void handle(IAsyncResult<IApiConnectionResponse> result) {
Assert.assertTrue(result.isError());
System.out.println(result.getError());
}
});
connection.end();
}
use of io.apiman.gateway.engine.IApiConnection in project apiman by apiman.
the class StandardTLSTest method shouldFailWhenCANotTrusted.
/**
* Scenario:
* - CA is only in API trust store, missing from gateway trust store
* - Gateway does not trust API, as it does not trust CA
* - API trusts gateway via CA
*/
@Test
public void shouldFailWhenCANotTrusted() {
// Keystore does not trust the root CA API is signed with.
config.put(TLSOptions.TLS_TRUSTSTORE, getResourcePath("2waytest/basic_mutual_auth/gateway_ts.jks"));
config.put(TLSOptions.TLS_TRUSTSTOREPASSWORD, "changeme");
config.put(TLSOptions.TLS_ALLOWANYHOST, "true");
config.put(TLSOptions.TLS_ALLOWSELFSIGNED, "false");
HttpConnectorFactory factory = new HttpConnectorFactory(config);
IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.DEFAULT, false, new ConnectorConfigImpl());
IApiConnection connection = connector.connect(request, new IAsyncResultHandler<IApiConnectionResponse>() {
@Override
public void handle(IAsyncResult<IApiConnectionResponse> result) {
Assert.assertTrue(result.isError());
System.out.println(result.getError());
Assert.assertTrue(result.getError() instanceof ConnectorException);
}
});
connection.end();
}
use of io.apiman.gateway.engine.IApiConnection in project apiman by apiman.
the class BasicAuthTest method shouldSucceedWithBasicAuth.
/**
* Scenario successful connection to the back end API via basic auth.
*/
@Test
public void shouldSucceedWithBasicAuth() {
endpointProperties.put(BasicAuthOptions.BASIC_USERNAME, "user");
endpointProperties.put(BasicAuthOptions.BASIC_PASSWORD, "user123!");
endpointProperties.put(BasicAuthOptions.BASIC_REQUIRE_SSL, "false");
api.setEndpointProperties(endpointProperties);
api.setEndpoint("http://localhost:8008/echo");
HttpConnectorFactory factory = new HttpConnectorFactory(globalConfig);
IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.BASIC, false, new ConnectorConfigImpl());
IApiConnection connection = connector.connect(request, new IAsyncResultHandler<IApiConnectionResponse>() {
@Override
public void handle(IAsyncResult<IApiConnectionResponse> result) {
Assert.assertTrue("Expected a successful connection response.", result.isSuccess());
IApiConnectionResponse scr = result.getResult();
Assert.assertEquals("Expected a 200 response from the echo server (valid creds).", 200, scr.getHead().getCode());
}
});
if (connection.isConnected()) {
connection.end();
}
}
Aggregations