Search in sources :

Example 1 with ConfigurationResourceManager

use of org.swisspush.gateleen.core.configuration.ConfigurationResourceManager in project gateleen by swisspush.

the class RouterTest method testRequestHopValidationWithLimitZero.

@Test
public void testRequestHopValidationWithLimitZero(TestContext context) {
    storage = new MockResourceStorage(ImmutableMap.of(rulesPath, RULES_WITH_HOPS, serverUrl + "/loop/4/resource", RANDOM_RESOURCE));
    Router router = new Router(vertx, storage, properties, loggingResourceManager, monitoringHandler, httpClient, serverUrl, rulesPath, userProfilePath, info, storagePort);
    ConfigurationResourceManager configurationResourceManager = Mockito.mock(ConfigurationResourceManager.class);
    router.enableRoutingConfiguration(configurationResourceManager, serverUrl + "/admin/v1/routing/config");
    context.assertFalse(router.isRoutingBroken(), "Routing should not be broken");
    context.assertNull(router.getRoutingBrokenMessage(), "RoutingBrokenMessage should be null");
    // change the hops limit to 0, so no re-routing is allowed
    router.resourceChanged(serverUrl + "/admin/v1/routing/config", Buffer.buffer("{\"request.hops.limit\":0}"));
    final DummyHttpServerResponse response = new DummyHttpServerResponse();
    response.setStatusCode(StatusCode.OK.getStatusCode());
    response.setStatusMessage(StatusCode.OK.getStatusMessage());
    class GETRandomResourceRequest extends DummyHttpServerRequest {

        MultiMap headers = MultiMap.caseInsensitiveMultiMap();

        @Override
        public HttpMethod method() {
            return HttpMethod.GET;
        }

        @Override
        public String uri() {
            return "/gateleen/server/loop/4/resource";
        }

        @Override
        public String path() {
            return "/gateleen/server/loop/4/resource";
        }

        @Override
        public MultiMap headers() {
            return headers;
        }

        @Override
        public MultiMap params() {
            return MultiMap.caseInsensitiveMultiMap();
        }

        @Override
        public HttpServerRequest bodyHandler(Handler<Buffer> bodyHandler) {
            bodyHandler.handle(Buffer.buffer(RANDOM_RESOURCE));
            return this;
        }

        @Override
        public HttpServerRequest handler(Handler<Buffer> handler) {
            handler.handle(Buffer.buffer(RANDOM_RESOURCE));
            return this;
        }

        @Override
        public HttpServerRequest endHandler(Handler<Void> endHandler) {
            endHandler.handle(null);
            return this;
        }

        @Override
        public DummyHttpServerResponse response() {
            return response;
        }
    }
    GETRandomResourceRequest request = new GETRandomResourceRequest();
    router.route(request);
    context.assertEquals("1", request.headers().get("x-hops"), "x-hops header should have value 1");
    context.assertEquals(StatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), request.response().getStatusCode(), "StatusCode should be 500");
    context.assertEquals("Request hops limit exceeded", request.response().getStatusMessage(), "StatusMessage should be 'Request hops limit exceeded'");
}
Also used : MultiMap(io.vertx.core.MultiMap) HeadersMultiMap(io.vertx.core.http.impl.headers.HeadersMultiMap) DummyHttpServerResponse(org.swisspush.gateleen.core.http.DummyHttpServerResponse) DummyHttpServerRequest(org.swisspush.gateleen.core.http.DummyHttpServerRequest) MockResourceStorage(org.swisspush.gateleen.core.storage.MockResourceStorage) MonitoringHandler(org.swisspush.gateleen.monitoring.MonitoringHandler) Handler(io.vertx.core.Handler) ConfigurationResourceManager(org.swisspush.gateleen.core.configuration.ConfigurationResourceManager) Test(org.junit.Test)

Example 2 with ConfigurationResourceManager

use of org.swisspush.gateleen.core.configuration.ConfigurationResourceManager in project gateleen by swisspush.

the class RouterTest method testForwarderRequestWithHeadersFilterPresent.

