question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IntegrationEventsScenarios and MarketingScenarios Unit Tests fail due to missing call to app.UseAuthorization()

See original GitHub issue

Running 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:closed
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
InstanceFactorycommented, Aug 26, 2020

Hi Stefan, yes the changes seem to be working fine.

But when I tested the PR #1406 in newly created Windows VM environment. Everything seems to be working fine. So accepting these changes.

Thank you for the details and PR

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

0reactions
sughosneocommented, Aug 26, 2020

Closing this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Failing unit tests due to missing .config file
Everything works fine when deploying the service, but under unit testing, it seems that the config file becomes invisible. ConfigurationManager.
Read more >
Xcode fails to discover tests, missing gutter test diamonds
Our test suite contains ~6000 unit tests derived from XCTestCase. This problem is reproducible on El Capitan 10.11.3, both when using Xcode ...
Read more >
Best practices for writing unit tests - .NET
Learn best practices for writing unit tests that drive code quality and resilience for .NET Core and .NET Standard projects.
Read more >
Why are unit tests failing seen as bad?
In a staging or release branch, failing tests are "red alert", showing there has been gone something utterly wrong with some changeset, when...
Read more >
Stop requiring only one assertion per unit test: Multiple ...
While clearly a no-op, this implementation passes all tests. The newly-written test asserts that the HTTP response returns a status code in the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found