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.

System.InvalidOperationException : The AuthorizationPolicy named: 'xxx' was not found.

See original GitHub issue

Hi guys, I am writing integration tests for my project that was totally referenced to eShopOnContainers. There are many different roles and role claims, and I created different policies in each project.

When executing a test case for Identity project, an execption thrown:

[2018/4/9 15:45:09 Informational] ------ Load Playlist started ------
[2018/4/9 15:45:09 Informational] ========== Load Playlist finished (0:00:00.0110086) ==========
[2018/4/9 15:45:35 Informational] ------ Discover test started ------
[2018/4/9 15:45:41 Informational] [xUnit.net 00:00:01.7246907]   Discovering: IntegrationTests
[2018/4/9 15:45:41 Informational] [xUnit.net 00:00:01.8588360]   Discovered:  IntegrationTests
[2018/4/9 15:45:41 Informational] ========== Discover test finished: 2 found (0:00:06.2311921) ==========
[2018/4/9 15:45:42 Informational] ------ Run test started ------
[2018/4/9 15:45:57 Informational] [xUnit.net 00:00:07.9918182]   Starting:    IntegrationTests
[2018/4/9 15:46:06 Error] [xUnit.net 00:00:17.3717143]     IntegrationTests.Services.Identity.RoleManagement.Get_regions_and_response_ok_status_code [FAIL]
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3736298]       System.InvalidOperationException : The AuthorizationPolicy named: 'orders.view' was not found.
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3749410]       Stack Trace:
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3760774]            at Microsoft.AspNetCore.Authorization.AuthorizationPolicy.<CombineAsync>d__9.MoveNext()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3761805]         --- End of stack trace from previous location where exception was thrown ---
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3762324]            at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3762577]            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3762961]            at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3763181]            at Microsoft.AspNetCore.Mvc.Internal.AuthorizationApplicationModelProvider.GetFilter(IAuthorizationPolicyProvider policyProvider, IEnumerable`1 authData)
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3763484]            at Microsoft.AspNetCore.Mvc.Internal.AuthorizationApplicationModelProvider.OnProvidersExecuting(ApplicationModelProviderContext context)
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3763770]            at Microsoft.AspNetCore.Mvc.Internal.ControllerActionDescriptorProvider.BuildModel()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3764031]            at Microsoft.AspNetCore.Mvc.Internal.ControllerActionDescriptorProvider.GetDescriptors()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3764307]            at Microsoft.AspNetCore.Mvc.Internal.ControllerActionDescriptorProvider.OnProvidersExecuting(ActionDescriptorProviderContext context)
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3764584]            at Microsoft.AspNetCore.Mvc.Internal.ActionDescriptorCollectionProvider.UpdateCollection()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3764839]            at Microsoft.AspNetCore.Mvc.Internal.ActionDescriptorCollectionProvider.get_ActionDescriptors()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3765095]            at Microsoft.AspNetCore.Mvc.Internal.AttributeRoute.GetTreeRouter()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3765344]            at Microsoft.AspNetCore.Mvc.Internal.AttributeRoute.RouteAsync(RouteContext context)
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3765597]            at Microsoft.AspNetCore.Routing.RouteCollection.<RouteAsync>d__9.MoveNext()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3765810]         --- End of stack trace from previous location where exception was thrown ---
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3766128]            at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3766390]            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3766636]            at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3766874]         --- End of stack trace from previous location where exception was thrown ---
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3767294]            at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3767559]            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3768280]         D:\code\gongfuge\gongfuge\test\Services\IntegrationTests\Middleware\AutoAuthorizeMiddleware.cs(60,0): at IntegrationTests.Middleware.AutoAuthorizeMiddleware.<Invoke>d__2.MoveNext()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3771879]         --- End of stack trace from previous location where exception was thrown ---
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3772450]            at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3772733]            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3773075]         C:\local\identity\server4\IdentityServer4\src\IdentityServer4\Hosting\IdentityServerMiddleware.cs(72,0): at IdentityServer4.Hosting.IdentityServerMiddleware.<Invoke>d__3.MoveNext()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3773337]         --- End of stack trace from previous location where exception was thrown ---
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3773592]            at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3773859]            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3774124]            at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.<Invoke>d__6.MoveNext()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3774340]         --- End of stack trace from previous location where exception was thrown ---
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3774635]            at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3774899]            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3775163]            at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.<Invoke>d__7.MoveNext()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3775374]         --- End of stack trace from previous location where exception was thrown ---
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3775623]            at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3775876]            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3776272]         C:\local\identity\server4\IdentityServer4\src\IdentityServer4\Hosting\BaseUrlMiddleware.cs(43,0): at IdentityServer4.Hosting.BaseUrlMiddleware.<Invoke>d__3.MoveNext()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3776519]         --- End of stack trace from previous location where exception was thrown ---
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3776771]            at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3777029]            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3777285]            at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.<Invoke>d__7.MoveNext()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3777495]         --- End of stack trace from previous location where exception was thrown ---
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3777751]            at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3778003]            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3778258]            at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>d__6.MoveNext()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3778469]         --- End of stack trace from previous location where exception was thrown ---
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3778712]            at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3778970]            at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>d__6.MoveNext()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3779211]         --- End of stack trace from previous location where exception was thrown ---
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3779514]            at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3779770]            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3780031]            at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.<Invoke>d__3.MoveNext()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3780238]         --- End of stack trace from previous location where exception was thrown ---
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3780515]            at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3780776]            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3781053]            at Microsoft.AspNetCore.TestHost.ClientHandler.<>c__DisplayClass3_0.<<SendAsync>b__0>d.MoveNext()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3781275]         --- End of stack trace from previous location where exception was thrown ---
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3781521]            at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3781843]            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3782137]            at Microsoft.AspNetCore.TestHost.ClientHandler.<SendAsync>d__3.MoveNext()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3782372]         --- End of stack trace from previous location where exception was thrown ---
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3782612]            at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3782883]            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3783153]            at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3783411]            at System.Net.Http.HttpClient.<FinishSendAsyncBuffered>d__58.MoveNext()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3783652]         --- End of stack trace from previous location where exception was thrown ---
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3783895]            at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3784175]            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3784538]            at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3784821]         D:\code\gongfuge\gongfuge\test\Services\IntegrationTests\Services\Identity\Scenarios\RoleManagement.cs(32,0): at IntegrationTests.Services.Identity.RoleManagement.<Get_regions_and_response_ok_status_code>d__1.MoveNext()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3785067]         --- End of stack trace from previous location where exception was thrown ---
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3785322]            at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3785596]            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3785803]         --- End of stack trace from previous location where exception was thrown ---
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3786055]            at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3786326]            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3786539]         --- End of stack trace from previous location where exception was thrown ---
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3786795]            at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.3787059]            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
[2018/4/9 15:46:06 Informational] [xUnit.net 00:00:17.4018535]   Finished:    IntegrationTests
[2018/4/9 15:46:06 Informational] ========== Run test finished: 1 run (0:00:24.8384149) ==========

Actually the policy named “orders.view” was added in another project, after I removed that project, the test case worked as expected.

How can i to run all of integration tests in a same project?
Thanks for your help.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
raboudcommented, Apr 9, 2018

@aqbjteddy look at my fork https://github.com/raboud/eshopOnContainers Branch AdminSecurity

eshopOnContainers/test/Services/FunctionalTests/Services/Catalog/CatalogScenarios.cs

1reaction
aqbjteddycommented, Apr 9, 2018

Got it, I will try to solve it in other ways, it should be a bug in Security, may load all of Authorize policies in current dll.
@mvelosop Thanks for your help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The AuthorizationPolicy named: 'Admin' was not found
An unhandled exception occurred while processing the request. InvalidOperationException: The AuthorizationPolicy named: 'Admin' was not found.
Read more >
I can't use ASP.NET Identity and JWT autentication at the ...
System.InvalidOperationException: The AuthorizationPolicy named: 'Bearer' was not found. at Microsoft.AspNetCore.Authorization.
Read more >
The AuthorizationPolicy named: 'Admin' was not found-.net-core
Coding example for the question The AuthorizationPolicy named: 'Admin' was not found-.net-core.
Read more >
C# – The AuthorizationPolicy named: 'Admin' was not found
An unhandled exception occurred while processing the request. InvalidOperationException: The AuthorizationPolicy named: 'Admin' was not found. Here's my code.
Read more >
The AuthorizationPolicy named: 'UserLevel' was not found
An unhandled exception occurred while processing the request. InvalidOperationException: The AuthorizationPolicy named: 'UserLevel' was not found. Microsoft.
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