@Test
public void testForwarderRequestWithHeadersFilterPresent(TestContext context) {
    storage = new MockResourceStorage(ImmutableMap.of(rulesPath, RULES_WITH_HEADERSFILTER, serverUrl + "forward/to/backend", RANDOM_RESOURCE));
    Router router = new Router(vertx, storage, properties, loggingResourceManager, monitoringHandler, httpClient, serverUrl, rulesPath, userProfilePath, info, storagePort);
    ConfigurationResourceManager configurationResourceManager = Mockito.mock(ConfigurationResourceManager.class);
    router.enableRoutingConfiguration(configurationResourceManager, serverUrl + "/admin/v1/routing/config");
    context.assertFalse(router.isRoutingBroken(), "Routing should not be broken");
    context.assertNull(router.getRoutingBrokenMessage(), "RoutingBrokenMessage should be null");
    final DummyHttpServerResponse response = new DummyHttpServerResponse();
    response.setStatusCode(StatusCode.OK.getStatusCode());
    response.setStatusMessage(StatusCode.OK.getStatusMessage());
    MultiMap headers = new HeadersMultiMap();
    headers.set("x-foo", "A");
    DummyHttpServerRequest request = buildRequest(HttpMethod.GET, "/gateleen/server/forward/to/backend", headers, Buffer.buffer(RANDOM_RESOURCE), response);
    router.route(request);
    // we expect a status code 500 because of a NullPointerException in the test setup
    // however, this means that the headersFilter evaluation did not return a 400 Bad Request
    context.assertEquals(StatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), request.response().getStatusCode(), "StatusCode should be 500");
}
Also used : MultiMap(io.vertx.core.MultiMap) HeadersMultiMap(io.vertx.core.http.impl.headers.HeadersMultiMap) DummyHttpServerResponse(org.swisspush.gateleen.core.http.DummyHttpServerResponse) DummyHttpServerRequest(org.swisspush.gateleen.core.http.DummyHttpServerRequest) HeadersMultiMap(io.vertx.core.http.impl.headers.HeadersMultiMap) MockResourceStorage(org.swisspush.gateleen.core.storage.MockResourceStorage) ConfigurationResourceManager(org.swisspush.gateleen.core.configuration.ConfigurationResourceManager) Test(org.junit.Test)

Example 3 with ConfigurationResourceManager

use of org.swisspush.gateleen.core.configuration.ConfigurationResourceManager in project gateleen by swisspush.

the class RouterTest method testStorageRequestWithHeadersFilterAbsent.

@Test
public void testStorageRequestWithHeadersFilterAbsent(TestContext context) {
    storage = new MockResourceStorage(ImmutableMap.of(rulesPath, RULES_WITH_HEADERSFILTER, serverUrl + "forward/to/storage", RANDOM_RESOURCE));
    Router router = new Router(vertx, storage, properties, loggingResourceManager, monitoringHandler, httpClient, serverUrl, rulesPath, userProfilePath, info, storagePort);
    ConfigurationResourceManager configurationResourceManager = Mockito.mock(ConfigurationResourceManager.class);
    router.enableRoutingConfiguration(configurationResourceManager, serverUrl + "/admin/v1/routing/config");
    context.assertFalse(router.isRoutingBroken(), "Routing should not be broken");
    context.assertNull(router.getRoutingBrokenMessage(), "RoutingBrokenMessage should be null");
    final DummyHttpServerResponse response = new DummyHttpServerResponse();
    response.setStatusCode(StatusCode.OK.getStatusCode());
    response.setStatusMessage(StatusCode.OK.getStatusMessage());
    MultiMap headers = new HeadersMultiMap();
    DummyHttpServerRequest request = buildRequest(HttpMethod.GET, "/gateleen/server/forward/to/storage", headers, Buffer.buffer(RANDOM_RESOURCE), response);
    router.route(request);
    context.assertEquals(StatusCode.BAD_REQUEST.getStatusCode(), request.response().getStatusCode(), "StatusCode should be 400");
    context.assertEquals(StatusCode.BAD_REQUEST.getStatusMessage(), request.response().getStatusMessage(), "StatusMessage should be Bad Request");
}
Also used : MultiMap(io.vertx.core.MultiMap) HeadersMultiMap(io.vertx.core.http.impl.headers.HeadersMultiMap) DummyHttpServerResponse(org.swisspush.gateleen.core.http.DummyHttpServerResponse) DummyHttpServerRequest(org.swisspush.gateleen.core.http.DummyHttpServerRequest) HeadersMultiMap(io.vertx.core.http.impl.headers.HeadersMultiMap) MockResourceStorage(org.swisspush.gateleen.core.storage.MockResourceStorage) ConfigurationResourceManager(org.swisspush.gateleen.core.configuration.ConfigurationResourceManager) Test(org.junit.Test)

