简体   繁体   English

asp.core Windows身份验证集成测试失败,未配置身份验证处理程序

[英]asp.core windows authentication integration tests fails with No authentication handler is configured

I have a ASP.Core web app that uses windows authentication I am trying to setup integration tests for. 我有一个使用Windows身份验证的ASP.Core Web应用程序,我正在尝试为此设置集成测试。

inside the startup the authorization is configured as follows 在启动过程中,授权配置如下

services.Configure<IISOptions>(options =>
        {
            options.ForwardWindowsAuthentication = true;
        });
        services.AddAuthorization(options =>
        {
            options.AddPolicy("SiteRead", policy => policy.RequireAssertion(
                context => context.User.HasClaim(
                    x => x.Value == "groupSidHere" 
                )));
        });
        services.AddMvc(config =>
        {
            var policy = new AuthorizationPolicyBuilder()
                .RequireAuthenticatedUser()
                .Build();
            config.Filters.Add(new AuthorizeFilter(policy));
        });

The test is as follows 测试如下

        var server = new TestServer(builder);
        var client = server.CreateClient();

        var response = await client.GetAsync("/");
        response.EnsureSuccessStatusCode();

The test fails with the following response 测试失败,并显示以下响应

InvalidOperationException: No authentication handler is configured to handle the scheme: Automatic InvalidOperationException:未配置身份验证处理程序以处理方案:自动

All the documentation I have been able to find for integration tests doesn't cover this scenario(windows auth). 我已经找到的用于集成测试的所有文档都没有涵盖这种情况(Windows身份验证)。 Has anyone found a solution to this? 有没有人找到解决方案?

See this issue , they say: 看到这个问题 ,他们说:

We ended up solving our need for Windows auth with TestServer by creating a little library that will inject some windows auth services into the pipeline to emulate the behavior provided by IIS - you can find it at 我们最终通过创建一个小的库来解决TestServer对Windows身份验证的需求,该库将向管道中注入一些Windows身份验证服务以模拟IIS提供的行为-您可以在以下位置找到它

You will find their library "IntelliTect.AspNetCore.TestHost.WindowsAuth" here . 您可以在此处找到其库“ IntelliTect.AspNetCore.TestHost.WindowsAuth”。

I faced the same issue, and that library worked for me! 我遇到了同样的问题,那个图书馆对我有用!

And it actually inject real windows authentication data, not just a mock data. 它实际上注入了真实的Windows身份验证数据,而不仅仅是模拟数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM