Skip to content

Testing Security Utilities

Dennis C. Mitchell edited this page Apr 4, 2019 · 4 revisions

At some point in the development process, developers add security to their applications. Because this added security can present additional hurdles during focused testing, developers sometimes wait until relatively late in the development process to add the security. Other times, developers toggle between commented and uncommented security code. Either way, testing with security in place can be awkward or annoying.

EDennis.AspNetCore.Base provides two middleware classes that are designed to improve the testing experience when security is in place. AutoLoginMiddleware is provided to automatically build a user principal from a set of predefined users with configured claims. MockClientAuthorizationMiddleware is provided to automatically retrieve an access token (for an API) from an Identity Server instance, using a client from a set of predefined clients with configured claims. These middleware classes can be configured to work with different launch profiles for test users or clients with different claims.

AutoLoginMiddleware

AutoLoginMiddleware is ASP.NET Core middleware that builds a user principal with one or more claims. Each mock user is configured in appsettings.Development.json. Optionally, the developer can setup separate launch profiles for each mock user.

IConfiguration (appsettings.Development.json)

(to be continued)

Startup.Configure

(to be continued)

Optional Launch Profile Configuration (launchSettings.json)

(to be continued)

MockClientAuthorizationMiddleware

MockClientAuthorizationMiddleware is ASP.NET Core middleware that requests an access token from an Identity Server for a particular client and a specific scope (or set of scopes). Each mock client is configured in appsettings.Development.json. Optionally, the developer can setup separate launch profiles for each mock client.

IConfiguration (appsettings.Development.json)

(to be continued)

Startup.Configure

(to be continued)

Optional Launch Profile Configuration (launchSettings.json)

(to be continued)

Clone this wiki locally