All Projects → IntelliTect → AspNetCore.TestHost.WindowsAuth

IntelliTect / AspNetCore.TestHost.WindowsAuth

Licence: Apache-2.0 license
Implements Windows authentication for ASP.NET Core TestServer-based integration test projects.

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to AspNetCore.TestHost.WindowsAuth

Restairline
DDD+CQRS+EventSourcing+Hypermedia API+ASP.NET Core 3.1+Masstransit+terraform+docker+k8s
Stars: ✭ 243 (+1057.14%)
Mutual labels:  aspnetcore, aspnet-core
Awesome-Nuget-Packages
📦 A collection of awesome and top .NET packages sorted by most popular needs.
Stars: ✭ 87 (+314.29%)
Mutual labels:  aspnetcore, aspnet-core
SeoTags
SeoTags create all SEO tags you need such as meta, link, twitter card (twitter:), open graph (og:), and JSON-LD schema (structred data).
Stars: ✭ 113 (+438.1%)
Mutual labels:  aspnetcore, aspnet-core
high-performance-aspnet-core-workshop
Sample application used in the High-Performance ASP.NET Core Workshop
Stars: ✭ 29 (+38.1%)
Mutual labels:  aspnetcore, aspnet-core
GatewayService
GatewayService (Ocelot).
Stars: ✭ 19 (-9.52%)
Mutual labels:  aspnetcore, aspnet-core
Idunno.authentication
A filled with self-loathing implementation of Basic Authentication, and Certificate Authentication to make me feel like a real security person, all for for ASP.NET Core
Stars: ✭ 228 (+985.71%)
Mutual labels:  aspnetcore, aspnet-core
Hexagonal-architecture-ASP.NET-Core
App generator API solution template which is built on Hexagnonal Architecture with all essential feature using .NET Core
Stars: ✭ 57 (+171.43%)
Mutual labels:  aspnetcore, integration-testing
Aspnetcoreangularsignalrsecurity
Security with ASP.NET Core, SignalR and Angular
Stars: ✭ 171 (+714.29%)
Mutual labels:  aspnetcore, aspnet-core
AspNetCoreIdentityEncryption
How to do manual encryption for ASP.NET Core Identity 2.1. Not that you should be doing it.
Stars: ✭ 51 (+142.86%)
Mutual labels:  aspnetcore, aspnet-core
Home
Home for Blazor Extensions
Stars: ✭ 51 (+142.86%)
Mutual labels:  aspnetcore, aspnet-core
Run Aspnetcore
A starter kit for your next ASP.NET Core web application. Boilerplate for ASP.NET Core reference application, demonstrating a layered application architecture with applying Clean Architecture and DDD best practices. Download 100+ page eBook PDF from here ->
Stars: ✭ 227 (+980.95%)
Mutual labels:  aspnetcore, aspnet-core
OnlineUsers-Counter-AspNetCore
Display online users count in ASP.NET Core in two ways (Cookie - SingalR)
Stars: ✭ 29 (+38.1%)
Mutual labels:  aspnetcore, aspnet-core
Run Aspnetcore Realworld
E-Commerce real world example of run-aspnetcore ASP.NET Core web application. Implemented e-commerce domain with clean architecture for ASP.NET Core reference application, demonstrating a layered application architecture with DDD best practices. Download 100+ page eBook PDF from here ->
Stars: ✭ 208 (+890.48%)
Mutual labels:  aspnetcore, aspnet-core
Identity.dapper
Identity package that uses Dapper instead EntityFramework for use with .NET Core
Stars: ✭ 234 (+1014.29%)
Mutual labels:  aspnetcore, aspnet-core
Onion Architecture Asp.net Core
WhiteApp API solution template which is built on Onion Architecture with all essential feature using .NET 5!
Stars: ✭ 196 (+833.33%)
Mutual labels:  aspnetcore, integration-testing
ASP.NET-Core-2.0-GraphQL-Sample
GraphQL sample project in ASP.NET Core 2.0
Stars: ✭ 26 (+23.81%)
Mutual labels:  aspnetcore, aspnet-core
Architecture
.NET 6, ASP.NET Core 6, Entity Framework Core 6, C# 10, Angular 13, Clean Code, SOLID, DDD.
Stars: ✭ 2,285 (+10780.95%)
Mutual labels:  aspnetcore, aspnet-core
React Core Boilerplate
Powerful ASP.NET Core 3 templates with React, true server-side rendering and Docker support
Stars: ✭ 169 (+704.76%)
Mutual labels:  aspnetcore, aspnet-core
MinimalApi
ASP.NET Core 7.0 - Minimal API Example - Todo API implementation using ASP.NET Core Minimal API, Entity Framework Core, Token authentication, Versioning, Unit Testing, Integration Testing and Open API.
Stars: ✭ 156 (+642.86%)
Mutual labels:  aspnetcore, aspnet-core
AspNetCore.Unobtrusive.Ajax
Unobtrusive Ajax Helpers (like MVC5 Ajax.BeignForm and Ajax.ActionLink) for ASP.NET Core
Stars: ✭ 46 (+119.05%)
Mutual labels:  aspnetcore, aspnet-core

IntelliTect.AspNetCore.TestHost.WindowsAuth

This project aims to emulate the functionality provided by IIS Integration in an ASP.NET Core project that uses Windows Authentication for the purposes of testing with ASP.NET Core's TestServer from Microsoft.AspNetCore.TestHost.

It provides real, authenticated Windows Auth capabilities - not just a mock of such. The WindowsIdentity of the WindowsPrincipal that will be signed into your application can use all normal behaviors, including .Impersonate().

Getting Started

Build Status Nuget

Visit Nuget.org to pull this library into your project as a dependency.

Usage

There are two main ways to use this library:

  1. Use the provided TestServer fixture that will add the required services for you.
  2. Use your own fixture and build a WebHostBuilder and TestServer yourself.

Option 1 - Use Provided Builder & Fixture

This project is designed to be used with xunit, but has no hard dependencies on it. The below example assumes xunit usage, but could easily be adapted for other test frameworks.

In your test project:

public class MyProjectServerFixture : WindowsAuthServerFixture<Startup>
{
    // Override members as desired. Likely culprits are:

    protected override string ApplicationName => "MyCompany.MyProject.Web";

    // Path to the web project, relative to the working directory of the running test assembly. 
    // Default value (seen below) assumes test and web project live side-by-side.
    // If projects are nested differently (e.g. separate 'src' and 'test' directories), modify as needed.
    protected override string ContentRoot => $"../../../../{ApplicationName}";
}

For more info about overridable members of WindowsAuthServerFixture, view this project's source code.

Option 2 - Bring Your Own Builder

If the provided fixture doesn't fit your needs, or you already have your own fixture for a TestServer/WebHostBuilder, you can simply add the needed services yourself:

var builder = new WebHostBuilder()
    // Your method calls go here...
    .ConfigureServices(services =>
    {
        services.AddWindowsAuthenticationForTesting();

        // ONLY IF AuthenticationMiddleware (UseAuthentication) isn't normally part of your pipeline:
        services.AddTransient<IStartupFilter, AddAuthenticationStartupFilter>();
    });

You would then create a test fixture (or equivalent for your preferred test framework) that would expose a TestServer created from this WebHostBuilder.

Usage in Tests

Then, in an xunit test:

public class MyTests : IClassFixture<MyProjectServerFixture>
{
    private readonly TestServer _server;

    public MyTests(MyProjectServerFixture fixture)
    {
        _server = fixture.Server;
    }

    [Fact]
    public async Task MyTest() 
    {
        HttpClient client;
        // Choose one:
        client = _server.ClientForAnonymous();
        client = _server.ClientForCurrentUser(); // Effectively: UseDefaultCredentials = true
        client = _server.ClientForUser(new NetworkCredential("userName", "password", "DOMAIN"));

        // Make requests against the HttpClient. The requests will be appropriately authenticated when they are handled by your web application, despite not running with IIS.
    }
}

Troubleshooting

  • If requests aren't being authenticated, ensure that the standard AuthenticationMiddleware is part of your request pipeline. Typically, this middleware is added by calling app.UseAuthentication() in the Configure method of Startup.cs. This middleware isn't strictly required when using IIS integration with Windows auth enabled and anonymous auth disabled, but it is required for this library. There is an overridable property, AddAuthenticationMiddleware, on WindowsAuthServerFixture that if overridden to true will add the middleware on your behalf.
  • This library sets its authentication handler as the default authentication scheme, overriding any other scheme configured in your Startup.cs. If this is not desired, check out WindowsAuthServiceCollectionExtensions.cs for how to add in the required services yourself in a different manner.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].