Browse Source

Update integration tests to work with authentication in the Order.Api

pull/82/head
dsanz 8 years ago
parent
commit
52bddc51a2
5 changed files with 71 additions and 12 deletions
  1. +12
    -9
      src/Services/Ordering/Ordering.API/Startup.cs
  2. +26
    -0
      test/Services/FunctionalTests/Middleware/AutoAuthorizeMiddleware.cs
  3. +2
    -2
      test/Services/FunctionalTests/Services/Ordering/OrderingScenarioBase.cs
  4. +29
    -0
      test/Services/FunctionalTests/Services/Ordering/OrderingTestsStartup.cs
  5. +2
    -1
      test/Services/FunctionalTests/settings.json

+ 12
- 9
src/Services/Ordering/Ordering.API/Startup.cs View File

@ -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
});
}
}
}

+ 26
- 0
test/Services/FunctionalTests/Middleware/AutoAuthorizeMiddleware.cs View File

@ -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);
}
}
}

+ 2
- 2
test/Services/FunctionalTests/Services/Ordering/OrderingScenarioBase.cs View File

@ -9,9 +9,9 @@
{
public TestServer CreateServer()
{
var webHostBuilder = new WebHostBuilder();
var webHostBuilder = new WebHostBuilder();
webHostBuilder.UseContentRoot(Directory.GetCurrentDirectory());
webHostBuilder.UseStartup<Startup>();
webHostBuilder.UseStartup<OrderingTestsStartup>();
return new TestServer(webHostBuilder);
}


+ 29
- 0
test/Services/FunctionalTests/Services/Ordering/OrderingTestsStartup.cs View File

@ -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);
}
}
}
}

+ 2
- 1
test/Services/FunctionalTests/settings.json View File

@ -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…
Cancel
Save