Example 4 with ConfigurationResourceManager

use of org.swisspush.gateleen.core.configuration.ConfigurationResourceManager in project gateleen by swisspush.

the class RouterTest method testForwarderRequestWithHeadersFilterNotMatching.

@Test
public void testForwarderRequestWithHeadersFilterNotMatching(TestContext context) {
    storage = new MockResourceStorage(ImmutableMap.of(rulesPath, RULES_WITH_HEADERSFILTER, serverUrl + "forward/to/backend", RANDOM_RESOURCE));
    Router router = new Router(vertx, storage, properties, loggingResourceManager, monitoringHandler, httpClient, serverUrl, rulesPath, userProfilePath, info, storagePort);
    ConfigurationResourceManager configurationResourceManager = Mockito.mock(ConfigurationResourceManager.class);
    router.enableRoutingConfiguration(configurationResourceManager, serverUrl + "/admin/v1/routing/config");
    context.assertFalse(router.isRoutingBroken(), "Routing should not be broken");
    context.assertNull(router.getRoutingBrokenMessage(), "RoutingBrokenMessage should be null");
    final DummyHttpServerResponse response = new DummyHttpServerResponse();
    response.setStatusCode(StatusCode.OK.getStatusCode());
    response.setStatusMessage(StatusCode.OK.getStatusMessage());
    MultiMap headers = new HeadersMultiMap();
    headers.set("x-foo", "X");
    DummyHttpServerRequest request = buildRequest(HttpMethod.GET, "/gateleen/server/forward/to/backend", headers, Buffer.buffer(RANDOM_RESOURCE), response);
    router.route(request);
    context.assertEquals(StatusCode.BAD_REQUEST.getStatusCode(), request.response().getStatusCode(), "StatusCode should be 400");
    context.assertEquals(StatusCode.BAD_REQUEST.getStatusMessage(), request.response().getStatusMessage(), "StatusMessage should be Bad Request");
}
Also used : MultiMap(io.vertx.core.MultiMap) HeadersMultiMap(io.vertx.core.http.impl.headers.HeadersMultiMap) DummyHttpServerResponse(org.swisspush.gateleen.core.http.DummyHttpServerResponse) DummyHttpServerRequest(org.swisspush.gateleen.core.http.DummyHttpServerRequest) HeadersMultiMap(io.vertx.core.http.impl.headers.HeadersMultiMap) MockResourceStorage(org.swisspush.gateleen.core.storage.MockResourceStorage) ConfigurationResourceManager(org.swisspush.gateleen.core.configuration.ConfigurationResourceManager) Test(org.junit.Test)

Example 5 with ConfigurationResourceManager

use of org.swisspush.gateleen.core.configuration.ConfigurationResourceManager in project gateleen by swisspush.

the class RouterTest method testRequestHopValidationLimitNotYetReached.

