public void should_add_content_type_and_content_length_headers() { var port = RandomPortFinder.GetRandomPort(); var configuration = new FileConfiguration { ReRoutes = new List <FileReRoute> { new FileReRoute { DownstreamPathTemplate = "/", DownstreamHostAndPorts = new List <FileHostAndPort> { new FileHostAndPort { Host = "localhost", Port = port, } }, DownstreamScheme = "http", UpstreamPathTemplate = "/", UpstreamHttpMethod = new List <string> { "Post" }, } } }; var contentType = "application/json"; this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 201, string.Empty)) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunning()) .And(x => _steps.GivenThePostHasContent("postContent")) .And(x => _steps.GivenThePostHasContentType(contentType)) .When(x => _steps.WhenIPostUrlOnTheApiGateway("/")) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.Created)) .And(x => ThenTheContentLengthIs(11)) .And(x => ThenTheContentTypeIsIs(contentType)) .BDDfy(); }
public void should_not_timeout() { var port = RandomPortFinder.GetRandomPort(); var configuration = new FileConfiguration { Routes = new List <FileRoute> { new FileRoute { DownstreamPathTemplate = "/", DownstreamHostAndPorts = new List <FileHostAndPort> { new FileHostAndPort { Host = "localhost", Port = port, }, }, DownstreamScheme = "http", UpstreamPathTemplate = "/", UpstreamHttpMethod = new List <string> { "Post" }, QoSOptions = new FileQoSOptions { TimeoutValue = 1000, ExceptionsAllowedBeforeBreaking = 10, }, }, }, }; this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, string.Empty, 10)) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunningWithPolly()) .And(x => _steps.GivenThePostHasContent("postContent")) .When(x => _steps.WhenIPostUrlOnTheApiGateway("/")) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .BDDfy(); }
public void should_use_global_request_id_and_forward() { var port = RandomPortFinder.GetRandomPort(); var configuration = new FileConfiguration { Routes = new List <FileRoute> { new FileRoute { DownstreamPathTemplate = "/", DownstreamHostAndPorts = new List <FileHostAndPort> { new FileHostAndPort { Host = "localhost", Port = port, } }, DownstreamScheme = "http", UpstreamPathTemplate = "/", UpstreamHttpMethod = new List <string> { "Get" }, } }, GlobalConfiguration = new FileGlobalConfiguration { RequestIdKey = _steps.RequestIdKey } }; var requestId = Guid.NewGuid().ToString(); this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}")) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunning()) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/", requestId)) .Then(x => _steps.ThenTheRequestIdIsReturned(requestId)) .BDDfy(); }
public void should_transform_upstream_header() { var port = RandomPortFinder.GetRandomPort(); var configuration = new FileConfiguration { Routes = new List <FileRoute> { new FileRoute { DownstreamPathTemplate = "/", DownstreamScheme = "http", DownstreamHostAndPorts = new List <FileHostAndPort> { new FileHostAndPort { Host = "localhost", Port = port, } }, UpstreamPathTemplate = "/", UpstreamHttpMethod = new List <string> { "Get" }, UpstreamHeaderTransform = new Dictionary <string, string> { { "Laz", "D, GP" } } } } }; this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 200, "Laz")) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunning()) .And(x => _steps.GivenIAddAHeader("Laz", "D")) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .And(x => _steps.ThenTheResponseBodyShouldBe("GP")) .BDDfy(); }
public void should_cache_one_http_client_same_re_route() { var port = RandomPortFinder.GetRandomPort(); var configuration = new FileConfiguration { ReRoutes = new List<FileReRoute> { new FileReRoute { DownstreamPathTemplate = "/", DownstreamScheme = "http", DownstreamHostAndPorts = new List<FileHostAndPort> { new FileHostAndPort { Host = "localhost", Port = port, } }, UpstreamPathTemplate = "/", UpstreamHttpMethod = new List<string> { "Get" }, } } }; var cache = new FakeHttpClientCache(); this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200, "Hello from Laura")) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunningWithFakeHttpClientCache(cache)) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura")) .And(x => cache.Count.ShouldBe(1)) .BDDfy(); }
public void should_return_response_200_when_get_converted_to_post_with_content() { var port = RandomPortFinder.GetRandomPort(); var configuration = new FileConfiguration { Routes = new List <FileRoute> { new FileRoute { DownstreamPathTemplate = "/{url}", DownstreamScheme = "http", UpstreamPathTemplate = "/{url}", UpstreamHttpMethod = new List <string> { "Get" }, DownstreamHostAndPorts = new List <FileHostAndPort> { new FileHostAndPort { Host = "localhost", Port = port, }, }, DownstreamHttpMethod = "POST", }, }, }; const string expected = "here is some content"; var httpContent = new StringContent(expected); this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}/", "/", "POST")) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunning()) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/", httpContent)) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .And(_ => _steps.ThenTheResponseBodyShouldBe(expected)) .BDDfy(); }
public void issue_474_should_put_spaces_in_header() { var port = RandomPortFinder.GetRandomPort(); var configuration = new FileConfiguration { ReRoutes = new List <FileReRoute> { new FileReRoute { DownstreamPathTemplate = "/", DownstreamScheme = "http", DownstreamHostAndPorts = new List <FileHostAndPort> { new FileHostAndPort { Host = "localhost", Port = port, } }, UpstreamPathTemplate = "/", UpstreamHttpMethod = new List <string> { "Get" }, } } }; this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 200, "Accept")) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunning()) .And(x => _steps.GivenIAddAHeader("Accept", "text/html")) .And(x => _steps.GivenIAddAHeader("Accept", "application/xhtml+xml")) .And(x => _steps.GivenIAddAHeader("Accept", "application/xml")) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .And(x => _steps.ThenTheResponseBodyShouldBe("text/html, application/xhtml+xml, application/xml")) .BDDfy(); }
public void should_call_global_di_handlers_with_dependency() { var port = RandomPortFinder.GetRandomPort(); var configuration = new FileConfiguration { ReRoutes = new List <FileReRoute> { new FileReRoute { DownstreamPathTemplate = "/", DownstreamScheme = "http", DownstreamHostAndPorts = new List <FileHostAndPort> { new FileHostAndPort { Host = "localhost", Port = port, } }, UpstreamPathTemplate = "/", UpstreamHttpMethod = new List <string> { "Get" }, } } }; var dependency = new FakeDependency(); this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 200, "Hello from Laura")) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunningWithGlobalHandlersRegisteredInDi <FakeHandlerWithDependency>(dependency)) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura")) .And(x => ThenTheDependencyIsCalled(dependency)) .BDDfy(); }
public void should_return_response_200_with_simple_url() { var port = RandomPortFinder.GetRandomPort(); var configuration = new FileConfiguration { Routes = new List <FileRoute> { new FileRoute { DownstreamPathTemplate = "/", DownstreamScheme = "http", DownstreamHostAndPorts = new List <FileHostAndPort> { new FileHostAndPort { Host = "localhost", Port = port, } }, UpstreamPathTemplate = "/", UpstreamHttpMethod = new List <string> { "Post" }, } } }; var input = "people"; this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 200, "Hello from Laura", "\"people\"")) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunning()) .And(x => _steps.GivenThePostHasGzipContent(input)) .When(x => _steps.WhenIPostUrlOnTheApiGateway("/")) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura")) .BDDfy(); }
public void should_not_add_content_type_or_content_length_headers() { var port = RandomPortFinder.GetRandomPort(); var configuration = new FileConfiguration { Routes = new List <FileRoute> { new FileRoute { DownstreamPathTemplate = "/", DownstreamScheme = "http", DownstreamHostAndPorts = new List <FileHostAndPort> { new FileHostAndPort { Host = "localhost", Port = port, } }, UpstreamPathTemplate = "/", UpstreamHttpMethod = new List <string> { "Get" }, } } }; this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 200, "Hello from Laura")) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunning()) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura")) .And(x => ThenTheContentTypeShouldBeEmpty()) .And(x => ThenTheContentLengthShouldBeZero()) .BDDfy(); }
public void should_return_response_200_when_using_http_one_point_one() { var port = RandomPortFinder.GetRandomPort(); var configuration = new FileConfiguration { ReRoutes = new List <FileReRoute> { new FileReRoute { DownstreamPathTemplate = "/{url}", DownstreamScheme = "https", UpstreamPathTemplate = "/{url}", UpstreamHttpMethod = new List <string> { "Get" }, DownstreamHostAndPorts = new List <FileHostAndPort> { new FileHostAndPort { Host = "localhost", Port = port, }, }, DownstreamHttpMethod = "POST", DownstreamHttpVersion = "1.1", DangerousAcceptAnyServerCertificateValidator = true }, }, }; this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}/", "/", port, HttpProtocols.Http1)) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunning()) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .BDDfy(); }
public void should_support_service_fabric_naming_and_dns_service_stateless_and_guest() { var port = RandomPortFinder.GetRandomPort(); var configuration = new FileConfiguration { ReRoutes = new List <FileReRoute> { new FileReRoute { DownstreamPathTemplate = "/api/values", DownstreamScheme = "http", UpstreamPathTemplate = "/EquipmentInterfaces", UpstreamHttpMethod = new List <string> { "Get" }, ServiceName = "OcelotServiceApplication/OcelotApplicationService" } }, GlobalConfiguration = new FileGlobalConfiguration { ServiceDiscoveryProvider = new FileServiceDiscoveryProvider() { Host = "localhost", Port = port, Type = "ServiceFabric" } } }; this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/OcelotServiceApplication/OcelotApplicationService/api/values", 200, "Hello from Laura", "test=best")) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunning()) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/EquipmentInterfaces?test=best")) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura")) .BDDfy(); }
public void should_return_response_200_with_odata_query_string() { var subscriptionId = Guid.NewGuid().ToString(); var unitId = Guid.NewGuid().ToString(); var port = RandomPortFinder.GetRandomPort(); var configuration = new FileConfiguration { ReRoutes = new List <FileReRoute> { new FileReRoute { DownstreamPathTemplate = "/{everything}", DownstreamScheme = "http", DownstreamHostAndPorts = new List <FileHostAndPort> { new FileHostAndPort { Host = "localhost", Port = port, } }, UpstreamPathTemplate = "/{everything}", UpstreamHttpMethod = new List <string> { "Get" }, } } }; this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", $"/odata/customers", "?$filter=Name%20eq%20'Sam'", 200, "Hello from Laura")) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunning()) .When(x => _steps.WhenIGetUrlOnTheApiGateway($"/odata/customers?$filter=Name eq 'Sam' ")) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura")) .BDDfy(); }
public void should_return_response_200_with_query_string_template_different_keys() { var subscriptionId = Guid.NewGuid().ToString(); var unitId = Guid.NewGuid().ToString(); var port = RandomPortFinder.GetRandomPort(); var configuration = new FileConfiguration { ReRoutes = new List <FileReRoute> { new FileReRoute { DownstreamPathTemplate = "/api/subscriptions/{subscriptionId}/updates?unitId={unitId}", DownstreamScheme = "http", DownstreamHostAndPorts = new List <FileHostAndPort> { new FileHostAndPort { Host = "localhost", Port = port, } }, UpstreamPathTemplate = "/api/units/{subscriptionId}/updates?unit={unitId}", UpstreamHttpMethod = new List <string> { "Get" }, } } }; this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", $"/api/subscriptions/{subscriptionId}/updates", $"?unitId={unitId}", 200, "Hello from Laura")) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunning()) .When(x => _steps.WhenIGetUrlOnTheApiGateway($"/api/units/{subscriptionId}/updates?unit={unitId}")) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura")) .BDDfy(); }
public void should_fix_issue_555() { var port = RandomPortFinder.GetRandomPort(); var configuration = new FileConfiguration { Routes = new List <FileRoute> { new FileRoute { DownstreamPathTemplate = "/{everything}", DownstreamScheme = "http", UpstreamPathTemplate = "/{everything}", UpstreamHttpMethod = new List <string> { "Get" }, ServiceName = "OcelotServiceApplication/OcelotApplicationService" } }, GlobalConfiguration = new FileGlobalConfiguration { ServiceDiscoveryProvider = new FileServiceDiscoveryProvider() { Host = "localhost", Port = port, Type = "ServiceFabric" } } }; this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/OcelotServiceApplication/OcelotApplicationService/a", 200, "Hello from Laura", "b=c")) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunning()) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/a?b=c")) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura")) .BDDfy(); }
public void should_not_try_and_write_to_disk_on_startup_when_not_using_admin_api() { var port = RandomPortFinder.GetRandomPort(); var configuration = new FileConfiguration { ReRoutes = new List <FileReRoute> { new FileReRoute { DownstreamPathTemplate = "/", DownstreamScheme = "http", DownstreamHostAndPorts = new List <FileHostAndPort> { new FileHostAndPort { Host = "localhost", Port = port, } }, UpstreamPathTemplate = "/", UpstreamHttpMethod = new List <string> { "Get" }, } } }; var fakeRepo = new FakeFileConfigurationRepository(); this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 200, "Hello from Laura")) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunningWithBlowingUpDiskRepo(fakeRepo)) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .BDDfy(); }
public void should_not_set_trailing_slash_on_url_template() { var port = RandomPortFinder.GetRandomPort(); var configuration = new FileConfiguration { ReRoutes = new List <FileReRoute> { new FileReRoute { DownstreamPathTemplate = "/api/{url}", DownstreamScheme = "http", DownstreamHostAndPorts = new List <FileHostAndPort> { new FileHostAndPort { Host = "localhost", Port = port, } }, UpstreamPathTemplate = "/platform/{url}", UpstreamHttpMethod = new List <string> { "Get" }, } } }; this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/api/swagger/lib/backbone-min.js", 200, "Hello from Laura")) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunning()) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/platform/swagger/lib/backbone-min.js")) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura")) .And(x => ThenTheDownstreamUrlPathShouldBe("/api/swagger/lib/backbone-min.js")) .BDDfy(); }
public void should_dangerous_accept_any_server_certificate_validator() { int port = RandomPortFinder.GetRandomPort(); var configuration = new FileConfiguration { ReRoutes = new List <FileReRoute> { new FileReRoute { DownstreamPathTemplate = "/", DownstreamScheme = "https", DownstreamHostAndPorts = new List <FileHostAndPort> { new FileHostAndPort { Host = "localhost", Port = port, } }, UpstreamPathTemplate = "/", UpstreamHttpMethod = new List <string> { "Get" }, DangerousAcceptAnyServerCertificateValidator = true } } }; this.Given(x => x.GivenThereIsAServiceRunningOn($"https://localhost:{port}", "/", 200, "Hello from Laura", port)) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunning()) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura")) .BDDfy(); }
public void should_return_response_404_with_simple_url_and_hosts_dont_match() { int port = RandomPortFinder.GetRandomPort(); var configuration = new FileConfiguration { Routes = new List <FileRoute> { new FileRoute { DownstreamPathTemplate = "/", DownstreamScheme = "http", DownstreamHostAndPorts = new List <FileHostAndPort> { new FileHostAndPort { Host = "localhost", Port = port, } }, UpstreamPathTemplate = "/", UpstreamHttpMethod = new List <string> { "Get" }, UpstreamHost = "127.0.0.20:5000" } } }; this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/", 200, "Hello from Laura")) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunning()) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.NotFound)) .BDDfy(); }
public void should_return_response_201_with_simple_url_and_multiple_upstream_http_method() { var port = RandomPortFinder.GetRandomPort(); var configuration = new FileConfiguration { ReRoutes = new List <FileReRoute> { new FileReRoute { DownstreamPathTemplate = "/", DownstreamHostAndPorts = new List <FileHostAndPort> { new FileHostAndPort { Host = "localhost", Port = port, } }, DownstreamScheme = "http", UpstreamPathTemplate = "/", UpstreamHttpMethod = new List <string> { "Get", "Post" }, } } }; this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "", 201, string.Empty)) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunning()) .And(x => _steps.GivenThePostHasContent("postContent")) .When(x => _steps.WhenIPostUrlOnTheApiGateway("/")) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.Created)) .BDDfy(); }
public void should_return_response_201_with_complex_query_string() { var port = RandomPortFinder.GetRandomPort(); var configuration = new FileConfiguration { ReRoutes = new List <FileReRoute> { new FileReRoute { DownstreamPathTemplate = "/newThing", UpstreamPathTemplate = "/newThing", DownstreamScheme = "http", DownstreamHostAndPorts = new List <FileHostAndPort> { new FileHostAndPort { Host = "localhost", Port = port, } }, UpstreamHttpMethod = new List <string> { "Get" }, } } }; this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/newThing", 200, "Hello from Laura")) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunning()) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/newThing?DeviceType=IphoneApp&Browser=moonpigIphone&BrowserString=-&CountryCode=123&DeviceName=iPhone 5 (GSM+CDMA)&OperatingSystem=iPhone OS 7.1.2&BrowserVersion=3708AdHoc&ipAddress=-")) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura")) .BDDfy(); }
public void should_return_response_200_with_forward_slash_and_placeholder_only() { var port = RandomPortFinder.GetRandomPort(); var configuration = new FileConfiguration { ReRoutes = new List <FileReRoute> { new FileReRoute { DownstreamPathTemplate = "/{url}", DownstreamScheme = "http", UpstreamPathTemplate = "/{url}", UpstreamHttpMethod = new List <string> { "Get" }, DownstreamHostAndPorts = new List <FileHostAndPort> { new FileHostAndPort { Host = "localhost", Port = port, } } } } }; this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}/", "/", 200, "Hello from Laura")) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunning()) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura")) .BDDfy(); }
public void should_match_multiple_paths_with_catch_all() { var port = RandomPortFinder.GetRandomPort(); var configuration = new FileConfiguration { ReRoutes = new List <FileReRoute> { new FileReRoute { DownstreamPathTemplate = "/{everything}", DownstreamScheme = "http", UpstreamPathTemplate = "/{everything}", UpstreamHttpMethod = new List <string> { "Get" }, DownstreamHostAndPorts = new List <FileHostAndPort> { new FileHostAndPort { Host = "localhost", Port = port, } }, } } }; this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}/", "/test/toot", 200, "Hello from Laura")) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunning()) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/test/toot")) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura")) .BDDfy(); }
public void should_return_response_404_when_reroute_respect_case_sensitivity_set() { int port = RandomPortFinder.GetRandomPort(); var configuration = new FileConfiguration { ReRoutes = new List <FileReRoute> { new FileReRoute { DownstreamPathTemplate = "/api/products/{productId}", DownstreamHostAndPorts = new List <FileHostAndPort> { new FileHostAndPort { Host = "localhost", Port = port, } }, DownstreamScheme = "http", UpstreamPathTemplate = "/products/{productId}", UpstreamHttpMethod = new List <string> { "Get" }, ReRouteIsCaseSensitive = true, } } }; this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/api/products/1", 200, "Some Product")) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunning()) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/PRODUCTS/1")) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.NotFound)) .BDDfy(); }
public void should_return_response_200_with_placeholder_for_final_url_path() { var port = RandomPortFinder.GetRandomPort(); var configuration = new FileConfiguration { ReRoutes = new List <FileReRoute> { new FileReRoute { DownstreamPathTemplate = "/api/{urlPath}", DownstreamScheme = "http", DownstreamHostAndPorts = new List <FileHostAndPort> { new FileHostAndPort { Host = "localhost", Port = port, } }, UpstreamPathTemplate = "/myApp1Name/api/{urlPath}", UpstreamHttpMethod = new List <string> { "Get" }, } } }; this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/api/products/1", 200, "Some Product")) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunning()) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/myApp1Name/api/products/1")) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .And(x => _steps.ThenTheResponseBodyShouldBe("Some Product")) .BDDfy(); }
public void should_handle_request_to_poll_consul_for_downstream_service_and_make_request() { int consulPort = RandomPortFinder.GetRandomPort(); const string serviceName = "web"; int downstreamServicePort = RandomPortFinder.GetRandomPort(); var downstreamServiceOneUrl = $"http://localhost:{downstreamServicePort}"; var fakeConsulServiceDiscoveryUrl = $"http://localhost:{consulPort}"; var serviceEntryOne = new ServiceEntry() { Service = new AgentService() { Service = serviceName, Address = "localhost", Port = downstreamServicePort, ID = $"web_90_0_2_224_{downstreamServicePort}", Tags = new[] { "version-v1" } }, }; var configuration = new FileConfiguration { Routes = new List <FileRoute> { new FileRoute { DownstreamPathTemplate = "/api/home", DownstreamScheme = "http", UpstreamPathTemplate = "/home", UpstreamHttpMethod = new List <string> { "Get", "Options" }, ServiceName = serviceName, LoadBalancerOptions = new FileLoadBalancerOptions { Type = "LeastConnection" }, } }, GlobalConfiguration = new FileGlobalConfiguration() { ServiceDiscoveryProvider = new FileServiceDiscoveryProvider() { Scheme = "http", Host = "localhost", Port = consulPort, Type = "PollConsul", PollingInterval = 0, Namespace = string.Empty } } }; this.Given(x => x.GivenThereIsAServiceRunningOn(downstreamServiceOneUrl, "/api/home", 200, "Hello from Laura")) .And(x => x.GivenThereIsAFakeConsulServiceDiscoveryProvider(fakeConsulServiceDiscoveryUrl, serviceName)) .And(x => x.GivenTheServicesAreRegisteredWithConsul(serviceEntryOne)) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunningWithConsul()) .When(x => _steps.WhenIGetUrlOnTheApiGatewayWaitingForTheResponseToBeOk("/home")) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura")) .BDDfy(); }
public void should_send_request_to_service_after_it_becomes_available_in_consul() { var consulPort = RandomPortFinder.GetRandomPort(); var serviceName = "product"; var servicePort1 = RandomPortFinder.GetRandomPort(); var servicePort2 = RandomPortFinder.GetRandomPort(); var downstreamServiceOneUrl = $"http://localhost:{servicePort1}"; var downstreamServiceTwoUrl = $"http://localhost:{servicePort2}"; var fakeConsulServiceDiscoveryUrl = $"http://localhost:{consulPort}"; var serviceEntryOne = new ServiceEntry() { Service = new AgentService() { Service = serviceName, Address = "localhost", Port = servicePort1, ID = Guid.NewGuid().ToString(), Tags = new string[0] }, }; var serviceEntryTwo = new ServiceEntry() { Service = new AgentService() { Service = serviceName, Address = "localhost", Port = servicePort2, ID = Guid.NewGuid().ToString(), Tags = new string[0] }, }; var configuration = new FileConfiguration { Routes = new List <FileRoute> { new FileRoute { DownstreamPathTemplate = "/", DownstreamScheme = "http", UpstreamPathTemplate = "/", UpstreamHttpMethod = new List <string> { "Get" }, ServiceName = serviceName, LoadBalancerOptions = new FileLoadBalancerOptions { Type = "LeastConnection" }, } }, GlobalConfiguration = new FileGlobalConfiguration() { ServiceDiscoveryProvider = new FileServiceDiscoveryProvider() { Scheme = "http", Host = "localhost", Port = consulPort } } }; this.Given(x => x.GivenProductServiceOneIsRunning(downstreamServiceOneUrl, 200)) .And(x => x.GivenProductServiceTwoIsRunning(downstreamServiceTwoUrl, 200)) .And(x => x.GivenThereIsAFakeConsulServiceDiscoveryProvider(fakeConsulServiceDiscoveryUrl, serviceName)) .And(x => x.GivenTheServicesAreRegisteredWithConsul(serviceEntryOne, serviceEntryTwo)) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunningWithConsul()) .And(x => _steps.WhenIGetUrlOnTheApiGatewayMultipleTimes("/", 10)) .And(x => x.ThenTheTwoServicesShouldHaveBeenCalledTimes(10)) .And(x => x.ThenBothServicesCalledRealisticAmountOfTimes(4, 6)) .And(x => WhenIRemoveAService(serviceEntryTwo)) .And(x => GivenIResetCounters()) .And(x => _steps.WhenIGetUrlOnTheApiGatewayMultipleTimes("/", 10)) .And(x => ThenOnlyOneServiceHasBeenCalled()) .And(x => WhenIAddAServiceBackIn(serviceEntryTwo)) .And(x => GivenIResetCounters()) .When(x => _steps.WhenIGetUrlOnTheApiGatewayMultipleTimes("/", 10)) .Then(x => x.ThenTheTwoServicesShouldHaveBeenCalledTimes(10)) .And(x => x.ThenBothServicesCalledRealisticAmountOfTimes(4, 6)) .BDDfy(); }
public void should_use_token_to_make_request_to_consul() { var token = "abctoken"; var consulPort = RandomPortFinder.GetRandomPort(); var serviceName = "web"; var servicePort = RandomPortFinder.GetRandomPort(); var downstreamServiceOneUrl = $"http://localhost:{servicePort}"; var fakeConsulServiceDiscoveryUrl = $"http://localhost:{consulPort}"; var serviceEntryOne = new ServiceEntry() { Service = new AgentService() { Service = serviceName, Address = "localhost", Port = servicePort, ID = "web_90_0_2_224_8080", Tags = new[] { "version-v1" } }, }; var configuration = new FileConfiguration { Routes = new List <FileRoute> { new FileRoute { DownstreamPathTemplate = "/api/home", DownstreamScheme = "http", UpstreamPathTemplate = "/home", UpstreamHttpMethod = new List <string> { "Get", "Options" }, ServiceName = serviceName, LoadBalancerOptions = new FileLoadBalancerOptions { Type = "LeastConnection" }, } }, GlobalConfiguration = new FileGlobalConfiguration() { ServiceDiscoveryProvider = new FileServiceDiscoveryProvider() { Scheme = "http", Host = "localhost", Port = consulPort, Token = token } } }; this.Given(_ => GivenThereIsAServiceRunningOn(downstreamServiceOneUrl, "/api/home", 200, "Hello from Laura")) .And(_ => GivenThereIsAFakeConsulServiceDiscoveryProvider(fakeConsulServiceDiscoveryUrl, serviceName)) .And(_ => GivenTheServicesAreRegisteredWithConsul(serviceEntryOne)) .And(_ => _steps.GivenThereIsAConfiguration(configuration)) .And(_ => _steps.GivenOcelotIsRunningWithConsul()) .When(_ => _steps.WhenIGetUrlOnTheApiGateway("/home")) .Then(_ => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .And(_ => _steps.ThenTheResponseBodyShouldBe("Hello from Laura")) .And(_ => ThenTheTokenIs(token)) .BDDfy(); }
public void should_wait_for_period_timespan_to_elapse_before_making_next_request() { int port = RandomPortFinder.GetRandomPort(); var configuration = new FileConfiguration { ReRoutes = new List <FileReRoute> { new FileReRoute { DownstreamPathTemplate = "/api/ClientRateLimit", DownstreamHostAndPorts = new List <FileHostAndPort> { new FileHostAndPort { Host = "localhost", Port = port, } }, DownstreamScheme = "http", UpstreamPathTemplate = "/api/ClientRateLimit", UpstreamHttpMethod = new List <string> { "Get" }, RequestIdKey = _steps.RequestIdKey, RateLimitOptions = new FileRateLimitRule() { EnableRateLimiting = true, ClientWhitelist = new List <string>(), Limit = 3, Period = "1s", PeriodTimespan = 2 } } }, GlobalConfiguration = new FileGlobalConfiguration() { RateLimitOptions = new FileRateLimitOptions() { ClientIdHeader = "ClientId", DisableRateLimitHeaders = false, QuotaExceededMessage = "", RateLimitCounterPrefix = "", HttpStatusCode = 428 }, RequestIdKey = "oceclientrequest" } }; this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/api/ClientRateLimit")) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunning()) .When(x => _steps.WhenIGetUrlOnTheApiGatewayMultipleTimesForRateLimit("/api/ClientRateLimit", 1)) .Then(x => _steps.ThenTheStatusCodeShouldBe(200)) .When(x => _steps.WhenIGetUrlOnTheApiGatewayMultipleTimesForRateLimit("/api/ClientRateLimit", 2)) .Then(x => _steps.ThenTheStatusCodeShouldBe(200)) .When(x => _steps.WhenIGetUrlOnTheApiGatewayMultipleTimesForRateLimit("/api/ClientRateLimit", 1)) .Then(x => _steps.ThenTheStatusCodeShouldBe(428)) .And(x => _steps.GivenIWait(1000)) .When(x => _steps.WhenIGetUrlOnTheApiGatewayMultipleTimesForRateLimit("/api/ClientRateLimit", 1)) .Then(x => _steps.ThenTheStatusCodeShouldBe(428)) .And(x => _steps.GivenIWait(1000)) .When(x => _steps.WhenIGetUrlOnTheApiGatewayMultipleTimesForRateLimit("/api/ClientRateLimit", 1)) .Then(x => _steps.ThenTheStatusCodeShouldBe(200)) .BDDfy(); }
public void should_return_response_200_and_foward_claim_as_query_string() { var user = new TestUser() { Username = "******", Password = "******", SubjectId = "registered|1231231", Claims = new List <Claim> { new Claim("CustomerId", "123"), new Claim("LocationId", "1") } }; int port = RandomPortFinder.GetRandomPort(); var configuration = new FileConfiguration { ReRoutes = new List <FileReRoute> { new FileReRoute { DownstreamPathTemplate = "/", DownstreamHostAndPorts = new List <FileHostAndPort> { new FileHostAndPort { Host = "localhost", Port = port, } }, DownstreamScheme = "http", UpstreamPathTemplate = "/", UpstreamHttpMethod = new List <string> { "Get" }, AuthenticationOptions = new FileAuthenticationOptions { AuthenticationProviderKey = "Test", AllowedScopes = new List <string> { "openid", "offline_access", "api" }, }, AddQueriesToRequest = { { "CustomerId", "Claims[CustomerId] > value" }, { "LocationId", "Claims[LocationId] > value" }, { "UserType", "Claims[sub] > value[0] > |" }, { "UserId", "Claims[sub] > value[1] > |" } } } } }; this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Jwt, user)) .And(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", 200)) .And(x => _steps.GivenIHaveAToken(_identityServerRootUrl)) .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunning(_options, "Test")) .And(x => _steps.GivenIHaveAddedATokenToMyRequest()) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .And(x => _steps.ThenTheResponseBodyShouldBe("CustomerId: 123 LocationId: 1 UserType: registered UserId: 1231231")) .BDDfy(); }