split DownstreamTemplate into DownstreamPathTemplate, DownstreamScheme, DownstreamHost and DownstreamPort in order to prepare for service discovery

This commit is contained in:
TomPallister
2017-01-21 09:59:47 +00:00
parent 044b609ea9
commit 0f71c040d9
53 changed files with 767 additions and 258 deletions

View File

@ -23,7 +23,11 @@ namespace Ocelot.AcceptanceTests
private readonly Steps _steps;
private IWebHost _identityServerBuilder;
private string _identityServerRootUrl = "http://localhost:51888";
private string _downstreamServiceRootUrl = "http://localhost:51876/";
private string _downstreamServicePath = "/";
private string _downstreamServiceHost = "localhost";
private int _downstreamServicePort = 51876;
private string _downstreamServiceScheme = "http";
private string _downstreamServiceUrl = "http://localhost:51876";
public AuthenticationTests()
{
@ -39,7 +43,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = _downstreamServiceRootUrl,
DownstreamPathTemplate = _downstreamServicePath,
DownstreamPort = _downstreamServicePort,
DownstreamHost = _downstreamServiceHost,
DownstreamScheme = _downstreamServiceScheme,
UpstreamTemplate = "/",
UpstreamHttpMethod = "Post",
AuthenticationOptions = new FileAuthenticationOptions
@ -56,7 +63,7 @@ namespace Ocelot.AcceptanceTests
};
this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Jwt))
.And(x => x.GivenThereIsAServiceRunningOn(_downstreamServiceRootUrl, 201, string.Empty))
.And(x => x.GivenThereIsAServiceRunningOn(_downstreamServiceUrl, 201, string.Empty))
.And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning())
.And(x => _steps.GivenThePostHasContent("postContent"))
@ -74,7 +81,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = _downstreamServiceRootUrl,
DownstreamPathTemplate = _downstreamServicePath,
DownstreamPort = _downstreamServicePort,
DownstreamHost = _downstreamServiceHost,
DownstreamScheme = _downstreamServiceScheme,
UpstreamTemplate = "/",
UpstreamHttpMethod = "Post",
AuthenticationOptions = new FileAuthenticationOptions
@ -91,7 +101,7 @@ namespace Ocelot.AcceptanceTests
};
this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Reference))
.And(x => x.GivenThereIsAServiceRunningOn(_downstreamServiceRootUrl, 201, string.Empty))
.And(x => x.GivenThereIsAServiceRunningOn(_downstreamServiceUrl, 201, string.Empty))
.And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning())
.And(x => _steps.GivenThePostHasContent("postContent"))
@ -109,7 +119,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = _downstreamServiceRootUrl,
DownstreamPathTemplate = _downstreamServicePath,
DownstreamPort = _downstreamServicePort,
DownstreamHost = _downstreamServiceHost,
DownstreamScheme = _downstreamServiceScheme,
UpstreamTemplate = "/",
UpstreamHttpMethod = "Get",
AuthenticationOptions = new FileAuthenticationOptions
@ -126,7 +139,7 @@ namespace Ocelot.AcceptanceTests
};
this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Jwt))
.And(x => x.GivenThereIsAServiceRunningOn(_downstreamServiceRootUrl, 200, "Hello from Laura"))
.And(x => x.GivenThereIsAServiceRunningOn(_downstreamServiceUrl, 200, "Hello from Laura"))
.And(x => _steps.GivenIHaveAToken(_identityServerRootUrl))
.And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning())
@ -146,7 +159,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = _downstreamServiceRootUrl,
DownstreamPathTemplate = _downstreamServicePath,
DownstreamPort = _downstreamServicePort,
DownstreamHost = _downstreamServiceHost,
DownstreamScheme = _downstreamServiceScheme,
UpstreamTemplate = "/",
UpstreamHttpMethod = "Post",
AuthenticationOptions = new FileAuthenticationOptions
@ -163,7 +179,7 @@ namespace Ocelot.AcceptanceTests
};
this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Jwt))
.And(x => x.GivenThereIsAServiceRunningOn(_downstreamServiceRootUrl, 201, string.Empty))
.And(x => x.GivenThereIsAServiceRunningOn(_downstreamServiceUrl, 201, string.Empty))
.And(x => _steps.GivenIHaveAToken(_identityServerRootUrl))
.And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning())
@ -183,7 +199,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = _downstreamServiceRootUrl,
DownstreamPathTemplate = _downstreamServicePath,
DownstreamPort = _downstreamServicePort,
DownstreamHost = _downstreamServiceHost,
DownstreamScheme = _downstreamServiceScheme,
UpstreamTemplate = "/",
UpstreamHttpMethod = "Post",
AuthenticationOptions = new FileAuthenticationOptions
@ -200,7 +219,7 @@ namespace Ocelot.AcceptanceTests
};
this.Given(x => x.GivenThereIsAnIdentityServerOn(_identityServerRootUrl, "api", AccessTokenType.Reference))
.And(x => x.GivenThereIsAServiceRunningOn(_downstreamServiceRootUrl, 201, string.Empty))
.And(x => x.GivenThereIsAServiceRunningOn(_downstreamServiceUrl, 201, string.Empty))
.And(x => _steps.GivenIHaveAToken(_identityServerRootUrl))
.And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning())