@Test
public void testRequestHopValidationLimitNotYetReached(TestContext context) {
    storage = new MockResourceStorage(ImmutableMap.of(rulesPath, RULES_WITH_HOPS, serverUrl + "/loop/4/resource", RANDOM_RESOURCE));
    Router router = new Router(vertx, storage, properties, loggingResourceManager, monitoringHandler, httpClient, serverUrl, rulesPath, userProfilePath, info, storagePort);
    ConfigurationResourceManager configurationResourceManager = Mockito.mock(ConfigurationResourceManager.class);
    router.enableRoutingConfiguration(configurationResourceManager, serverUrl + "/admin/v1/routing/config");
    context.assertFalse(router.isRoutingBroken(), "Routing should not be broken");
    context.assertNull(router.getRoutingBrokenMessage(), "RoutingBrokenMessage should be null");
    // change the hops limit to 5
    router.resourceChanged(serverUrl + "/admin/v1/routing/config", Buffer.buffer("{\"request.hops.limit\":5}"));
    final DummyHttpServerResponse response = new DummyHttpServerResponse();
    response.setStatusCode(StatusCode.OK.getStatusCode());
    response.setStatusMessage(StatusCode.OK.getStatusMessage());
    class GETRandomResourceRequest extends DummyHttpServerRequest {

        MultiMap headers = MultiMap.caseInsensitiveMultiMap();

        @Override
        public HttpMethod method() {
            return HttpMethod.GET;
        }

        @Override
        public String uri() {
            return "/gateleen/server/loop/4/resource";
        }

        @Override
        public String path() {
            return "/gateleen/server/loop/4/resource";
        }

        @Override
        public MultiMap headers() {
            return headers;
        }

        @Override
        public MultiMap params() {
            return MultiMap.caseInsensitiveMultiMap();
        }

        @Override
        public HttpServerRequest bodyHandler(Handler<Buffer> bodyHandler) {
            bodyHandler.handle(Buffer.buffer(RANDOM_RESOURCE));
            return this;
        }

        @Override
        public HttpServerRequest handler(Handler<Buffer> handler) {
            handler.handle(Buffer.buffer(RANDOM_RESOURCE));
            return this;
        }

        @Override
        public HttpServerRequest endHandler(Handler<Void> endHandler) {
            endHandler.handle(null);
            return this;
        }

        @Override
        public DummyHttpServerResponse response() {
            return response;
        }
    }
    GETRandomResourceRequest request = new GETRandomResourceRequest();
    router.route(request);
    context.assertEquals("1", request.headers().get("x-hops"), "x-hops header should have value 1");
    context.assertEquals(StatusCode.OK.getStatusCode(), request.response().getStatusCode(), "StatusCode should be 200");
    context.assertEquals(StatusCode.OK.getStatusMessage(), request.response().getStatusMessage(), "StatusMessage should be OK");
}
Also used : MultiMap(io.vertx.core.MultiMap) HeadersMultiMap(io.vertx.core.http.impl.headers.HeadersMultiMap) DummyHttpServerResponse(org.swisspush.gateleen.core.http.DummyHttpServerResponse) DummyHttpServerRequest(org.swisspush.gateleen.core.http.DummyHttpServerRequest) MockResourceStorage(org.swisspush.gateleen.core.storage.MockResourceStorage) MonitoringHandler(org.swisspush.gateleen.monitoring.MonitoringHandler) Handler(io.vertx.core.Handler) ConfigurationResourceManager(org.swisspush.gateleen.core.configuration.ConfigurationResourceManager) Test(org.junit.Test)

Aggregations

ConfigurationResourceManager (org.swisspush.gateleen.core.configuration.ConfigurationResourceManager)13 MockResourceStorage (org.swisspush.gateleen.core.storage.MockResourceStorage)11 MultiMap (io.vertx.core.MultiMap)9 HeadersMultiMap (io.vertx.core.http.impl.headers.HeadersMultiMap)9 Test (org.junit.Test)9 DummyHttpServerRequest (org.swisspush.gateleen.core.http.DummyHttpServerRequest)9 DummyHttpServerResponse (org.swisspush.gateleen.core.http.DummyHttpServerResponse)9 MonitoringHandler (org.swisspush.gateleen.monitoring.MonitoringHandler)5 Handler (io.vertx.core.Handler)4 Before (org.junit.Before)3 JsonObject (io.vertx.core.json.JsonObject)2 RoutingContext (io.vertx.ext.web.RoutingContext)2 RedisOptions (io.vertx.redis.client.RedisOptions)2 RedisClient (io.vertx.redis.client.impl.RedisClient)2 CacheHandler (org.swisspush.gateleen.cache.CacheHandler)2 DefaultCacheDataFetcher (org.swisspush.gateleen.cache.fetch.DefaultCacheDataFetcher)2 RedisCacheStorage (org.swisspush.gateleen.cache.storage.RedisCacheStorage)2 CORSHandler (org.swisspush.gateleen.core.cors.CORSHandler)2 EventBusHandler (org.swisspush.gateleen.core.event.EventBusHandler)2 ClientRequestCreator (org.swisspush.gateleen.core.http.ClientRequestCreator)2