IntegrationEventsScenarios and MarketingScenarios Unit Tests fail due to missing call to app.UseAuthorization()
See original GitHub issueRunning the unit test cases IntegrationEventsScenarios.Post_update_product_price_and_catalog_and_basket_list_modified
and MarketingScenarios.Set_new_user_location_and_get_location_campaign_by_user_id
on my Windows 10 dev machine, both failed with the same error (after local fix of #1403):
Message:
System.InvalidOperationException : Endpoint Microsoft.eShopOnContainers.Services.Basket.API.Controllers.BasketController.UpdateBasketAsync (Basket.API) contains authorization metadata, but a middleware was not found that supports authorization.
Configure your application startup by adding app.UseAuthorization() inside the call to Configure(..) in the application startup code. The call to app.UseAuthorization() must appear between app.UseRouting() and app.UseEndpoints(...).
Stack Trace:
EndpointMiddleware.ThrowMissingAuthMiddlewareException(Endpoint endpoint)
EndpointMiddleware.Invoke(HttpContext httpContext)
StaticFileMiddleware.Invoke(HttpContext context)
AutoAuthorizeMiddleware.Invoke(HttpContext httpContext) line 30
SwaggerUIMiddleware.Invoke(HttpContext httpContext)
SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
<<SendAsync>g__RunRequestAsync|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
ClientHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
IntegrationEventsScenarios.Post_update_product_price_and_catalog_and_basket_list_modified() line 37
--- End of stack trace from previous location where exception was thrown ---
Looking at the code I noticed that a call to app.UseAuthorization()
was not implemented by the three test service startup classes BasketTestsStartup, LocationsTestsStartup
, and MarketingTestsStartup
in the overloaded method ConfigureAuth
in case the configuration item isTest
is set to true
.
After adding this call, both test cases passed, and none of the other test cases were impacted.
I suggest to add the missing call mentioned above. If you agree, I offer to create the corresponding PR.
Kind Regards,
Stefan
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
Hi Sumit,
Good to hear that it seems to work - hope it will remain this way 😉
Thanks for the feedback and merging the PR.
Regards,
Stefan
Closing this issue.