View File

@ -37,7 +37,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:51876/",
DownstreamPathTemplate = "/",
DownstreamPort = 51876,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamHttpMethod = "Get",
AuthenticationOptions = new FileAuthenticationOptions
@ -91,7 +94,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:51876/",
DownstreamPathTemplate = "/",
DownstreamPort = 51876,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamHttpMethod = "Get",
AuthenticationOptions = new FileAuthenticationOptions

View File

@ -31,7 +31,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:51879/",
DownstreamPathTemplate = "/",
DownstreamPort = 51879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamHttpMethod = "Get",
FileCacheOptions = new FileCacheOptions
@ -64,7 +67,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:51879/",
DownstreamPathTemplate = "/",
DownstreamPort = 51879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamHttpMethod = "Get",
FileCacheOptions = new FileCacheOptions

View File

@ -30,7 +30,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:51879/api/products/{productId}",
DownstreamPathTemplate = "/api/products/{productId}",
DownstreamPort = 51879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/products/{productId}",
UpstreamHttpMethod = "Get"
}
@ -54,7 +57,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:51879/api/products/{productId}",
DownstreamPathTemplate = "/api/products/{productId}",
DownstreamPort = 51879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/products/{productId}",
UpstreamHttpMethod = "Get",
ReRouteIsCaseSensitive = false
@ -79,7 +85,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:51879/api/products/{productId}",
DownstreamPathTemplate = "/api/products/{productId}",
DownstreamPort = 51879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/products/{productId}",
UpstreamHttpMethod = "Get",
ReRouteIsCaseSensitive = true
@ -104,7 +113,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:51879/api/products/{productId}",
DownstreamPathTemplate = "/api/products/{productId}",
DownstreamPort = 51879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/PRODUCTS/{productId}",
UpstreamHttpMethod = "Get",
ReRouteIsCaseSensitive = true
@ -129,7 +141,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:51879/api/products/{productId}",
DownstreamPathTemplate = "/api/products/{productId}",
DownstreamPort = 51879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/products/{productId}",
UpstreamHttpMethod = "Get",
ReRouteIsCaseSensitive = true
@ -154,7 +169,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:51879/api/products/{productId}",
DownstreamPathTemplate = "/api/products/{productId}",
DownstreamPort = 51879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/PRODUCTS/{productId}",
UpstreamHttpMethod = "Get",
ReRouteIsCaseSensitive = true

View File

@ -51,7 +51,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:52876/",
DownstreamPathTemplate = "/",
DownstreamPort = 52876,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamHttpMethod = "Get",
AuthenticationOptions = new FileAuthenticationOptions

View File

@ -51,7 +51,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:57876/",
DownstreamPathTemplate = "/",
DownstreamPort = 57876,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamHttpMethod = "Get",
AuthenticationOptions = new FileAuthenticationOptions

View File

@ -45,7 +45,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:41879/",
DownstreamPathTemplate = "/",
DownstreamPort = 41879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamHttpMethod = "Get",
}
@ -79,7 +82,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:41879/",
DownstreamPathTemplate = "/",
DownstreamPort = 41879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamHttpMethod = "Get",
}
@ -113,7 +119,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:41879/",
DownstreamPathTemplate = "41879/",
DownstreamPort = 41879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamHttpMethod = "Get",
}
@ -147,7 +156,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:41879/",
DownstreamPathTemplate = "/",
DownstreamPort = 41879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamHttpMethod = "Get",
}
@ -181,7 +193,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:41879/",
DownstreamPathTemplate = "/",
DownstreamPort = 41879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamHttpMethod = "Get",
}
@ -215,7 +230,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:41879/",
DownstreamPathTemplate = "/",
DownstreamPort = 41879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamHttpMethod = "Get",
}

View File

@ -33,7 +33,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:51879/",
DownstreamPathTemplate = "/",
DownstreamPort = 51879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamHttpMethod = "Get",
RequestIdKey = _steps.RequestIdKey
@ -58,7 +61,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:51879/",
DownstreamPathTemplate = "/",
DownstreamPort = 51879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamHttpMethod = "Get",
RequestIdKey = _steps.RequestIdKey
@ -85,7 +91,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:51879/",
DownstreamPathTemplate = "/",
DownstreamPort = 51879,
DownstreamScheme = "http",
DownstreamHost = "localhost",
UpstreamTemplate = "/",
UpstreamHttpMethod = "Get",
}

View File

@ -29,7 +29,7 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:53876/",
DownstreamPathTemplate = "http://localhost:53876/",
UpstreamTemplate = "/",
UpstreamHttpMethod = "Get"
}

