Search in sources :

Example 6 with IApiConnectionResponse

use of io.apiman.gateway.engine.IApiConnectionResponse 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();
}
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 7 with IApiConnectionResponse

use of io.apiman.gateway.engine.IApiConnectionResponse 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();
    }
}
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 8 with IApiConnectionResponse

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

the class BasicAuthTest method shouldFailWithBadCredentials.

/**
 * Should fail because the credentials provided are not valid/
 */
@Test
public void shouldFailWithBadCredentials() {
    endpointProperties.put(BasicAuthOptions.BASIC_USERNAME, "user");
    endpointProperties.put(BasicAuthOptions.BASIC_PASSWORD, "bad-password");
    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 401 response from the echo server (invalid creds).", 401, scr.getHead().getCode());
        }
    });
    if (connection.isConnected()) {
        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 9 with IApiConnectionResponse

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

the class BasicAuthTest method shouldFailWithNoCredentials.

/**
 * Should fail because no credentials were provided.
 */
@Test
public void shouldFailWithNoCredentials() {
    endpointProperties.remove(BasicAuthOptions.BASIC_USERNAME);
    endpointProperties.remove(BasicAuthOptions.BASIC_PASSWORD);
    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 401 response from the echo server (invalid creds).", 401, scr.getHead().getCode());
        }
    });
    if (connection.isConnected()) {
        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 10 with IApiConnectionResponse

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

the class BasicAuthTest method shouldFailWithNoSSL.

/**
 * Scenario successful connection to the back end API via basic auth.
 */
@Test
public void shouldFailWithNoSSL() {
    endpointProperties.put(BasicAuthOptions.BASIC_USERNAME, "user");
    endpointProperties.put(BasicAuthOptions.BASIC_PASSWORD, "user123!");
    endpointProperties.put(BasicAuthOptions.BASIC_REQUIRE_SSL, "true");
    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 an error due to not using SSL.", result.isError());
            Assert.assertTrue("Expected a ConnectorException due to not using SSL.", result.getError() instanceof ConnectorException);
            Assert.assertEquals("Endpoint security requested (BASIC auth) but endpoint is not secure (SSL).", result.getError().getMessage());
        }
    });
    if (connection.isConnected()) {
        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)

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