Search in sources :

Example 16 with IApiConnectionResponse

use of io.apiman.gateway.engine.IApiConnectionResponse in project apiman by apiman.

the class CipherAndProtocolSelectionTest method shouldFailWhenRemoteProtocolsAreExcluded.

/**
 * Scenario:
 *   - Only allowed protocol is one that is disallowed by remote end
 * @throws Exception any exception
 */
@Test
public void shouldFailWhenRemoteProtocolsAreExcluded() 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_DISALLOWEDPROTOCOLS, "SSLv3");
    jettySslContextFactory.setIncludeProtocols("SSLv3");
    jettySslContextFactory.setExcludeProtocols("SSLv1", "SSLv2", "TLSv1", "TLSv2");
    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() instanceof ConnectorException);
        }
    });
    connection.end();
}
Also used : IApiConnection(io.apiman.gateway.engine.IApiConnection) HttpConnectorFactory(io.apiman.gateway.platforms.servlet.connectors.HttpConnectorFactory) ConnectorException(io.apiman.gateway.engine.beans.exceptions.ConnectorException) ConnectorConfigImpl(io.apiman.gateway.platforms.servlet.connectors.ConnectorConfigImpl) IApiConnectionResponse(io.apiman.gateway.engine.IApiConnectionResponse) IApiConnector(io.apiman.gateway.engine.IApiConnector) Test(org.junit.Test)

Example 17 with IApiConnectionResponse

use of io.apiman.gateway.engine.IApiConnectionResponse in project apiman by apiman.

the class CipherAndProtocolSelectionTest method shouldFailWhenAllAvailableProtocolsExcluded.

/**
 * Scenario:
 *   - Only allowed protocol is one that is disallowed by remote end
 * @throws Exception any exception
 */
@Test
public void shouldFailWhenAllAvailableProtocolsExcluded() 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());
            Assert.assertTrue(result.getError().getCause() instanceof java.net.UnknownServiceException);
        }
    });
    connection.end();
}
Also used : IApiConnection(io.apiman.gateway.engine.IApiConnection) HttpConnectorFactory(io.apiman.gateway.platforms.servlet.connectors.HttpConnectorFactory) ConnectorConfigImpl(io.apiman.gateway.platforms.servlet.connectors.ConnectorConfigImpl) IApiConnectionResponse(io.apiman.gateway.engine.IApiConnectionResponse) IApiConnector(io.apiman.gateway.engine.IApiConnector) Test(org.junit.Test)

Example 18 with IApiConnectionResponse

use of io.apiman.gateway.engine.IApiConnectionResponse in project apiman by apiman.

the class StandardTLSTest method shouldSucceedWithValidTLS.

/**
 * Scenario:
 *   - CA inherited trust
 *   - gateway trusts API via CA
 *   - API does not evaluate trust
 */
@Test
public void shouldSucceedWithValidTLS() {
    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");
    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) {
            if (result.isError())
                throw new RuntimeException(result.getError());
            Assert.assertTrue(result.isSuccess());
        }
    });
    connection.end();
}
Also used : IApiConnection(io.apiman.gateway.engine.IApiConnection) HttpConnectorFactory(io.apiman.gateway.platforms.servlet.connectors.HttpConnectorFactory) ConnectorConfigImpl(io.apiman.gateway.platforms.servlet.connectors.ConnectorConfigImpl) IApiConnectionResponse(io.apiman.gateway.engine.IApiConnectionResponse) IApiConnector(io.apiman.gateway.engine.IApiConnector) Test(org.junit.Test)

Example 19 with IApiConnectionResponse

use of io.apiman.gateway.engine.IApiConnectionResponse in project apiman by apiman.

the class StandardTLSTest method shouldAllowAllWhenDevMode.

/**
 * Scenario:
 *   - Development mode TLS pass-through. Accepts anything.
 */
@Test
public void shouldAllowAllWhenDevMode() {
    config.put(TLSOptions.TLS_DEVMODE, "true");
    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.isSuccess());
        }
    });
    connection.end();
}
Also used : IApiConnection(io.apiman.gateway.engine.IApiConnection) HttpConnectorFactory(io.apiman.gateway.platforms.servlet.connectors.HttpConnectorFactory) ConnectorConfigImpl(io.apiman.gateway.platforms.servlet.connectors.ConnectorConfigImpl) IApiConnectionResponse(io.apiman.gateway.engine.IApiConnectionResponse) IApiConnector(io.apiman.gateway.engine.IApiConnector) Test(org.junit.Test)

Example 20 with IApiConnectionResponse

use of io.apiman.gateway.engine.IApiConnectionResponse in project apiman by apiman.

the class PolicyTesterApiConnection method end.

/**
 * @see io.apiman.gateway.engine.io.IWriteStream#end()
 */
@Override
public void end() {
    PolicyTestBackEndApiResponse response = backEndApi.invoke(request, output == null ? null : output.toByteArray());
    IApiConnectionResponse connectionResponse = new PolicyTesterApiConnectionResponse(response);
    handler.handle(AsyncResultImpl.create(connectionResponse));
    finished = true;
}
Also used : IApiConnectionResponse(io.apiman.gateway.engine.IApiConnectionResponse)

Aggregations

IApiConnectionResponse (io.apiman.gateway.engine.IApiConnectionResponse)20 IApiConnector (io.apiman.gateway.engine.IApiConnector)19 IApiConnection (io.apiman.gateway.engine.IApiConnection)18 ConnectorConfigImpl (io.apiman.gateway.platforms.servlet.connectors.ConnectorConfigImpl)18 HttpConnectorFactory (io.apiman.gateway.platforms.servlet.connectors.HttpConnectorFactory)18 Test (org.junit.Test)18 ConnectorException (io.apiman.gateway.engine.beans.exceptions.ConnectorException)4 IApiRequestExecutor (io.apiman.gateway.engine.IApiRequestExecutor)1 IConnectorConfig (io.apiman.gateway.engine.IConnectorConfig)1 IConnectorFactory (io.apiman.gateway.engine.IConnectorFactory)1 IEngine (io.apiman.gateway.engine.IEngine)1 IEngineResult (io.apiman.gateway.engine.IEngineResult)1 IPluginRegistry (io.apiman.gateway.engine.IPluginRegistry)1 IAsyncResultHandler (io.apiman.gateway.engine.async.IAsyncResultHandler)1 RequiredAuthType (io.apiman.gateway.engine.auth.RequiredAuthType)1 Api (io.apiman.gateway.engine.beans.Api)1 ApiRequest (io.apiman.gateway.engine.beans.ApiRequest)1 ApiResponse (io.apiman.gateway.engine.beans.ApiResponse)1 Client (io.apiman.gateway.engine.beans.Client)1 Contract (io.apiman.gateway.engine.beans.Contract)1