View File

@ -40,7 +40,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:51879/",
DownstreamPathTemplate = "/",
DownstreamScheme = "http",
DownstreamHost = "localhost",
DownstreamPort = 51879,
UpstreamTemplate = "/",
UpstreamHttpMethod = "Get",
}
@ -56,6 +59,62 @@ namespace Ocelot.AcceptanceTests
.BDDfy();
}
[Fact]
public void should_return_response_200_when_path_missing_forward_slash_as_first_char()
{
var configuration = new FileConfiguration
{
ReRoutes = new List<FileReRoute>
{
new FileReRoute
{
DownstreamPathTemplate = "api/products",
DownstreamScheme = "http",
DownstreamHost = "localhost",
DownstreamPort = 51879,
UpstreamTemplate = "/",
UpstreamHttpMethod = "Get",
}
}
};
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879/api/products", 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();
}
[Fact]
public void should_return_response_200_when_host_has_trailing_slash()
{
var configuration = new FileConfiguration
{
ReRoutes = new List<FileReRoute>
{
new FileReRoute
{
DownstreamPathTemplate = "/api/products",
DownstreamScheme = "http",
DownstreamHost = "localhost/",
DownstreamPort = 51879,
UpstreamTemplate = "/",
UpstreamHttpMethod = "Get",
}
}
};
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879/api/products", 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();
}
[Fact]
public void should_not_care_about_no_trailing()
{
@ -65,7 +124,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:51879/products",
DownstreamPathTemplate = "/products",
DownstreamScheme = "http",
DownstreamHost = "localhost",
DownstreamPort = 51879,
UpstreamTemplate = "/products/",
UpstreamHttpMethod = "Get",
}
@ -90,7 +152,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:51879/products",
DownstreamPathTemplate = "/products",
DownstreamScheme = "http",
DownstreamHost = "localhost",
DownstreamPort = 51879,
UpstreamTemplate = "/products",
UpstreamHttpMethod = "Get",
}
@ -115,7 +180,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:51879/products",
DownstreamPathTemplate = "/products",
DownstreamScheme = "http",
DownstreamHost = "localhost",
DownstreamPort = 51879,
UpstreamTemplate = "/products/{productId}",
UpstreamHttpMethod = "Get",
}
@ -139,7 +207,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:51879/api/products/{productId}",
DownstreamPathTemplate = "/api/products/{productId}",
DownstreamScheme = "http",
DownstreamHost = "localhost",
DownstreamPort = 51879,
UpstreamTemplate = "/products/{productId}",
UpstreamHttpMethod = "Get"
}
@ -164,7 +235,10 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:51879/",
DownstreamPathTemplate = "/",
DownstreamHost = "localhost",
DownstreamPort = 51879,
DownstreamScheme = "http",
UpstreamTemplate = "/",
UpstreamHttpMethod = "Post"
}
@ -189,8 +263,11 @@ namespace Ocelot.AcceptanceTests
{
new FileReRoute
{
DownstreamTemplate = "http://localhost:51879/newThing",
DownstreamPathTemplate = "/newThing",
UpstreamTemplate = "/newThing",
DownstreamScheme = "http",
DownstreamHost = "localhost",
DownstreamPort = 51879,
UpstreamHttpMethod = "Get",
}
}

View File

@ -1 +1 @@
{"ReRoutes":[{"DownstreamTemplate":"http://localhost:41879/","UpstreamTemplate":"/","UpstreamHttpMethod":"Get","AuthenticationOptions":{"Provider":null,"ProviderRootUrl":null,"ScopeName":null,"RequireHttps":false,"AdditionalScopes":[],"ScopeSecret":null},"AddHeadersToRequest":{},"AddClaimsToRequest":{},"RouteClaimsRequirement":{},"AddQueriesToRequest":{},"RequestIdKey":null,"FileCacheOptions":{"TtlSeconds":0},"ReRouteIsCaseSensitive":false}],"GlobalConfiguration":{"RequestIdKey":null}}
{"ReRoutes":[{"DownstreamPathTemplate":"/","UpstreamTemplate":"/","UpstreamHttpMethod":"Get","AuthenticationOptions":{"Provider":null,"ProviderRootUrl":null,"ScopeName":null,"RequireHttps":false,"AdditionalScopes":[],"ScopeSecret":null},"AddHeadersToRequest":{},"AddClaimsToRequest":{},"RouteClaimsRequirement":{},"AddQueriesToRequest":{},"RequestIdKey":null,"FileCacheOptions":{"TtlSeconds":0},"ReRouteIsCaseSensitive":false,"ServiceName":null,"DownstreamScheme":"http","DownstreamHost":"localhost","DownstreamPort":41879}],"GlobalConfiguration":{"RequestIdKey":null,"ServiceDiscoveryProvider":{"Provider":null,"Address":null}}}