Update integration tests to work with authentication in the Order.Api
This commit is contained in:
parent
0fc35d7b4e
commit
52bddc51a2
@ -109,15 +109,7 @@
|
||||
|
||||
app.UseCors("CorsPolicy");
|
||||
|
||||
var identityUrl = Configuration.GetValue<string>("IdentityUrl");
|
||||
|
||||
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
|
||||
{
|
||||
Authority = identityUrl.ToString(),
|
||||
ScopeName = "orders",
|
||||
RequireHttpsMetadata = false
|
||||
});
|
||||
|
||||
ConfigureAuth(app);
|
||||
|
||||
app.UseMvcWithDefaultRoute();
|
||||
|
||||
@ -126,5 +118,16 @@
|
||||
|
||||
OrderingContextSeed.SeedAsync(app).Wait();
|
||||
}
|
||||
|
||||
protected virtual void ConfigureAuth(IApplicationBuilder app)
|
||||
{
|
||||
var identityUrl = Configuration.GetValue<string>("IdentityUrl");
|
||||
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
|
||||
{
|
||||
Authority = identityUrl.ToString(),
|
||||
ScopeName = "orders",
|
||||
RequireHttpsMetadata = false
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FunctionalTests.Middleware
|
||||
{
|
||||
class AutoAuthorizeMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
public AutoAuthorizeMiddleware(RequestDelegate rd)
|
||||
{
|
||||
_next = rd;
|
||||
}
|
||||
|
||||
public async Task Invoke(HttpContext httpContext)
|
||||
{
|
||||
var identity = new ClaimsIdentity();
|
||||
identity.AddClaim(new Claim("sub", "1234"));
|
||||
httpContext.User.AddIdentity(identity);
|
||||
await _next.Invoke(httpContext);
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
{
|
||||
var webHostBuilder = new WebHostBuilder();
|
||||
webHostBuilder.UseContentRoot(Directory.GetCurrentDirectory());
|
||||
webHostBuilder.UseStartup<Startup>();
|
||||
webHostBuilder.UseStartup<OrderingTestsStartup>();
|
||||
|
||||
return new TestServer(webHostBuilder);
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.API;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using FunctionalTests.Middleware;
|
||||
|
||||
namespace FunctionalTests.Services.Ordering
|
||||
{
|
||||
public class OrderingTestsStartup : Startup
|
||||
{
|
||||
public OrderingTestsStartup(IHostingEnvironment env) : base(env)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void ConfigureAuth(IApplicationBuilder app)
|
||||
{
|
||||
if (Configuration["isTest"] == bool.TrueString.ToLowerInvariant())
|
||||
{
|
||||
app.UseMiddleware<AutoAuthorizeMiddleware>();
|
||||
}
|
||||
else
|
||||
{
|
||||
base.ConfigureAuth(app);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
{
|
||||
"ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;",
|
||||
"IdentityUrl": "http://localhost:5105"
|
||||
"IdentityUrl": "http://localhost:5105",
|
||||
"isTest": "true"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user