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