4

I have a ASP.Core web app that uses windows authentication I am trying to setup integration tests for.

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

All the documentation I have been able to find for integration tests doesn't cover this scenario(windows auth). Has anyone found a solution to this?

1 Answer 1

2

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

You will find their library "IntelliTect.AspNetCore.TestHost.WindowsAuth" here.

I faced the same issue, and that library worked for me!

And it actually inject real windows authentication data, not just a mock data.

Sign up to request clarification or add additional context in comments.

2 Comments

While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
Thank u very much for the advice

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.