You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.4 KiB

  1. namespace FunctionalTests.Services.Locations
  2. {
  3. using Microsoft.AspNetCore.Builder;
  4. using Microsoft.AspNetCore.Hosting;
  5. using Microsoft.AspNetCore.Http;
  6. using Microsoft.eShopOnContainers.Services.Locations.API;
  7. using Microsoft.Extensions.Configuration;
  8. using System.Security.Claims;
  9. using System.Threading.Tasks;
  10. public class LocationsTestsStartup : Startup
  11. {
  12. public LocationsTestsStartup(IConfiguration configuration) : base(configuration)
  13. {
  14. }
  15. protected override void ConfigureAuth(IApplicationBuilder app)
  16. {
  17. if (Configuration["isTest"] == bool.TrueString.ToLowerInvariant())
  18. {
  19. app.UseMiddleware<LocationAuthorizeMiddleware>();
  20. }
  21. else
  22. {
  23. base.ConfigureAuth(app);
  24. }
  25. }
  26. class LocationAuthorizeMiddleware
  27. {
  28. private readonly RequestDelegate _next;
  29. public LocationAuthorizeMiddleware(RequestDelegate rd)
  30. {
  31. _next = rd;
  32. }
  33. public async Task Invoke(HttpContext httpContext)
  34. {
  35. var identity = new ClaimsIdentity("cookies");
  36. identity.AddClaim(new Claim("sub", "4611ce3f-380d-4db5-8d76-87a8689058ed"));
  37. httpContext.User.AddIdentity(identity);
  38. await _next.Invoke(httpContext);
  39. }
  40. }
  41. }
  42. }