diff --git a/AspNetCore.Authentication.ApiKey.sln b/AspNetCore.Authentication.ApiKey.sln index 244fa79..d04d136 100644 --- a/AspNetCore.Authentication.ApiKey.sln +++ b/AspNetCore.Authentication.ApiKey.sln @@ -25,7 +25,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCore.Authentication.A EndProject Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "SampleWebApi.Shared", "samples\SampleWebApi.Shared\SampleWebApi.Shared.shproj", "{E544FB20-29F3-41F5-A78E-6164F9C43B3C}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleWebApi_6_0", "samples\SampleWebApi_6_0\SampleWebApi_6_0.csproj", "{13031DBF-54EA-4A64-A03B-88B4CED1D5F5}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleWebApi", "samples\SampleWebApi\SampleWebApi.csproj", "{0B6FB864-E2AE-4086-8E51-53A6A079E9FD}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -41,10 +41,10 @@ Global {5A9AAE35-66E9-408E-B763-C71F0C0751B2}.Debug|Any CPU.Build.0 = Debug|Any CPU {5A9AAE35-66E9-408E-B763-C71F0C0751B2}.Release|Any CPU.ActiveCfg = Release|Any CPU {5A9AAE35-66E9-408E-B763-C71F0C0751B2}.Release|Any CPU.Build.0 = Release|Any CPU - {13031DBF-54EA-4A64-A03B-88B4CED1D5F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {13031DBF-54EA-4A64-A03B-88B4CED1D5F5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {13031DBF-54EA-4A64-A03B-88B4CED1D5F5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {13031DBF-54EA-4A64-A03B-88B4CED1D5F5}.Release|Any CPU.Build.0 = Release|Any CPU + {0B6FB864-E2AE-4086-8E51-53A6A079E9FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0B6FB864-E2AE-4086-8E51-53A6A079E9FD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0B6FB864-E2AE-4086-8E51-53A6A079E9FD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0B6FB864-E2AE-4086-8E51-53A6A079E9FD}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -53,13 +53,13 @@ Global {09D17A19-0406-487A-810A-24107AE767F8} = {BCEF726B-D658-40C2-9099-7001BA519E71} {5A9AAE35-66E9-408E-B763-C71F0C0751B2} = {A15FB7AB-5B7A-4428-BEBA-32DEE3C88C39} {E544FB20-29F3-41F5-A78E-6164F9C43B3C} = {3C777BBB-7464-43FB-A046-EA465791AB0C} - {13031DBF-54EA-4A64-A03B-88B4CED1D5F5} = {3C777BBB-7464-43FB-A046-EA465791AB0C} + {0B6FB864-E2AE-4086-8E51-53A6A079E9FD} = {3C777BBB-7464-43FB-A046-EA465791AB0C} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {70815049-1680-480A-BF5A-00536D6C9C20} EndGlobalSection GlobalSection(SharedMSBuildProjectFiles) = preSolution - samples\SampleWebApi.Shared\SampleWebApi.Shared.projitems*{13031dbf-54ea-4a64-a03b-88b4ced1d5f5}*SharedItemsImports = 5 + samples\SampleWebApi.Shared\SampleWebApi.Shared.projitems*{0b6fb864-e2ae-4086-8e51-53a6a079e9fd}*SharedItemsImports = 5 samples\SampleWebApi.Shared\SampleWebApi.Shared.projitems*{e544fb20-29f3-41f5-a78e-6164f9c43b3c}*SharedItemsImports = 13 EndGlobalSection EndGlobal diff --git a/samples/SampleWebApi.Shared/Models/ApiKey.cs b/samples/SampleWebApi.Shared/Models/ApiKey.cs index a2bfcbc..c70c0a1 100644 --- a/samples/SampleWebApi.Shared/Models/ApiKey.cs +++ b/samples/SampleWebApi.Shared/Models/ApiKey.cs @@ -1,10 +1,9 @@ -using AspNetCore.Authentication.ApiKey; -using System.Collections.Generic; +using System.Collections.Generic; using System.Security.Claims; namespace SampleWebApi.Models { - class ApiKey : IApiKey + class ApiKey : MadEyeMatt.AspNetCore.Authentication.ApiKey.IApiKey { public ApiKey(string key, string owner, List claims = null) { diff --git a/samples/SampleWebApi.Shared/Repositories/IApiKeyRepository.cs b/samples/SampleWebApi.Shared/Repositories/IApiKeyRepository.cs index a2e1cd1..8de41ce 100644 --- a/samples/SampleWebApi.Shared/Repositories/IApiKeyRepository.cs +++ b/samples/SampleWebApi.Shared/Repositories/IApiKeyRepository.cs @@ -1,5 +1,4 @@ -using AspNetCore.Authentication.ApiKey; -using System.Threading.Tasks; +using System.Threading.Tasks; namespace SampleWebApi.Repositories { @@ -8,6 +7,6 @@ namespace SampleWebApi.Repositories /// public interface IApiKeyRepository { - Task GetApiKeyAsync(string key); + Task GetApiKeyAsync(string key); } } \ No newline at end of file diff --git a/samples/SampleWebApi.Shared/Repositories/InMemoryApiKeyRepository.cs b/samples/SampleWebApi.Shared/Repositories/InMemoryApiKeyRepository.cs index 1a0b1da..b8a112a 100644 --- a/samples/SampleWebApi.Shared/Repositories/InMemoryApiKeyRepository.cs +++ b/samples/SampleWebApi.Shared/Repositories/InMemoryApiKeyRepository.cs @@ -1,5 +1,4 @@ -using AspNetCore.Authentication.ApiKey; -using SampleWebApi.Models; +using SampleWebApi.Models; using System; using System.Collections.Generic; using System.Linq; @@ -12,13 +11,13 @@ namespace SampleWebApi.Repositories /// public class InMemoryApiKeyRepository : IApiKeyRepository { - private List _cache = new List + private List _cache = new List { new ApiKey("Key1", "Admin"), new ApiKey("Key2", "User"), }; - public Task GetApiKeyAsync(string key) + public Task GetApiKeyAsync(string key) { var apiKey = _cache.FirstOrDefault(k => k.Key.Equals(key, StringComparison.OrdinalIgnoreCase)); return Task.FromResult(apiKey); diff --git a/samples/SampleWebApi.Shared/Services/ApiKeyAuthenticationService.cs b/samples/SampleWebApi.Shared/Services/ApiKeyAuthenticationService.cs index 40aa278..d059869 100644 --- a/samples/SampleWebApi.Shared/Services/ApiKeyAuthenticationService.cs +++ b/samples/SampleWebApi.Shared/Services/ApiKeyAuthenticationService.cs @@ -1,13 +1,12 @@ -using AspNetCore.Authentication.ApiKey; using Microsoft.Extensions.Logging; using SampleWebApi.Repositories; using System.Threading.Tasks; namespace SampleWebApi.Services { - internal class ApiKeyAuthenticationService : IApiKeyAuthenticationService + internal class ApiKeyAuthenticationService : MadEyeMatt.AspNetCore.Authentication.ApiKey.IApiKeyAuthenticationService { - private readonly ILogger _logger; + private readonly ILogger _logger; private readonly IApiKeyRepository _apiKeyRepository; public ApiKeyAuthenticationService(ILogger logger, IApiKeyRepository apiKeyRepository) @@ -16,7 +15,7 @@ public ApiKeyAuthenticationService(ILogger logger, _apiKeyRepository = apiKeyRepository; } - public async Task AuthenticateAsync(string key) + public async Task AuthenticateAsync(string key) { try { diff --git a/samples/SampleWebApi.Shared/Services/ApiKeyAuthenticationServiceFactory.cs b/samples/SampleWebApi.Shared/Services/ApiKeyAuthenticationServiceFactory.cs index d1c541e..b432f4a 100644 --- a/samples/SampleWebApi.Shared/Services/ApiKeyAuthenticationServiceFactory.cs +++ b/samples/SampleWebApi.Shared/Services/ApiKeyAuthenticationServiceFactory.cs @@ -1,11 +1,10 @@ -using AspNetCore.Authentication.ApiKey; -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; using SampleWebApi.Repositories; using System.Diagnostics; namespace SampleWebApi.Services { - internal class ApiKeyAuthenticationServiceFactory : IApiKeyAuthenticationServiceFactory + internal class ApiKeyAuthenticationServiceFactory : MadEyeMatt.AspNetCore.Authentication.ApiKey.IApiKeyAuthenticationServiceFactory { private readonly ILoggerFactory loggerFactory; private readonly IApiKeyRepository apiKeyRepository; @@ -17,7 +16,7 @@ public ApiKeyAuthenticationServiceFactory(ILoggerFactory loggerFactory, IApiKeyR } /// - public IApiKeyAuthenticationService CreateApiKeyAuthenticationService(string authenticationSchemaName) + public MadEyeMatt.AspNetCore.Authentication.ApiKey.IApiKeyAuthenticationService CreateApiKeyAuthenticationService(string authenticationSchemaName) { Debug.WriteLine(authenticationSchemaName); return new ApiKeyAuthenticationService(loggerFactory.CreateLogger(), this.apiKeyRepository); diff --git a/samples/SampleWebApi_6_0/Controllers/ValuesController.cs b/samples/SampleWebApi/Controllers/ValuesController.cs similarity index 81% rename from samples/SampleWebApi_6_0/Controllers/ValuesController.cs rename to samples/SampleWebApi/Controllers/ValuesController.cs index 9e2cfb6..12e71fb 100644 --- a/samples/SampleWebApi_6_0/Controllers/ValuesController.cs +++ b/samples/SampleWebApi/Controllers/ValuesController.cs @@ -1,12 +1,11 @@ -using Microsoft.AspNetCore.Mvc; -using System.Collections.Generic; -using System.Text; - -namespace SampleWebApi_6_0.Controllers +namespace SampleWebApi.Controllers { - using Microsoft.AspNetCore.Authorization; + using System.Collections.Generic; + using System.Text; + using Microsoft.AspNetCore.Authorization; + using Microsoft.AspNetCore.Mvc; - [Route("api/[controller]")] + [Route("api/[controller]")] [ApiController] public class ValuesController : ControllerBase { diff --git a/samples/SampleWebApi_6_0/Program.cs b/samples/SampleWebApi/Program.cs similarity index 89% rename from samples/SampleWebApi_6_0/Program.cs rename to samples/SampleWebApi/Program.cs index ae1e4b2..48c0ec0 100644 --- a/samples/SampleWebApi_6_0/Program.cs +++ b/samples/SampleWebApi/Program.cs @@ -1,9 +1,9 @@ -using AspNetCore.Authentication.ApiKey; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using SampleWebApi.Repositories; using SampleWebApi.Services; +using ApiKeyExtensions = MadEyeMatt.AspNetCore.Authentication.ApiKey.ApiKeyExtensions; var builder = WebApplication.CreateBuilder(args); @@ -13,15 +13,7 @@ // Add the ApiKey scheme authentication here.. // It requires Realm to be set in the options if SuppressWWWAuthenticateHeader is not set. // If an implementation of IApiKeyProvider interface is registered in the dependency register as well as OnValidateKey delegete on options.Events is also set then this delegate will be used instead of an implementation of IApiKeyProvider. -builder.Services.AddAuthentication(ApiKeyDefaults.AuthenticationScheme) - - // The below AddApiKeyInHeaderOrQueryParams without type parameter will require OnValidateKey delegete on options.Events to be set unless an implementation of IApiKeyProvider interface is registered in the dependency register. - // Please note if OnValidateKey delegete on options.Events is also set then this delegate will be used instead of ApiKeyProvider.* - //.AddApiKeyInHeaderOrQueryParams(options => - - // The below AddApiKeyInHeaderOrQueryParams with type parameter will add the ApiKeyProvider to the dependency register. - // Please note if OnValidateKey delegete on options.Events is also set then this delegate will be used instead of ApiKeyProvider. - .AddApiKeyInHeaderOrQueryParams(options => +ApiKeyExtensions.AddApiKeyInHeaderOrQueryParams(builder.Services.AddAuthentication(MadEyeMatt.AspNetCore.Authentication.ApiKey.ApiKeyDefaults.AuthenticationScheme), options => { options.Realm = "Sample Web API"; options.KeyName = "X-API-KEY"; @@ -37,7 +29,7 @@ //// Optional events to override the ApiKey original logic with custom logic. //// Only use this if you know what you are doing at your own risk. Any of the events can be assigned. - options.Events = new ApiKeyEvents + options.Events = new MadEyeMatt.AspNetCore.Authentication.ApiKey.Events.ApiKeyEvents { //// A delegate assigned to this property will be invoked just before validating the api key. diff --git a/samples/SampleWebApi_6_0/Program_Factory.cs b/samples/SampleWebApi/Program_Factory.cs similarity index 100% rename from samples/SampleWebApi_6_0/Program_Factory.cs rename to samples/SampleWebApi/Program_Factory.cs diff --git a/samples/SampleWebApi_6_0/Properties/launchSettings.json b/samples/SampleWebApi/Properties/launchSettings.json similarity index 100% rename from samples/SampleWebApi_6_0/Properties/launchSettings.json rename to samples/SampleWebApi/Properties/launchSettings.json diff --git a/samples/SampleWebApi_6_0/SampleWebApi_6_0.csproj b/samples/SampleWebApi/SampleWebApi.csproj similarity index 90% rename from samples/SampleWebApi_6_0/SampleWebApi_6_0.csproj rename to samples/SampleWebApi/SampleWebApi.csproj index ce197df..4c9a1bc 100644 --- a/samples/SampleWebApi_6_0/SampleWebApi_6_0.csproj +++ b/samples/SampleWebApi/SampleWebApi.csproj @@ -1,7 +1,7 @@  - net6.0 + net7.0 latest disable disable diff --git a/samples/SampleWebApi_6_0/appsettings.Development.json b/samples/SampleWebApi/appsettings.Development.json similarity index 100% rename from samples/SampleWebApi_6_0/appsettings.Development.json rename to samples/SampleWebApi/appsettings.Development.json diff --git a/samples/SampleWebApi_6_0/appsettings.json b/samples/SampleWebApi/appsettings.json similarity index 100% rename from samples/SampleWebApi_6_0/appsettings.json rename to samples/SampleWebApi/appsettings.json diff --git a/src/AspNetCore.Authentication.ApiKey/ApiKeyDefaults.cs b/src/AspNetCore.Authentication.ApiKey/ApiKeyDefaults.cs index 495097f..6aed70e 100644 --- a/src/AspNetCore.Authentication.ApiKey/ApiKeyDefaults.cs +++ b/src/AspNetCore.Authentication.ApiKey/ApiKeyDefaults.cs @@ -1,7 +1,7 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -namespace AspNetCore.Authentication.ApiKey +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey { /// /// Default values used by api key authentication. diff --git a/src/AspNetCore.Authentication.ApiKey/ApiKeyExtensions.cs b/src/AspNetCore.Authentication.ApiKey/ApiKeyExtensions.cs index 774ef08..3596850 100644 --- a/src/AspNetCore.Authentication.ApiKey/ApiKeyExtensions.cs +++ b/src/AspNetCore.Authentication.ApiKey/ApiKeyExtensions.cs @@ -1,15 +1,15 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using Microsoft.AspNetCore.Authentication; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; -using Microsoft.Extensions.Options; -using System; - -namespace AspNetCore.Authentication.ApiKey +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey { - /// + using System; + using Microsoft.AspNetCore.Authentication; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.DependencyInjection.Extensions; + using Microsoft.Extensions.Options; + + /// /// Extension methods for api key authentication. /// public static class ApiKeyExtensions @@ -18,7 +18,7 @@ public static class ApiKeyExtensions /// /// Adds API Key - In Header authentication scheme to the project. - /// delegate must be set on the . + /// delegate must be set on the . /// /// /// The instance of @@ -27,7 +27,7 @@ public static AuthenticationBuilder AddApiKeyInHeader(this AuthenticationBuilder /// /// Adds API Key - In Header authentication scheme to the project. - /// delegate must be set on the . + /// delegate must be set on the . /// /// /// The authentication scheme. @@ -37,7 +37,7 @@ public static AuthenticationBuilder AddApiKeyInHeader(this AuthenticationBuilder /// /// Adds API Key - In Header authentication scheme to the project. - /// delegate must be set on the Events property on . + /// delegate must be set on the Events property on . /// /// /// The configure options. @@ -47,7 +47,7 @@ public static AuthenticationBuilder AddApiKeyInHeader(this AuthenticationBuilder /// /// Adds API Key - In Header authentication scheme to the project. - /// delegate must be set on the Events property on . + /// delegate must be set on the Events property on . /// /// /// The authentication scheme. @@ -58,7 +58,7 @@ public static AuthenticationBuilder AddApiKeyInHeader(this AuthenticationBuilder /// /// Adds API Key - In Header authentication scheme to the project. - /// delegate must be set on the Events property on . + /// delegate must be set on the Events property on . /// /// /// The authentication scheme. @@ -74,7 +74,7 @@ public static AuthenticationBuilder AddApiKeyInHeader(this AuthenticationBuilder /// /// Adds API Key - In Header authentication scheme to the project. It takes a implementation of as type parameter. - /// If delegate is set on the then it will be used instead of implementation of . + /// If delegate is set on the then it will be used instead of implementation of . /// /// /// @@ -84,7 +84,7 @@ public static AuthenticationBuilder AddApiKeyInHeader(this Auth /// /// Adds API Key - In Header authentication scheme to the project. It takes a implementation of as type parameter. - /// If delegate is set on the then it will be used instead of implementation of . + /// If delegate is set on the then it will be used instead of implementation of . /// /// /// @@ -95,7 +95,7 @@ public static AuthenticationBuilder AddApiKeyInHeader(this Auth /// /// Adds API Key - In Header authentication scheme to the project. It takes a implementation of as type parameter. - /// If delegate is set on the Events property on then it will be used instead of implementation of . + /// If delegate is set on the Events property on then it will be used instead of implementation of . /// /// /// @@ -106,7 +106,7 @@ public static AuthenticationBuilder AddApiKeyInHeader(this Auth /// /// Adds API Key - In Header authentication scheme to the project. It takes a implementation of as type parameter. - /// If delegate is set on the Events property on then it will be used instead of implementation of . + /// If delegate is set on the Events property on then it will be used instead of implementation of . /// /// /// @@ -118,7 +118,7 @@ public static AuthenticationBuilder AddApiKeyInHeader(this Auth /// /// Adds API Key - In Header authentication scheme to the project. It takes a implementation of as type parameter. - /// If delegate is set on the Events property on then it will be used instead of implementation of . + /// If delegate is set on the Events property on then it will be used instead of implementation of . /// /// /// @@ -135,7 +135,7 @@ public static AuthenticationBuilder AddApiKeyInHeader(this Auth /// /// Adds API Key - In Authorization Header authentication scheme to the project. - /// delegate must be set on the . + /// delegate must be set on the . /// /// /// The instance of @@ -144,7 +144,7 @@ public static AuthenticationBuilder AddApiKeyInAuthorizationHeader(this Authenti /// /// Adds API Key - In Authorization Header authentication scheme to the project. - /// delegate must be set on the . + /// delegate must be set on the . /// /// /// The authentication scheme. @@ -154,7 +154,7 @@ public static AuthenticationBuilder AddApiKeyInAuthorizationHeader(this Authenti /// /// Adds API Key - In Authorization Header authentication scheme to the project. - /// delegate must be set on the Events property on . + /// delegate must be set on the Events property on . /// /// /// The configure options. @@ -164,7 +164,7 @@ public static AuthenticationBuilder AddApiKeyInAuthorizationHeader(this Authenti /// /// Adds API Key - In Authorization Header authentication scheme to the project. - /// delegate must be set on the Events property on . + /// delegate must be set on the Events property on . /// /// /// The authentication scheme. @@ -175,7 +175,7 @@ public static AuthenticationBuilder AddApiKeyInAuthorizationHeader(this Authenti /// /// Adds API Key - In Authorization Header authentication scheme to the project. - /// delegate must be set on the Events property on . + /// delegate must be set on the Events property on . /// /// /// The authentication scheme. @@ -191,7 +191,7 @@ public static AuthenticationBuilder AddApiKeyInAuthorizationHeader(this Authenti /// /// Adds API Key - In Authorization Header authentication scheme to the project. It takes a implementation of as type parameter. - /// If delegate is set on the then it will be used instead of implementation of . + /// If delegate is set on the then it will be used instead of implementation of . /// /// /// @@ -201,7 +201,7 @@ public static AuthenticationBuilder AddApiKeyInAuthorizationHeader /// Adds API Key - In Authorization Header authentication scheme to the project. It takes a implementation of as type parameter. - /// If delegate is set on the then it will be used instead of implementation of . + /// If delegate is set on the then it will be used instead of implementation of . /// /// /// @@ -212,7 +212,7 @@ public static AuthenticationBuilder AddApiKeyInAuthorizationHeader /// Adds API Key - In Authorization Header authentication scheme to the project. It takes a implementation of as type parameter. - /// If delegate is set on the Events property on then it will be used instead of implementation of . + /// If delegate is set on the Events property on then it will be used instead of implementation of . /// /// /// @@ -223,7 +223,7 @@ public static AuthenticationBuilder AddApiKeyInAuthorizationHeader /// Adds API Key - In Authorization Header authentication scheme to the project. It takes a implementation of as type parameter. - /// If delegate is set on the Events property on then it will be used instead of implementation of . + /// If delegate is set on the Events property on then it will be used instead of implementation of . /// /// /// @@ -235,7 +235,7 @@ public static AuthenticationBuilder AddApiKeyInAuthorizationHeader /// Adds API Key - In Authorization Header authentication scheme to the project. It takes a implementation of as type parameter. - /// If delegate is set on the Events property on then it will be used instead of implementation of . + /// If delegate is set on the Events property on then it will be used instead of implementation of . /// /// /// @@ -252,7 +252,7 @@ public static AuthenticationBuilder AddApiKeyInAuthorizationHeader /// Adds API Key - In Query Parameters authentication scheme to the project. - /// delegate must be set on the . + /// delegate must be set on the . /// /// /// The instance of @@ -261,7 +261,7 @@ public static AuthenticationBuilder AddApiKeyInQueryParams(this AuthenticationBu /// /// Adds API Key - In Query Parameters authentication scheme to the project. - /// delegate must be set on the . + /// delegate must be set on the . /// /// /// The authentication scheme. @@ -271,7 +271,7 @@ public static AuthenticationBuilder AddApiKeyInQueryParams(this AuthenticationBu /// /// Adds API Key - In Query Parameters authentication scheme to the project. - /// delegate must be set on the Events property on . + /// delegate must be set on the Events property on . /// /// /// The configure options. @@ -281,7 +281,7 @@ public static AuthenticationBuilder AddApiKeyInQueryParams(this AuthenticationBu /// /// Adds API Key - In Query Parameters authentication scheme to the project. - /// delegate must be set on the Events property on . + /// delegate must be set on the Events property on . /// /// /// The authentication scheme. @@ -292,7 +292,7 @@ public static AuthenticationBuilder AddApiKeyInQueryParams(this AuthenticationBu /// /// Adds API Key - In Query Parameters authentication scheme to the project. - /// delegate must be set on the Events property on . + /// delegate must be set on the Events property on . /// /// /// The authentication scheme. @@ -308,7 +308,7 @@ public static AuthenticationBuilder AddApiKeyInQueryParams(this AuthenticationBu /// /// Adds API Key - In Query Parameters authentication scheme to the project. It takes a implementation of as type parameter. - /// If delegate is set on the then it will be used instead of implementation of . + /// If delegate is set on the then it will be used instead of implementation of . /// /// /// @@ -318,7 +318,7 @@ public static AuthenticationBuilder AddApiKeyInQueryParams(this /// /// Adds API Key - In Query Parameters authentication scheme to the project. It takes a implementation of as type parameter. - /// If delegate is set on the then it will be used instead of implementation of . + /// If delegate is set on the then it will be used instead of implementation of . /// /// /// @@ -329,7 +329,7 @@ public static AuthenticationBuilder AddApiKeyInQueryParams(this /// /// Adds API Key - In Query Parameters authentication scheme to the project. It takes a implementation of as type parameter. - /// If delegate is set on the Events property on then it will be used instead of implementation of . + /// If delegate is set on the Events property on then it will be used instead of implementation of . /// /// /// @@ -340,7 +340,7 @@ public static AuthenticationBuilder AddApiKeyInQueryParams(this /// /// Adds API Key - In Query Parameters authentication scheme to the project. It takes a implementation of as type parameter. - /// If delegate is set on the Events property on then it will be used instead of implementation of . + /// If delegate is set on the Events property on then it will be used instead of implementation of . /// /// /// @@ -352,7 +352,7 @@ public static AuthenticationBuilder AddApiKeyInQueryParams(this /// /// Adds API Key - In Query Parameters authentication scheme to the project. It takes a implementation of as type parameter. - /// If delegate is set on the Events property on then it will be used instead of implementation of . + /// If delegate is set on the Events property on then it will be used instead of implementation of . /// /// /// @@ -369,7 +369,7 @@ public static AuthenticationBuilder AddApiKeyInQueryParams(this /// /// Adds API Key - In Header Or Query Parameters authentication scheme to the project. - /// delegate must be set on the . + /// delegate must be set on the . /// /// /// The instance of @@ -378,7 +378,7 @@ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams(this Authenti /// /// Adds API Key - In Header Or Query Parameters authentication scheme to the project. - /// delegate must be set on the . + /// delegate must be set on the . /// /// /// The authentication scheme. @@ -388,7 +388,7 @@ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams(this Authenti /// /// Adds API Key - In Header Or Query Parameters authentication scheme to the project. - /// delegate must be set on the Events property on . + /// delegate must be set on the Events property on . /// /// /// The configure options. @@ -398,7 +398,7 @@ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams(this Authenti /// /// Adds API Key - In Header Or Query Parameters authentication scheme to the project. - /// delegate must be set on the Events property on . + /// delegate must be set on the Events property on . /// /// /// The authentication scheme. @@ -409,7 +409,7 @@ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams(this Authenti /// /// Adds API Key - In Header Or Query Parameters authentication scheme to the project. - /// delegate must be set on the Events property on . + /// delegate must be set on the Events property on . /// /// /// The authentication scheme. @@ -425,7 +425,7 @@ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams(this Authenti /// /// Adds API Key - In Header Or Query Parameters authentication scheme to the project. It takes a implementation of as type parameter. - /// If delegate is set on the then it will be used instead of implementation of . + /// If delegate is set on the then it will be used instead of implementation of . /// /// /// @@ -435,7 +435,7 @@ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams /// Adds API Key - In Header Or Query Parameters authentication scheme to the project. It takes a implementation of as type parameter. - /// If delegate is set on the then it will be used instead of implementation of . + /// If delegate is set on the then it will be used instead of implementation of . /// /// /// @@ -446,7 +446,7 @@ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams /// Adds API Key - In Header Or Query Parameters authentication scheme to the project. It takes a implementation of as type parameter. - /// If delegate is set on the Events property on then it will be used instead of implementation of . + /// If delegate is set on the Events property on then it will be used instead of implementation of . /// /// /// @@ -457,7 +457,7 @@ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams /// Adds API Key - In Header Or Query Parameters authentication scheme to the project. It takes a implementation of as type parameter. - /// If delegate is set on the Events property on then it will be used instead of implementation of . + /// If delegate is set on the Events property on then it will be used instead of implementation of . /// /// /// @@ -469,7 +469,7 @@ public static AuthenticationBuilder AddApiKeyInHeaderOrQueryParams /// Adds API Key - In Header Or Query Parameters authentication scheme to the project. It takes a implementation of as type parameter. - /// If delegate is set on the Events property on then it will be used instead of implementation of . + /// If delegate is set on the Events property on then it will be used instead of implementation of . /// /// /// diff --git a/src/AspNetCore.Authentication.ApiKey/ApiKeyHandlerBase.cs b/src/AspNetCore.Authentication.ApiKey/ApiKeyHandlerBase.cs index 379f571..7e00880 100644 --- a/src/AspNetCore.Authentication.ApiKey/ApiKeyHandlerBase.cs +++ b/src/AspNetCore.Authentication.ApiKey/ApiKeyHandlerBase.cs @@ -1,19 +1,19 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; -using Microsoft.Net.Http.Headers; -using System; -using System.Text.Encodings.Web; -using System.Threading.Tasks; - -namespace AspNetCore.Authentication.ApiKey +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey { - /// + using System; + using System.Text.Encodings.Web; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Authentication; + using Microsoft.AspNetCore.Http; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.Logging; + using Microsoft.Extensions.Options; + using Microsoft.Net.Http.Headers; + + /// /// Inherited from for api key authentication. /// public abstract class ApiKeyHandlerBase : AuthenticationHandler @@ -26,15 +26,15 @@ protected ApiKeyHandlerBase(IOptionsMonitor options, ILoggerFacto private string Challenge => $"{GetWwwAuthenticateSchemeName()} realm=\"{Options.Realm}\", charset=\"UTF-8\", in=\"{GetWwwAuthenticateInParameter()}\", key_name=\"{Options.KeyName}\""; /// - /// Get or set . + /// Get or set . /// - protected new ApiKeyEvents Events { get => (ApiKeyEvents)base.Events; set => base.Events = value; } + protected new MadEyeMatt.AspNetCore.Authentication.ApiKey.Events.ApiKeyEvents Events { get => (MadEyeMatt.AspNetCore.Authentication.ApiKey.Events.ApiKeyEvents)base.Events; set => base.Events = value; } /// - /// Create an instance of . + /// Create an instance of . /// /// - protected override Task CreateEventsAsync() => Task.FromResult(new ApiKeyEvents()); + protected override Task CreateEventsAsync() => Task.FromResult(new MadEyeMatt.AspNetCore.Authentication.ApiKey.Events.ApiKeyEvents()); protected abstract Task ParseApiKeyAsync(); @@ -86,7 +86,7 @@ protected override async Task HandleAuthenticateAsync() } catch (Exception exception) { - var authenticationFailedContext = new ApiKeyAuthenticationFailedContext(Context, Scheme, Options, exception); + var authenticationFailedContext = new MadEyeMatt.AspNetCore.Authentication.ApiKey.Events.ApiKeyAuthenticationFailedContext(Context, Scheme, Options, exception); await Events.AuthenticationFailedAsync(authenticationFailedContext).ConfigureAwait(false); if (authenticationFailedContext.Result != null) @@ -102,7 +102,7 @@ protected override async Task HandleAuthenticateAsync() protected override async Task HandleForbiddenAsync(AuthenticationProperties properties) { // Raise handle forbidden event. - var handleForbiddenContext = new ApiKeyHandleForbiddenContext(Context, Scheme, Options, properties); + var handleForbiddenContext = new MadEyeMatt.AspNetCore.Authentication.ApiKey.Events.ApiKeyHandleForbiddenContext(Context, Scheme, Options, properties); await Events.HandleForbiddenAsync(handleForbiddenContext).ConfigureAwait(false); if (handleForbiddenContext.IsHandled) { @@ -124,7 +124,7 @@ protected override async Task HandleForbiddenAsync(AuthenticationProperties prop protected override async Task HandleChallengeAsync(AuthenticationProperties properties) { // Raise handle challenge event. - var handleChallengeContext = new ApiKeyHandleChallengeContext(Context, Scheme, Options, properties); + var handleChallengeContext = new MadEyeMatt.AspNetCore.Authentication.ApiKey.Events.ApiKeyHandleChallengeContext(Context, Scheme, Options, properties); await Events.HandleChallengeAsync(handleChallengeContext).ConfigureAwait(false); if (handleChallengeContext.IsHandled) { @@ -140,7 +140,7 @@ protected override async Task HandleChallengeAsync(AuthenticationProperties prop private async Task RaiseAndHandleEventValidateKeyAsync(string apiKey) { - var validateApiContext = new ApiKeyValidateKeyContext(Context, Scheme, Options, apiKey); + var validateApiContext = new MadEyeMatt.AspNetCore.Authentication.ApiKey.Events.ApiKeyValidateKeyContext(Context, Scheme, Options, apiKey); await Events.ValidateKeyAsync(validateApiContext).ConfigureAwait(false); if (validateApiContext.Result != null) @@ -164,7 +164,7 @@ private async Task RaiseAndHandleAuthenticationSucceededAsyn var principal = ApiKeyUtils.BuildClaimsPrincipal(apiKey.OwnerName, Scheme.Name, ClaimsIssuer, apiKey.Claims); // Raise authentication succeeded event. - var authenticationSucceededContext = new ApiKeyAuthenticationSucceededContext(Context, Scheme, Options, principal); + var authenticationSucceededContext = new MadEyeMatt.AspNetCore.Authentication.ApiKey.Events.ApiKeyAuthenticationSucceededContext(Context, Scheme, Options, principal); await Events.AuthenticationSucceededAsync(authenticationSucceededContext).ConfigureAwait(false); if (authenticationSucceededContext.Result != null) diff --git a/src/AspNetCore.Authentication.ApiKey/ApiKeyInAuthorizationHeaderHandler.cs b/src/AspNetCore.Authentication.ApiKey/ApiKeyInAuthorizationHeaderHandler.cs index ca4b08e..bedf40c 100644 --- a/src/AspNetCore.Authentication.ApiKey/ApiKeyInAuthorizationHeaderHandler.cs +++ b/src/AspNetCore.Authentication.ApiKey/ApiKeyInAuthorizationHeaderHandler.cs @@ -1,17 +1,17 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using Microsoft.AspNetCore.Authentication; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; -using Microsoft.Net.Http.Headers; -using System; -using System.Net.Http.Headers; -using System.Text.Encodings.Web; -using System.Threading.Tasks; - -namespace AspNetCore.Authentication.ApiKey +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey { + using System; + using System.Net.Http.Headers; + using System.Text.Encodings.Web; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Authentication; + using Microsoft.Extensions.Logging; + using Microsoft.Extensions.Options; + using Microsoft.Net.Http.Headers; + public class ApiKeyInAuthorizationHeaderHandler : ApiKeyHandlerBase { public ApiKeyInAuthorizationHeaderHandler(IOptionsMonitor options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) diff --git a/src/AspNetCore.Authentication.ApiKey/ApiKeyInHeaderHandler.cs b/src/AspNetCore.Authentication.ApiKey/ApiKeyInHeaderHandler.cs index 6f0b9ff..783fbfe 100644 --- a/src/AspNetCore.Authentication.ApiKey/ApiKeyInHeaderHandler.cs +++ b/src/AspNetCore.Authentication.ApiKey/ApiKeyInHeaderHandler.cs @@ -1,16 +1,16 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using Microsoft.AspNetCore.Authentication; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; -using System.Linq; -using System.Text.Encodings.Web; -using System.Threading.Tasks; - -namespace AspNetCore.Authentication.ApiKey +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey { - public class ApiKeyInHeaderHandler : ApiKeyHandlerBase + using System.Linq; + using System.Text.Encodings.Web; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Authentication; + using Microsoft.Extensions.Logging; + using Microsoft.Extensions.Options; + + public class ApiKeyInHeaderHandler : ApiKeyHandlerBase { public ApiKeyInHeaderHandler(IOptionsMonitor options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) : base(options, logger, encoder, clock) diff --git a/src/AspNetCore.Authentication.ApiKey/ApiKeyInHeaderOrQueryParamsHandler.cs b/src/AspNetCore.Authentication.ApiKey/ApiKeyInHeaderOrQueryParamsHandler.cs index f5f50fd..560f0f4 100644 --- a/src/AspNetCore.Authentication.ApiKey/ApiKeyInHeaderOrQueryParamsHandler.cs +++ b/src/AspNetCore.Authentication.ApiKey/ApiKeyInHeaderOrQueryParamsHandler.cs @@ -1,19 +1,19 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using Microsoft.AspNetCore.Authentication; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; -using Microsoft.Net.Http.Headers; -using System; -using System.Linq; -using System.Net.Http.Headers; -using System.Text.Encodings.Web; -using System.Threading.Tasks; - -namespace AspNetCore.Authentication.ApiKey +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey { - public class ApiKeyInHeaderOrQueryParamsHandler : ApiKeyHandlerBase + using System; + using System.Linq; + using System.Net.Http.Headers; + using System.Text.Encodings.Web; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Authentication; + using Microsoft.Extensions.Logging; + using Microsoft.Extensions.Options; + using Microsoft.Net.Http.Headers; + + public class ApiKeyInHeaderOrQueryParamsHandler : ApiKeyHandlerBase { public ApiKeyInHeaderOrQueryParamsHandler(IOptionsMonitor options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) : base(options, logger, encoder, clock) diff --git a/src/AspNetCore.Authentication.ApiKey/ApiKeyInQueryParamsHandler.cs b/src/AspNetCore.Authentication.ApiKey/ApiKeyInQueryParamsHandler.cs index 42ab982..4dca309 100644 --- a/src/AspNetCore.Authentication.ApiKey/ApiKeyInQueryParamsHandler.cs +++ b/src/AspNetCore.Authentication.ApiKey/ApiKeyInQueryParamsHandler.cs @@ -1,16 +1,16 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using Microsoft.AspNetCore.Authentication; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; -using System.Linq; -using System.Text.Encodings.Web; -using System.Threading.Tasks; - -namespace AspNetCore.Authentication.ApiKey +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey { - public class ApiKeyInQueryParamsHandler : ApiKeyHandlerBase + using System.Linq; + using System.Text.Encodings.Web; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Authentication; + using Microsoft.Extensions.Logging; + using Microsoft.Extensions.Options; + + public class ApiKeyInQueryParamsHandler : ApiKeyHandlerBase { public ApiKeyInQueryParamsHandler(IOptionsMonitor options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) : base(options, logger, encoder, clock) diff --git a/src/AspNetCore.Authentication.ApiKey/ApiKeyOptions.cs b/src/AspNetCore.Authentication.ApiKey/ApiKeyOptions.cs index d3901cb..ddb75ec 100644 --- a/src/AspNetCore.Authentication.ApiKey/ApiKeyOptions.cs +++ b/src/AspNetCore.Authentication.ApiKey/ApiKeyOptions.cs @@ -1,11 +1,11 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using Microsoft.AspNetCore.Authentication; -using System; - -namespace AspNetCore.Authentication.ApiKey +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey { + using System; + using Microsoft.AspNetCore.Authentication; + /// /// Inherited from to allow extra option properties for 'ApiKey' authentication. /// @@ -13,7 +13,7 @@ public class ApiKeyOptions : AuthenticationSchemeOptions { public ApiKeyOptions() { - Events = new ApiKeyEvents(); + Events = new MadEyeMatt.AspNetCore.Authentication.ApiKey.Events.ApiKeyEvents(); } /// @@ -39,12 +39,12 @@ public ApiKeyOptions() /// /// The object provided by the application to process events raised by the api key authentication middleware. - /// The application may implement the interface fully, or it may create an instance of + /// The application may implement the interface fully, or it may create an instance of /// and assign delegates only to the events it wants to process. /// - public new ApiKeyEvents Events + public new MadEyeMatt.AspNetCore.Authentication.ApiKey.Events.ApiKeyEvents Events { - get => (ApiKeyEvents)base.Events; + get => (MadEyeMatt.AspNetCore.Authentication.ApiKey.Events.ApiKeyEvents)base.Events; set => base.Events = value; } diff --git a/src/AspNetCore.Authentication.ApiKey/ApiKeyPostConfigureOptions.cs b/src/AspNetCore.Authentication.ApiKey/ApiKeyPostConfigureOptions.cs index 98b2663..8b0338b 100644 --- a/src/AspNetCore.Authentication.ApiKey/ApiKeyPostConfigureOptions.cs +++ b/src/AspNetCore.Authentication.ApiKey/ApiKeyPostConfigureOptions.cs @@ -1,14 +1,13 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using System; -using Microsoft.Extensions.Options; - -namespace AspNetCore.Authentication.ApiKey +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey { - using Microsoft.Extensions.DependencyInjection; + using System; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.Options; - /// + /// /// This post configure options checks whether the required option properties are set or not on . /// class ApiKeyPostConfigureOptions : IPostConfigureOptions diff --git a/src/AspNetCore.Authentication.ApiKey/ApiKeyUtils.cs b/src/AspNetCore.Authentication.ApiKey/ApiKeyUtils.cs index dc87ba8..3ba2c75 100644 --- a/src/AspNetCore.Authentication.ApiKey/ApiKeyUtils.cs +++ b/src/AspNetCore.Authentication.ApiKey/ApiKeyUtils.cs @@ -1,14 +1,14 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; - -namespace AspNetCore.Authentication.ApiKey +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey { - /// + using System; + using System.Collections.Generic; + using System.Linq; + using System.Security.Claims; + + /// /// Utility class. /// internal static class ApiKeyUtils diff --git a/src/AspNetCore.Authentication.ApiKey/AspNetCore.Authentication.ApiKey.csproj b/src/AspNetCore.Authentication.ApiKey/AspNetCore.Authentication.ApiKey.csproj index b830c31..851d6f2 100644 --- a/src/AspNetCore.Authentication.ApiKey/AspNetCore.Authentication.ApiKey.csproj +++ b/src/AspNetCore.Authentication.ApiKey/AspNetCore.Authentication.ApiKey.csproj @@ -1,7 +1,7 @@  - net6.0 + net7.0 latest disable disable @@ -10,11 +10,13 @@ MadEyeMatt.$(AssemblyName) + MadEyeMatt.$(MSBuildProjectName) + MadEyeMatt.$(MSBuildProjectName.Replace(" ", "_")) false Copyright © 2022 Mihir Dilip, Matthias Gernand. All rights reserved. - 6.3.0 - 6.3.0 - 6.3.0 + 7.0.0 + 7.0.0 + 7.0.0 Mihir Dilip, Matthias Gernand An easy to use and light weight Microsoft style API-Key authentication implementation for ASP.NET Core. en @@ -29,7 +31,7 @@ - + diff --git a/src/AspNetCore.Authentication.ApiKey/Events/ApiKeyAuthenticationFailedContext.cs b/src/AspNetCore.Authentication.ApiKey/Events/ApiKeyAuthenticationFailedContext.cs index 8224421..f4414c7 100644 --- a/src/AspNetCore.Authentication.ApiKey/Events/ApiKeyAuthenticationFailedContext.cs +++ b/src/AspNetCore.Authentication.ApiKey/Events/ApiKeyAuthenticationFailedContext.cs @@ -1,12 +1,12 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Http; -using System; - -namespace AspNetCore.Authentication.ApiKey +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey.Events { + using System; + using Microsoft.AspNetCore.Authentication; + using Microsoft.AspNetCore.Http; + /// /// Context used when authentication is failed. /// diff --git a/src/AspNetCore.Authentication.ApiKey/Events/ApiKeyAuthenticationSucceededContext.cs b/src/AspNetCore.Authentication.ApiKey/Events/ApiKeyAuthenticationSucceededContext.cs index f95db1d..94f72d3 100644 --- a/src/AspNetCore.Authentication.ApiKey/Events/ApiKeyAuthenticationSucceededContext.cs +++ b/src/AspNetCore.Authentication.ApiKey/Events/ApiKeyAuthenticationSucceededContext.cs @@ -1,14 +1,14 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Http; -using System; -using System.Collections.Generic; -using System.Security.Claims; - -namespace AspNetCore.Authentication.ApiKey +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey.Events { + using System; + using System.Collections.Generic; + using System.Security.Claims; + using Microsoft.AspNetCore.Authentication; + using Microsoft.AspNetCore.Http; + /// /// Context used when authentication is succeeded. /// diff --git a/src/AspNetCore.Authentication.ApiKey/Events/ApiKeyEvents.cs b/src/AspNetCore.Authentication.ApiKey/Events/ApiKeyEvents.cs index 5f1940c..c1d967a 100644 --- a/src/AspNetCore.Authentication.ApiKey/Events/ApiKeyEvents.cs +++ b/src/AspNetCore.Authentication.ApiKey/Events/ApiKeyEvents.cs @@ -1,11 +1,11 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using System; -using System.Threading.Tasks; - -namespace AspNetCore.Authentication.ApiKey +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey.Events { + using System; + using System.Threading.Tasks; + /// /// ApiKey Events. /// diff --git a/src/AspNetCore.Authentication.ApiKey/Events/ApiKeyHandleChallengeContext.cs b/src/AspNetCore.Authentication.ApiKey/Events/ApiKeyHandleChallengeContext.cs index b86b856..c3700f4 100644 --- a/src/AspNetCore.Authentication.ApiKey/Events/ApiKeyHandleChallengeContext.cs +++ b/src/AspNetCore.Authentication.ApiKey/Events/ApiKeyHandleChallengeContext.cs @@ -1,11 +1,11 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Http; - -namespace AspNetCore.Authentication.ApiKey +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey.Events { + using Microsoft.AspNetCore.Authentication; + using Microsoft.AspNetCore.Http; + /// /// Context used when challenging unauthorized response. /// diff --git a/src/AspNetCore.Authentication.ApiKey/Events/ApiKeyHandleForbiddenContext.cs b/src/AspNetCore.Authentication.ApiKey/Events/ApiKeyHandleForbiddenContext.cs index 8838cd9..97163de 100644 --- a/src/AspNetCore.Authentication.ApiKey/Events/ApiKeyHandleForbiddenContext.cs +++ b/src/AspNetCore.Authentication.ApiKey/Events/ApiKeyHandleForbiddenContext.cs @@ -1,11 +1,11 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Http; - -namespace AspNetCore.Authentication.ApiKey +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey.Events { + using Microsoft.AspNetCore.Authentication; + using Microsoft.AspNetCore.Http; + /// /// Context used when handling forbidden response. /// diff --git a/src/AspNetCore.Authentication.ApiKey/Events/ApiKeyValidateKeyContext.cs b/src/AspNetCore.Authentication.ApiKey/Events/ApiKeyValidateKeyContext.cs index 104e048..ae1f934 100644 --- a/src/AspNetCore.Authentication.ApiKey/Events/ApiKeyValidateKeyContext.cs +++ b/src/AspNetCore.Authentication.ApiKey/Events/ApiKeyValidateKeyContext.cs @@ -1,14 +1,14 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Http; -using System; -using System.Collections.Generic; -using System.Security.Claims; - -namespace AspNetCore.Authentication.ApiKey +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey.Events { + using System; + using System.Collections.Generic; + using System.Security.Claims; + using Microsoft.AspNetCore.Authentication; + using Microsoft.AspNetCore.Http; + /// /// Context used for validating key. /// diff --git a/src/AspNetCore.Authentication.ApiKey/IApiKey.cs b/src/AspNetCore.Authentication.ApiKey/IApiKey.cs index 671c208..38cd1b7 100644 --- a/src/AspNetCore.Authentication.ApiKey/IApiKey.cs +++ b/src/AspNetCore.Authentication.ApiKey/IApiKey.cs @@ -1,12 +1,12 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using System.Collections.Generic; -using System.Security.Claims; - -namespace AspNetCore.Authentication.ApiKey +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey { - /// + using System.Collections.Generic; + using System.Security.Claims; + + /// /// API Key Details /// public interface IApiKey diff --git a/src/AspNetCore.Authentication.ApiKey/IApiKeyAuthenticationService.cs b/src/AspNetCore.Authentication.ApiKey/IApiKeyAuthenticationService.cs index 8be9a2c..a004805 100644 --- a/src/AspNetCore.Authentication.ApiKey/IApiKeyAuthenticationService.cs +++ b/src/AspNetCore.Authentication.ApiKey/IApiKeyAuthenticationService.cs @@ -1,11 +1,11 @@ // Copyright (c) Mihir Dilip, Matthias Gernand. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using System.Threading.Tasks; - -namespace AspNetCore.Authentication.ApiKey +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey { - /// + using System.Threading.Tasks; + + /// /// Implementation of this interface will be used by the 'ApiKey' authentication handler to validated and get details from the key. /// public interface IApiKeyAuthenticationService diff --git a/src/AspNetCore.Authentication.ApiKey/IApiKeyAuthenticationServiceFactory.cs b/src/AspNetCore.Authentication.ApiKey/IApiKeyAuthenticationServiceFactory.cs index 8c5e537..7bb992c 100644 --- a/src/AspNetCore.Authentication.ApiKey/IApiKeyAuthenticationServiceFactory.cs +++ b/src/AspNetCore.Authentication.ApiKey/IApiKeyAuthenticationServiceFactory.cs @@ -1,7 +1,7 @@ // Copyright (c) Matthias Gernand. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -namespace AspNetCore.Authentication.ApiKey +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey { /// /// Implementation of this interface will be used by the 'ApiKey' authentication handler to get a schema specific . diff --git a/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyDefaultsTests.cs b/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyDefaultsTests.cs index a01760a..c571891 100644 --- a/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyDefaultsTests.cs +++ b/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyDefaultsTests.cs @@ -1,10 +1,10 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using Xunit; - -namespace AspNetCore.Authentication.ApiKey.Tests +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests { + using Xunit; + public class ApiKeyDefaultsTests { [Fact] diff --git a/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyExtensionsTests.cs b/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyExtensionsTests.cs index cd6ce5c..6a78c16 100644 --- a/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyExtensionsTests.cs +++ b/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyExtensionsTests.cs @@ -1,15 +1,15 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using Microsoft.AspNetCore.Authentication; -using Microsoft.Extensions.DependencyInjection; -using System; -using System.Linq; -using System.Threading.Tasks; -using Xunit; - -namespace AspNetCore.Authentication.ApiKey.Tests +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests { + using System; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Authentication; + using Microsoft.Extensions.DependencyInjection; + using Xunit; + public class ApiKeyExtensionsTests { #region API Key - In Header diff --git a/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyHandlerBaseTests.cs b/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyHandlerBaseTests.cs index 508b968..d5ffd8b 100644 --- a/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyHandlerBaseTests.cs +++ b/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyHandlerBaseTests.cs @@ -1,22 +1,21 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using AspNetCore.Authentication.ApiKey.Tests.Infrastructure; -using Microsoft.AspNetCore.Authorization; -using Microsoft.Extensions.DependencyInjection; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Security.Claims; -using System.Text.Json; -using System.Threading.Tasks; -using Xunit; - -namespace AspNetCore.Authentication.ApiKey.Tests +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests { + using System; + using System.Collections.Generic; + using System.Linq; + using System.Net; + using System.Net.Http; + using System.Net.Http.Headers; + using System.Security.Claims; + using System.Text.Json; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Authorization; + using Microsoft.Extensions.DependencyInjection; + using Xunit; + public class ApiKeyHandlerBaseTests { private const string HeaderFromEventsKey = nameof(HeaderFromEventsKey); @@ -27,10 +26,10 @@ public class ApiKeyHandlerBaseTests [Fact] public async Task HandleForbidden() { - using var server = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(); + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(); using var client = server.CreateClient(); - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.ForbiddenUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.ForbiddenUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await client.SendAsync(request); Assert.False(response.IsSuccessStatusCode); @@ -41,10 +40,10 @@ public async Task HandleForbidden() [Fact] public async Task HandleForbidden_using_OnHandleForbidden() { - using var server = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => { - options.Realm = TestServerBuilder.Realm; - options.KeyName = FakeApiKeys.KeyName; + options.Realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; + options.KeyName = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName; options.Events.OnHandleForbidden = context => { context.HttpContext.Response.Headers.Add(HeaderFromEventsKey, HeaderFromEventsValue); @@ -52,8 +51,8 @@ public async Task HandleForbidden_using_OnHandleForbidden() }; }); using var client = server.CreateClient(); - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.ForbiddenUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.ForbiddenUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await client.SendAsync(request); Assert.False(response.IsSuccessStatusCode); @@ -69,9 +68,9 @@ public async Task HandleForbidden_using_OnHandleForbidden() [Fact] public async Task HandleChallange() { - using var server = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(); + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(); using var client = server.CreateClient(); - using var response = await client.GetAsync(TestServerBuilder.BaseUrl); + using var response = await client.GetAsync(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -81,10 +80,10 @@ public async Task HandleChallange() [Fact] public async Task HandleChallange_using_OnHandleChallenge() { - using var server = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => { - options.Realm = TestServerBuilder.Realm; - options.KeyName = FakeApiKeys.KeyName; + options.Realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; + options.KeyName = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName; options.Events.OnHandleChallenge = context => { context.HttpContext.Response.Headers.Add(HeaderFromEventsKey, HeaderFromEventsValue); @@ -92,7 +91,7 @@ public async Task HandleChallange_using_OnHandleChallenge() }; }); using var client = server.CreateClient(); - using var response = await client.GetAsync(TestServerBuilder.BaseUrl); + using var response = await client.GetAsync(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -104,14 +103,14 @@ public async Task HandleChallange_using_OnHandleChallenge() [Fact] public async Task HandleChallange_using_SuppressWWWAuthenticateHeader() { - using var server = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => { - options.Realm = TestServerBuilder.Realm; - options.KeyName = FakeApiKeys.KeyName; + options.Realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; + options.KeyName = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName; options.SuppressWWWAuthenticateHeader = true; }); using var client = server.CreateClient(); - using var response = await client.GetAsync(TestServerBuilder.BaseUrl); + using var response = await client.GetAsync(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -121,10 +120,10 @@ public async Task HandleChallange_using_SuppressWWWAuthenticateHeader() [Fact] public async Task HandleChallange_using_OnHandleChallenge_and_SuppressWWWAuthenticateHeader() { - using var server = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => { - options.Realm = TestServerBuilder.Realm; - options.KeyName = FakeApiKeys.KeyName; + options.Realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; + options.KeyName = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName; options.SuppressWWWAuthenticateHeader = true; options.Events.OnHandleChallenge = context => { @@ -133,7 +132,7 @@ public async Task HandleChallange_using_OnHandleChallenge_and_SuppressWWWAuthent }; }); using var client = server.CreateClient(); - using var response = await client.GetAsync(TestServerBuilder.BaseUrl); + using var response = await client.GetAsync(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -151,9 +150,9 @@ public async Task HandleChallange_using_OnHandleChallenge_and_SuppressWWWAuthent [Fact] public async Task HandleAuthenticate_IgnoreAuthenticationIfAllowAnonymous() { - using var server = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(); + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(); using var client = server.CreateClient(); - using var response = await client.GetAsync(TestServerBuilder.AnonymousUrl); + using var response = await client.GetAsync(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.AnonymousUrl); var principal = await DeserializeClaimsPrincipalAsync(response); Assert.True(response.IsSuccessStatusCode); @@ -166,10 +165,10 @@ public async Task HandleAuthenticate_IgnoreAuthenticationIfAllowAnonymous() [Fact] public async Task HandleAuthenticate_ParseApiKey_empty() { - using var server = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(); + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(); using var client = server.CreateClient(); - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Add(FakeApiKeys.KeyName, string.Empty); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, string.Empty); using var response = await client.SendAsync(request); Assert.False(response.IsSuccessStatusCode); @@ -179,10 +178,10 @@ public async Task HandleAuthenticate_ParseApiKey_empty() [Fact] public async Task HandleAuthenticate_OnValidateKey_result_not_null() { - using var server = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => { - options.Realm = TestServerBuilder.Realm; - options.KeyName = FakeApiKeys.KeyName; + options.Realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; + options.KeyName = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName; options.Events.OnValidateKey = context => { context.ValidationSucceeded(); @@ -193,23 +192,23 @@ public async Task HandleAuthenticate_OnValidateKey_result_not_null() }; }); using var client = server.CreateClient(); - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.ClaimsPrincipalUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.ClaimsPrincipalUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await client.SendAsync(request); var principal = await DeserializeClaimsPrincipalAsync(response); Assert.True(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.DoesNotContain(new ClaimDto(FakeApiKeys.FakeRoleClaim), principal.Claims); // provider not called + Assert.DoesNotContain(new MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.ClaimDto(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeRoleClaim), principal.Claims); // provider not called } [Fact] public async Task HandleAuthenticate_OnValidateKey_result_null() { - using var server = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => { - options.Realm = TestServerBuilder.Realm; - options.KeyName = FakeApiKeys.KeyName; + options.Realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; + options.KeyName = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName; options.Events.OnValidateKey = context => { Assert.Null(context.Result); @@ -218,25 +217,25 @@ public async Task HandleAuthenticate_OnValidateKey_result_null() }; }); using var client = server.CreateClient(); - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.ClaimsPrincipalUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.ClaimsPrincipalUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await client.SendAsync(request); var principal = await DeserializeClaimsPrincipalAsync(response); Assert.True(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode); - Assert.Contains(new ClaimDto(FakeApiKeys.FakeRoleClaim), principal.Claims); // coming from provider, so provider called + Assert.Contains(new MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.ClaimDto(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeRoleClaim), principal.Claims); // coming from provider, so provider called } [Fact] public async Task HandleAuthenticate_OnValidateKey_result_null_without_provider_and_OnAuthenticationFailed_throws() { - var expectedExceptionMessage = $"Either {nameof(ApiKeyEvents.OnValidateKey)} delegate on configure options {nameof(ApiKeyOptions.Events)} should be set or use an extension method with type parameter of type {nameof(IApiKeyAuthenticationService)} or register an implementation of type {nameof(IApiKeyAuthenticationServiceFactory)} in the service collection."; + var expectedExceptionMessage = $"Either {nameof(MadEyeMatt.AspNetCore.Authentication.ApiKey.Events.ApiKeyEvents.OnValidateKey)} delegate on configure options {nameof(ApiKeyOptions.Events)} should be set or use an extension method with type parameter of type {nameof(IApiKeyAuthenticationService)} or register an implementation of type {nameof(IApiKeyAuthenticationServiceFactory)} in the service collection."; - using var server = TestServerBuilder.BuildInHeaderOrQueryParamsServer(options => + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServer(options => { - options.Realm = TestServerBuilder.Realm; - options.KeyName = FakeApiKeys.KeyName; + options.Realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; + options.KeyName = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName; options.Events.OnValidateKey = context => { Assert.Null(context.Result); @@ -254,8 +253,8 @@ public async Task HandleAuthenticate_OnValidateKey_result_null_without_provider_ }; }); using var client = server.CreateClient(); - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); var exception = await Assert.ThrowsAsync(async () => { @@ -271,12 +270,12 @@ public async Task HandleAuthenticate_OnValidateKey_result_null_without_provider_ [Fact] public async Task HandleAuthenticate_OnValidateKey_result_null_without_provider_and_OnAuthenticationFailed_does_not_throw() { - var expectedExceptionMessage = $"Either {nameof(ApiKeyEvents.OnValidateKey)} delegate on configure options {nameof(ApiKeyOptions.Events)} should be set or use an extension method with type parameter of type {nameof(IApiKeyAuthenticationService)} or register an implementation of type {nameof(IApiKeyAuthenticationServiceFactory)} in the service collection."; + var expectedExceptionMessage = $"Either {nameof(MadEyeMatt.AspNetCore.Authentication.ApiKey.Events.ApiKeyEvents.OnValidateKey)} delegate on configure options {nameof(ApiKeyOptions.Events)} should be set or use an extension method with type parameter of type {nameof(IApiKeyAuthenticationService)} or register an implementation of type {nameof(IApiKeyAuthenticationServiceFactory)} in the service collection."; - using var server = TestServerBuilder.BuildInHeaderOrQueryParamsServer(options => + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServer(options => { - options.Realm = TestServerBuilder.Realm; - options.KeyName = FakeApiKeys.KeyName; + options.Realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; + options.KeyName = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName; options.Events.OnValidateKey = context => { Assert.Null(context.Result); @@ -299,8 +298,8 @@ public async Task HandleAuthenticate_OnValidateKey_result_null_without_provider_ }; }); using var client = server.CreateClient(); - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await client.SendAsync(request); Assert.False(response.IsSuccessStatusCode); @@ -310,10 +309,10 @@ public async Task HandleAuthenticate_OnValidateKey_result_null_without_provider_ [Fact] public async Task HandleAuthenticate_ForLegacyIgnoreExtraValidatedApiKeyCheck() { - using var server = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(); + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(); using var client = server.CreateClient(); - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeKeyForLegacyIgnoreExtraValidatedApiKeyCheck); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKeyForLegacyIgnoreExtraValidatedApiKeyCheck); using var response = await client.SendAsync(request); Assert.False(response.IsSuccessStatusCode); @@ -323,10 +322,10 @@ public async Task HandleAuthenticate_ForLegacyIgnoreExtraValidatedApiKeyCheck() [Fact] public async Task HandleAuthenticate_OnAuthenticationSucceeded_result_null() { - using var server = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => { - options.Realm = TestServerBuilder.Realm; - options.KeyName = FakeApiKeys.KeyName; + options.Realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; + options.KeyName = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName; options.Events.OnAuthenticationSucceeded = context => { Assert.Null(context.Result); @@ -335,8 +334,8 @@ public async Task HandleAuthenticate_OnAuthenticationSucceeded_result_null() }; }); using var client = server.CreateClient(); - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await client.SendAsync(request); Assert.True(response.IsSuccessStatusCode); @@ -346,10 +345,10 @@ public async Task HandleAuthenticate_OnAuthenticationSucceeded_result_null() [Fact] public async Task HandleAuthenticate_OnAuthenticationSucceeded_result_and_principal_null() { - using var server = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => { - options.Realm = TestServerBuilder.Realm; - options.KeyName = FakeApiKeys.KeyName; + options.Realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; + options.KeyName = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName; options.Events.OnAuthenticationSucceeded = context => { context.RejectPrincipal(); @@ -361,8 +360,8 @@ public async Task HandleAuthenticate_OnAuthenticationSucceeded_result_and_princi }; }); using var client = server.CreateClient(); - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await client.SendAsync(request); Assert.False(response.IsSuccessStatusCode); @@ -372,10 +371,10 @@ public async Task HandleAuthenticate_OnAuthenticationSucceeded_result_and_princi [Fact] public async Task HandleAuthenticate_OnAuthenticationSucceeded_result_not_null() { - using var server = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => { - options.Realm = TestServerBuilder.Realm; - options.KeyName = FakeApiKeys.KeyName; + options.Realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; + options.KeyName = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName; options.Events.OnAuthenticationSucceeded = context => { context.Fail("test"); @@ -387,8 +386,8 @@ public async Task HandleAuthenticate_OnAuthenticationSucceeded_result_not_null() }; }); using var client = server.CreateClient(); - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await client.SendAsync(request); Assert.False(response.IsSuccessStatusCode); @@ -406,17 +405,17 @@ public async Task MultiScheme() var keyName2 = "Key2"; var keyName3 = "Key3"; var keyName4 = "Key4"; - var claimProvider1 = new ClaimDto { Type = "Provider", Value = "1" }; - var claimProvider2 = new ClaimDto { Type = "Provider", Value = "2" }; - var claimRole = new ClaimDto(FakeApiKeys.FakeRoleClaim); + var claimProvider1 = new MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.ClaimDto { Type = "Provider", Value = "1" }; + var claimProvider2 = new MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.ClaimDto { Type = "Provider", Value = "2" }; + var claimRole = new MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.ClaimDto(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeRoleClaim); var schemes = new List { "InHeader", "InHeaderWithProvider", "InAuthorizationHeader", "InQueryParams" }; - using var server = TestServerBuilder.BuildTestServer(services => + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildTestServer(services => { services.AddAuthentication("InHeader") .AddApiKeyInHeader("InHeader", options => { - options.Realm = TestServerBuilder.Realm; + options.Realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; options.KeyName = keyName1; options.Events.OnValidateKey = context => { @@ -427,17 +426,17 @@ public async Task MultiScheme() }) .AddApiKeyInHeader("InHeaderWithProvider", options => { - options.Realm = TestServerBuilder.Realm; + options.Realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; options.KeyName = keyName2; }) .AddApiKeyInAuthorizationHeader("InAuthorizationHeader", options => { - options.Realm = TestServerBuilder.Realm; + options.Realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; options.KeyName = keyName3; }) - .AddApiKeyInQueryParams("InQueryParams", options => + .AddApiKeyInQueryParams("InQueryParams", options => { - options.Realm = TestServerBuilder.Realm; + options.Realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; options.KeyName = keyName4; }); @@ -448,8 +447,8 @@ public async Task MultiScheme() using var client = server.CreateClient(); - using var request1 = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.ClaimsPrincipalUrl + "?scheme=" + schemes[0]); - request1.Headers.Add(keyName1, FakeApiKeys.FakeKey); + using var request1 = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.ClaimsPrincipalUrl + "?scheme=" + schemes[0]); + request1.Headers.Add(keyName1, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response1 = await client.SendAsync(request1); Assert.True(response1.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.OK, response1.StatusCode); @@ -460,8 +459,8 @@ public async Task MultiScheme() Assert.DoesNotContain(response1Principal.Claims, c => c.Type == claimRole.Type && c.Value == claimRole.Value); - using var request2 = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.ClaimsPrincipalUrl + "?scheme=" + schemes[1]); - request2.Headers.Add(keyName2, FakeApiKeys.FakeKey); + using var request2 = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.ClaimsPrincipalUrl + "?scheme=" + schemes[1]); + request2.Headers.Add(keyName2, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response2 = await client.SendAsync(request2); Assert.True(response2.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.OK, response2.StatusCode); @@ -472,8 +471,8 @@ public async Task MultiScheme() Assert.DoesNotContain(response2Principal.Claims, c => c.Type == claimRole.Type && c.Value == claimRole.Value); - using var request3 = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.ClaimsPrincipalUrl + "?scheme=" + schemes[2]); - request3.Headers.Authorization = new AuthenticationHeaderValue(keyName3, FakeApiKeys.FakeKey); + using var request3 = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.ClaimsPrincipalUrl + "?scheme=" + schemes[2]); + request3.Headers.Authorization = new AuthenticationHeaderValue(keyName3, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response3 = await client.SendAsync(request3); Assert.True(response3.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.OK, response3.StatusCode); @@ -484,7 +483,7 @@ public async Task MultiScheme() Assert.DoesNotContain(response3Principal.Claims, c => c.Type == claimRole.Type && c.Value == claimRole.Value); - using var request4 = new HttpRequestMessage(HttpMethod.Get, $"{TestServerBuilder.ClaimsPrincipalUrl}?scheme={schemes[3]}&{keyName4}={FakeApiKeys.FakeKey}"); + using var request4 = new HttpRequestMessage(HttpMethod.Get, $"{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.ClaimsPrincipalUrl}?scheme={schemes[3]}&{keyName4}={MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey}"); using var response4 = await client.SendAsync(request4); Assert.True(response4.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.OK, response3.StatusCode); @@ -497,16 +496,16 @@ public async Task MultiScheme() #endregion // Multi-Scheme - private async Task DeserializeClaimsPrincipalAsync(HttpResponseMessage response) + private async Task DeserializeClaimsPrincipalAsync(HttpResponseMessage response) { - return JsonSerializer.Deserialize(await response.Content.ReadAsStringAsync()); + return JsonSerializer.Deserialize(await response.Content.ReadAsStringAsync()); } private class FakeApiKeyAuthenticationServiceLocal1 : IApiKeyAuthenticationService { public Task AuthenticateAsync(string key) { - return Task.FromResult((IApiKey)new FakeApiKey(key, "Test", new List { new Claim("Provider", "1") })); + return Task.FromResult((IApiKey)new MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKey(key, "Test", new List { new Claim("Provider", "1") })); } } @@ -514,7 +513,7 @@ private class FakeApiKeyAuthenticationServiceLocal2 : IApiKeyAuthenticationServi { public Task AuthenticateAsync(string key) { - return Task.FromResult((IApiKey)new FakeApiKey(key, "Test", new List { new Claim("Provider", "2") })); + return Task.FromResult((IApiKey)new MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKey(key, "Test", new List { new Claim("Provider", "2") })); } } } diff --git a/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyInAuthorizationHeaderHandlerTests.cs b/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyInAuthorizationHeaderHandlerTests.cs index bbb2638..aa6f571 100644 --- a/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyInAuthorizationHeaderHandlerTests.cs +++ b/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyInAuthorizationHeaderHandlerTests.cs @@ -1,20 +1,19 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using AspNetCore.Authentication.ApiKey.Tests.Infrastructure; -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.TestHost; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; -using System; -using System.Net; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Threading.Tasks; -using Xunit; - -namespace AspNetCore.Authentication.ApiKey.Tests +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests { + using System; + using System.Net; + using System.Net.Http; + using System.Net.Http.Headers; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Authentication; + using Microsoft.AspNetCore.TestHost; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.Options; + using Xunit; + public class ApiKeyInAuthorizationHeaderHandlerTests : IDisposable { private readonly TestServer _server; @@ -26,13 +25,13 @@ public class ApiKeyInAuthorizationHeaderHandlerTests : IDisposable public ApiKeyInAuthorizationHeaderHandlerTests() { - _server = TestServerBuilder.BuildInAuthorizationHeaderServer(); + _server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInAuthorizationHeaderServer(); _client = _server.CreateClient(); - _serverWithProvider = TestServerBuilder.BuildInAuthorizationHeaderServerWithProvider(); + _serverWithProvider = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInAuthorizationHeaderServerWithProvider(); _clientWithProvider = _serverWithProvider.CreateClient(); - _serverWithProviderFactory = TestServerBuilder.BuildInAuthorizationHeaderServerWithProviderFactory(); + _serverWithProviderFactory = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInAuthorizationHeaderServerWithProviderFactory(); _clientWithProviderFactory = _serverWithProvider.CreateClient(); } @@ -85,11 +84,11 @@ public async Task TApiKeyProvider_Verify_Handler() Assert.NotNull(apiKeyOptions); Assert.Null(apiKeyOptions.Events?.OnValidateKey); Assert.NotNull(apiKeyOptions.ApiKeyProviderType); - Assert.Equal(typeof(FakeApiKeyAuthenticationService), apiKeyOptions.ApiKeyProviderType); + Assert.Equal(typeof(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeyAuthenticationService), apiKeyOptions.ApiKeyProviderType); var apiKeyProvider = services.GetService(); Assert.NotNull(apiKeyProvider); - Assert.Equal(typeof(FakeApiKeyAuthenticationService), apiKeyProvider.GetType()); + Assert.Equal(typeof(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeyAuthenticationService), apiKeyProvider.GetType()); } [Fact] @@ -114,14 +113,14 @@ public async Task TApiKeyProvider_Via_Factory_Verify_Handler() var apiKeyProviderFactory = services.GetService(); Assert.NotNull(apiKeyProviderFactory); - Assert.Equal(typeof(FakeApiKeyAuthenticationServiceFactory), apiKeyProviderFactory.GetType()); + Assert.Equal(typeof(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeyAuthenticationServiceFactory), apiKeyProviderFactory.GetType()); } [Fact] public async Task Verify_challenge_www_authenticate_header() { - using var response = await _client.GetAsync(TestServerBuilder.BaseUrl); + using var response = await _client.GetAsync(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); Assert.False(response.IsSuccessStatusCode); var wwwAuthenticateHeader = response.Headers.WwwAuthenticate; @@ -130,13 +129,13 @@ public async Task Verify_challenge_www_authenticate_header() var wwwAuthenticateHeaderToMatch = Assert.Single(wwwAuthenticateHeader); Assert.NotNull(wwwAuthenticateHeaderToMatch); Assert.Equal(ApiKeyDefaults.AuthenticationScheme, wwwAuthenticateHeaderToMatch.Scheme); - Assert.Equal($"realm=\"{TestServerBuilder.Realm}\", charset=\"UTF-8\", in=\"authorization_header\", key_name=\"{FakeApiKeys.KeyName}\"", wwwAuthenticateHeaderToMatch.Parameter); + Assert.Equal($"realm=\"{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm}\", charset=\"UTF-8\", in=\"authorization_header\", key_name=\"{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName}\"", wwwAuthenticateHeaderToMatch.Parameter); } [Fact] public async Task Unauthorized() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); using var response = await _client.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -145,8 +144,8 @@ public async Task Unauthorized() [Fact] public async Task Success() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Authorization = new AuthenticationHeaderValue(ApiKeyDefaults.AuthenticationScheme, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Authorization = new AuthenticationHeaderValue(ApiKeyDefaults.AuthenticationScheme, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await _client.SendAsync(request); Assert.True(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -155,8 +154,8 @@ public async Task Success() [Fact] public async Task Success_with_key_name() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Authorization = new AuthenticationHeaderValue(FakeApiKeys.KeyName, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Authorization = new AuthenticationHeaderValue(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await _client.SendAsync(request); Assert.True(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -165,8 +164,8 @@ public async Task Success_with_key_name() [Fact] public async Task Invalid_scheme_unauthorized() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Authorization = new AuthenticationHeaderValue("INVALID", FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Authorization = new AuthenticationHeaderValue("INVALID", MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await _client.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -175,8 +174,8 @@ public async Task Invalid_scheme_unauthorized() [Fact] public async Task Invalid_key_unauthorized() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Authorization = new AuthenticationHeaderValue(ApiKeyDefaults.AuthenticationScheme, FakeApiKeys.FakeInvalidKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Authorization = new AuthenticationHeaderValue(ApiKeyDefaults.AuthenticationScheme, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeInvalidKey); using var response = await _client.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -185,8 +184,8 @@ public async Task Invalid_key_unauthorized() [Fact] public async Task Invalid_key_unauthorized_with_key_name() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Authorization = new AuthenticationHeaderValue(FakeApiKeys.KeyName, FakeApiKeys.FakeInvalidKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Authorization = new AuthenticationHeaderValue(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeInvalidKey); using var response = await _client.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -197,7 +196,7 @@ public async Task Invalid_key_unauthorized_with_key_name() [Fact] public async Task TApiKeyProvider_Unauthorized() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); using var response = await _clientWithProvider.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -206,8 +205,8 @@ public async Task TApiKeyProvider_Unauthorized() [Fact] public async Task TApiKeyProvider_success() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Authorization = new AuthenticationHeaderValue(ApiKeyDefaults.AuthenticationScheme, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Authorization = new AuthenticationHeaderValue(ApiKeyDefaults.AuthenticationScheme, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await _clientWithProvider.SendAsync(request); Assert.True(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -216,8 +215,8 @@ public async Task TApiKeyProvider_success() [Fact] public async Task TApiKeyProvider_success_with_key_name() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Authorization = new AuthenticationHeaderValue(FakeApiKeys.KeyName, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Authorization = new AuthenticationHeaderValue(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await _clientWithProvider.SendAsync(request); Assert.True(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -226,8 +225,8 @@ public async Task TApiKeyProvider_success_with_key_name() [Fact] public async Task TApiKeyProvider_invalid_scheme_unauthorized() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Authorization = new AuthenticationHeaderValue("INVALID", FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Authorization = new AuthenticationHeaderValue("INVALID", MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await _clientWithProvider.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -236,8 +235,8 @@ public async Task TApiKeyProvider_invalid_scheme_unauthorized() [Fact] public async Task TApiKeyProvider_invalid_key_unauthorized() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Authorization = new AuthenticationHeaderValue(ApiKeyDefaults.AuthenticationScheme, FakeApiKeys.FakeInvalidKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Authorization = new AuthenticationHeaderValue(ApiKeyDefaults.AuthenticationScheme, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeInvalidKey); using var response = await _clientWithProvider.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -246,8 +245,8 @@ public async Task TApiKeyProvider_invalid_key_unauthorized() [Fact] public async Task TApiKeyProvider_invalid_key_unauthorized_with_key_name() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Authorization = new AuthenticationHeaderValue(FakeApiKeys.KeyName, FakeApiKeys.FakeInvalidKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Authorization = new AuthenticationHeaderValue(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeInvalidKey); using var response = await _clientWithProvider.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -258,7 +257,7 @@ public async Task TApiKeyProvider_invalid_key_unauthorized_with_key_name() [Fact] public async Task TApiKeyProvider_Via_Factory_Unauthorized() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); using var response = await _clientWithProviderFactory.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -267,8 +266,8 @@ public async Task TApiKeyProvider_Via_Factory_Unauthorized() [Fact] public async Task TApiKeyProvider_Via_Factory_success() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Authorization = new AuthenticationHeaderValue(ApiKeyDefaults.AuthenticationScheme, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Authorization = new AuthenticationHeaderValue(ApiKeyDefaults.AuthenticationScheme, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await _clientWithProviderFactory.SendAsync(request); Assert.True(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -277,8 +276,8 @@ public async Task TApiKeyProvider_Via_Factory_success() [Fact] public async Task TApiKeyProvider_Via_Factory_success_with_key_name() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Authorization = new AuthenticationHeaderValue(FakeApiKeys.KeyName, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Authorization = new AuthenticationHeaderValue(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await _clientWithProviderFactory.SendAsync(request); Assert.True(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -287,8 +286,8 @@ public async Task TApiKeyProvider_Via_Factory_success_with_key_name() [Fact] public async Task TApiKeyProvider_Via_Factory_invalid_scheme_unauthorized() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Authorization = new AuthenticationHeaderValue("INVALID", FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Authorization = new AuthenticationHeaderValue("INVALID", MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await _clientWithProviderFactory.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -297,8 +296,8 @@ public async Task TApiKeyProvider_Via_Factory_invalid_scheme_unauthorized() [Fact] public async Task TApiKeyProvider_Via_Factory_invalid_key_unauthorized() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Authorization = new AuthenticationHeaderValue(ApiKeyDefaults.AuthenticationScheme, FakeApiKeys.FakeInvalidKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Authorization = new AuthenticationHeaderValue(ApiKeyDefaults.AuthenticationScheme, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeInvalidKey); using var response = await _clientWithProviderFactory.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -307,8 +306,8 @@ public async Task TApiKeyProvider_Via_Factory_invalid_key_unauthorized() [Fact] public async Task TApiKeyProvider_Via_Factory_invalid_key_unauthorized_with_key_name() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Authorization = new AuthenticationHeaderValue(FakeApiKeys.KeyName, FakeApiKeys.FakeInvalidKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Authorization = new AuthenticationHeaderValue(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeInvalidKey); using var response = await _clientWithProviderFactory.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); diff --git a/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyInHeaderHandlerTests.cs b/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyInHeaderHandlerTests.cs index 1fef9f7..2905e6c 100644 --- a/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyInHeaderHandlerTests.cs +++ b/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyInHeaderHandlerTests.cs @@ -1,19 +1,18 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using AspNetCore.Authentication.ApiKey.Tests.Infrastructure; -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.TestHost; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; -using System; -using System.Net; -using System.Net.Http; -using System.Threading.Tasks; -using Xunit; - -namespace AspNetCore.Authentication.ApiKey.Tests +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests { + using System; + using System.Net; + using System.Net.Http; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Authentication; + using Microsoft.AspNetCore.TestHost; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.Options; + using Xunit; + public class ApiKeyInHeaderHandlerTests : IDisposable { private readonly TestServer _server; @@ -25,13 +24,13 @@ public class ApiKeyInHeaderHandlerTests : IDisposable public ApiKeyInHeaderHandlerTests() { - _server = TestServerBuilder.BuildInHeaderServer(); + _server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderServer(); _client = _server.CreateClient(); - _serverWithProvider = TestServerBuilder.BuildInHeaderServerWithProvider(); + _serverWithProvider = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderServerWithProvider(); _clientWithProvider = _serverWithProvider.CreateClient(); - _serverWithProviderFactory = TestServerBuilder.BuildInHeaderServerWithProviderFactory(); + _serverWithProviderFactory = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderServerWithProviderFactory(); _clientWithProviderFactory = _serverWithProvider.CreateClient(); } @@ -84,11 +83,11 @@ public async Task TApiKeyProvider_Verify_Handler() Assert.NotNull(apiKeyOptions); Assert.Null(apiKeyOptions.Events?.OnValidateKey); Assert.NotNull(apiKeyOptions.ApiKeyProviderType); - Assert.Equal(typeof(FakeApiKeyAuthenticationService), apiKeyOptions.ApiKeyProviderType); + Assert.Equal(typeof(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeyAuthenticationService), apiKeyOptions.ApiKeyProviderType); var apiKeyProvider = services.GetService(); Assert.NotNull(apiKeyProvider); - Assert.Equal(typeof(FakeApiKeyAuthenticationService), apiKeyProvider.GetType()); + Assert.Equal(typeof(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeyAuthenticationService), apiKeyProvider.GetType()); } [Fact] @@ -113,13 +112,13 @@ public async Task TApiKeyProvider_Via_Factory_Verify_Handler() var apiKeyProviderFactory = services.GetService(); Assert.NotNull(apiKeyProviderFactory); - Assert.Equal(typeof(FakeApiKeyAuthenticationServiceFactory), apiKeyProviderFactory.GetType()); + Assert.Equal(typeof(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeyAuthenticationServiceFactory), apiKeyProviderFactory.GetType()); } [Fact] public async Task Verify_challenge_www_authenticate_header() { - using var response = await _client.GetAsync(TestServerBuilder.BaseUrl); + using var response = await _client.GetAsync(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); Assert.False(response.IsSuccessStatusCode); var wwwAuthenticateHeader = response.Headers.WwwAuthenticate; @@ -128,13 +127,13 @@ public async Task Verify_challenge_www_authenticate_header() var wwwAuthenticateHeaderToMatch = Assert.Single(wwwAuthenticateHeader); Assert.NotNull(wwwAuthenticateHeaderToMatch); Assert.Equal(ApiKeyDefaults.AuthenticationScheme, wwwAuthenticateHeaderToMatch.Scheme); - Assert.Equal($"realm=\"{TestServerBuilder.Realm}\", charset=\"UTF-8\", in=\"header\", key_name=\"{FakeApiKeys.KeyName}\"", wwwAuthenticateHeaderToMatch.Parameter); + Assert.Equal($"realm=\"{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm}\", charset=\"UTF-8\", in=\"header\", key_name=\"{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName}\"", wwwAuthenticateHeaderToMatch.Parameter); } [Fact] public async Task Unauthorized() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); using var response = await _client.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -143,8 +142,8 @@ public async Task Unauthorized() [Fact] public async Task Success() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await _client.SendAsync(request); Assert.True(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -153,8 +152,8 @@ public async Task Success() [Fact] public async Task Invalid_key_unauthorized() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeInvalidKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeInvalidKey); using var response = await _client.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -164,7 +163,7 @@ public async Task Invalid_key_unauthorized() [Fact] public async Task TApiKeyProvider_unauthorized() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); using var response = await _clientWithProvider.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -173,8 +172,8 @@ public async Task TApiKeyProvider_unauthorized() [Fact] public async Task TApiKeyProvider_success() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await _clientWithProvider.SendAsync(request); Assert.True(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -183,8 +182,8 @@ public async Task TApiKeyProvider_success() [Fact] public async Task TApiKeyProvider_invalid_key_unauthorized() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeInvalidKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeInvalidKey); using var response = await _clientWithProvider.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -194,7 +193,7 @@ public async Task TApiKeyProvider_invalid_key_unauthorized() [Fact] public async Task TApiKeyProvider_Via_Factory_unauthorized() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); using var response = await _clientWithProviderFactory.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -203,8 +202,8 @@ public async Task TApiKeyProvider_Via_Factory_unauthorized() [Fact] public async Task TApiKeyProvider_Via_Factory_success() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await _clientWithProviderFactory.SendAsync(request); Assert.True(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -213,8 +212,8 @@ public async Task TApiKeyProvider_Via_Factory_success() [Fact] public async Task TApiKeyProvider_Via_Factory_invalid_key_unauthorized() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeInvalidKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeInvalidKey); using var response = await _clientWithProviderFactory.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); diff --git a/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyInHeaderOrQueryParamsHandlerTests.cs b/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyInHeaderOrQueryParamsHandlerTests.cs index 986baec..934f936 100644 --- a/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyInHeaderOrQueryParamsHandlerTests.cs +++ b/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyInHeaderOrQueryParamsHandlerTests.cs @@ -1,20 +1,19 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using AspNetCore.Authentication.ApiKey.Tests.Infrastructure; -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.TestHost; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; -using System; -using System.Net; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Threading.Tasks; -using Xunit; - -namespace AspNetCore.Authentication.ApiKey.Tests +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests { + using System; + using System.Net; + using System.Net.Http; + using System.Net.Http.Headers; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Authentication; + using Microsoft.AspNetCore.TestHost; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.Options; + using Xunit; + public class ApiKeyInHeaderOrQueryParamsHandlerTests : IDisposable { private readonly TestServer _server; @@ -26,13 +25,13 @@ public class ApiKeyInHeaderOrQueryParamsHandlerTests : IDisposable public ApiKeyInHeaderOrQueryParamsHandlerTests() { - _server = TestServerBuilder.BuildInHeaderOrQueryParamsServer(); + _server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServer(); _client = _server.CreateClient(); - _serverWithProvider = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(); + _serverWithProvider = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(); _clientWithProvider = _serverWithProvider.CreateClient(); - _serverWithProviderFactory = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProviderFactory(); + _serverWithProviderFactory = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProviderFactory(); _clientWithProviderFactory = _serverWithProvider.CreateClient(); } @@ -85,11 +84,11 @@ public async Task TApiKeyProvider_Verify_Handler() Assert.NotNull(apiKeyOptions); Assert.Null(apiKeyOptions.Events?.OnValidateKey); Assert.NotNull(apiKeyOptions.ApiKeyProviderType); - Assert.Equal(typeof(FakeApiKeyAuthenticationService), apiKeyOptions.ApiKeyProviderType); + Assert.Equal(typeof(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeyAuthenticationService), apiKeyOptions.ApiKeyProviderType); var apiKeyProvider = services.GetService(); Assert.NotNull(apiKeyProvider); - Assert.Equal(typeof(FakeApiKeyAuthenticationService), apiKeyProvider.GetType()); + Assert.Equal(typeof(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeyAuthenticationService), apiKeyProvider.GetType()); } [Fact] @@ -114,13 +113,13 @@ public async Task TApiKeyProvider_Via_Factory_Verify_Handler() var apiKeyProviderFactory = services.GetService(); Assert.NotNull(apiKeyProviderFactory); - Assert.Equal(typeof(FakeApiKeyAuthenticationServiceFactory), apiKeyProviderFactory.GetType()); + Assert.Equal(typeof(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeyAuthenticationServiceFactory), apiKeyProviderFactory.GetType()); } [Fact] public async Task Verify_challenge_www_authenticate_header() { - using var response = await _client.GetAsync(TestServerBuilder.BaseUrl); + using var response = await _client.GetAsync(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); Assert.False(response.IsSuccessStatusCode); var wwwAuthenticateHeader = response.Headers.WwwAuthenticate; @@ -129,13 +128,13 @@ public async Task Verify_challenge_www_authenticate_header() var wwwAuthenticateHeaderToMatch = Assert.Single(wwwAuthenticateHeader); Assert.NotNull(wwwAuthenticateHeaderToMatch); Assert.Equal(ApiKeyDefaults.AuthenticationScheme, wwwAuthenticateHeaderToMatch.Scheme); - Assert.Equal($"realm=\"{TestServerBuilder.Realm}\", charset=\"UTF-8\", in=\"header_or_query_params\", key_name=\"{FakeApiKeys.KeyName}\"", wwwAuthenticateHeaderToMatch.Parameter); + Assert.Equal($"realm=\"{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm}\", charset=\"UTF-8\", in=\"header_or_query_params\", key_name=\"{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName}\"", wwwAuthenticateHeaderToMatch.Parameter); } [Fact] public async Task Unauthorized() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); using var response = await _client.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -144,8 +143,8 @@ public async Task Unauthorized() [Fact] public async Task InHeader_success() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await _client.SendAsync(request); Assert.True(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -154,8 +153,8 @@ public async Task InHeader_success() [Fact] public async Task InHeader_invalid_key_unauthorized() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeInvalidKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeInvalidKey); using var response = await _client.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -164,8 +163,8 @@ public async Task InHeader_invalid_key_unauthorized() [Fact] public async Task InAuthorizationHeader_success() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Authorization = new AuthenticationHeaderValue(FakeApiKeys.KeyName, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Authorization = new AuthenticationHeaderValue(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await _client.SendAsync(request); Assert.True(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -174,8 +173,8 @@ public async Task InAuthorizationHeader_success() [Fact] public async Task InAuthorizationHeader_invalid_key_unauthorized() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Authorization = new AuthenticationHeaderValue(FakeApiKeys.KeyName, FakeApiKeys.FakeInvalidKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Authorization = new AuthenticationHeaderValue(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeInvalidKey); using var response = await _client.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -184,7 +183,7 @@ public async Task InAuthorizationHeader_invalid_key_unauthorized() [Fact] public async Task InQueryParams_success() { - var uri = $"{TestServerBuilder.BaseUrl}?{FakeApiKeys.KeyName}={FakeApiKeys.FakeKey}"; + var uri = $"{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl}?{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName}={MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey}"; using var request = new HttpRequestMessage(HttpMethod.Get, uri); using var response = await _client.SendAsync(request); Assert.True(response.IsSuccessStatusCode); @@ -194,7 +193,7 @@ public async Task InQueryParams_success() [Fact] public async Task InQueryParams_invalid_key_unauthorized() { - var uri = $"{TestServerBuilder.BaseUrl}?{FakeApiKeys.KeyName}={FakeApiKeys.FakeInvalidKey}"; + var uri = $"{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl}?{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName}={MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeInvalidKey}"; using var request = new HttpRequestMessage(HttpMethod.Get, uri); using var response = await _client.SendAsync(request); Assert.False(response.IsSuccessStatusCode); @@ -206,7 +205,7 @@ public async Task InQueryParams_invalid_key_unauthorized() [Fact] public async Task TApiKeyProvider_unauthorized() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); using var response = await _clientWithProvider.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -215,8 +214,8 @@ public async Task TApiKeyProvider_unauthorized() [Fact] public async Task TApiKeyProvider_InHeader_success() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await _clientWithProvider.SendAsync(request); Assert.True(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -225,8 +224,8 @@ public async Task TApiKeyProvider_InHeader_success() [Fact] public async Task TApiKeyProvider_InHeader_invalid_key_unauthorized() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeInvalidKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeInvalidKey); using var response = await _clientWithProvider.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -235,8 +234,8 @@ public async Task TApiKeyProvider_InHeader_invalid_key_unauthorized() [Fact] public async Task TApiKeyProvider_InAuthorizationHeader_success() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Authorization = new AuthenticationHeaderValue(FakeApiKeys.KeyName, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Authorization = new AuthenticationHeaderValue(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await _clientWithProvider.SendAsync(request); Assert.True(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -245,8 +244,8 @@ public async Task TApiKeyProvider_InAuthorizationHeader_success() [Fact] public async Task TApiKeyProvider_InAuthorizationHeader_invalid_key_unauthorized() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Authorization = new AuthenticationHeaderValue(FakeApiKeys.KeyName, FakeApiKeys.FakeInvalidKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Authorization = new AuthenticationHeaderValue(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeInvalidKey); using var response = await _clientWithProvider.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -255,7 +254,7 @@ public async Task TApiKeyProvider_InAuthorizationHeader_invalid_key_unauthorized [Fact] public async Task TApiKeyProvider_InQueryParams_success() { - var uri = $"{TestServerBuilder.BaseUrl}?{FakeApiKeys.KeyName}={FakeApiKeys.FakeKey}"; + var uri = $"{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl}?{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName}={MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey}"; using var request = new HttpRequestMessage(HttpMethod.Get, uri); using var response = await _clientWithProvider.SendAsync(request); Assert.True(response.IsSuccessStatusCode); @@ -265,7 +264,7 @@ public async Task TApiKeyProvider_InQueryParams_success() [Fact] public async Task TApiKeyProvider_InQueryParams_invalid_key_unauthorized() { - var uri = $"{TestServerBuilder.BaseUrl}?{FakeApiKeys.KeyName}={FakeApiKeys.FakeInvalidKey}"; + var uri = $"{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl}?{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName}={MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeInvalidKey}"; using var request = new HttpRequestMessage(HttpMethod.Get, uri); using var response = await _clientWithProvider.SendAsync(request); Assert.False(response.IsSuccessStatusCode); @@ -276,7 +275,7 @@ public async Task TApiKeyProvider_InQueryParams_invalid_key_unauthorized() [Fact] public async Task TApiKeyProvider_Via_Factory_unauthorized() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); using var response = await _clientWithProviderFactory.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -285,8 +284,8 @@ public async Task TApiKeyProvider_Via_Factory_unauthorized() [Fact] public async Task TApiKeyProvider_Via_Factory_InHeader_success() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await _clientWithProviderFactory.SendAsync(request); Assert.True(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -295,8 +294,8 @@ public async Task TApiKeyProvider_Via_Factory_InHeader_success() [Fact] public async Task TApiKeyProvider_Via_Factory_InHeader_invalid_key_unauthorized() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeInvalidKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeInvalidKey); using var response = await _clientWithProviderFactory.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -305,8 +304,8 @@ public async Task TApiKeyProvider_Via_Factory_InHeader_invalid_key_unauthorized( [Fact] public async Task TApiKeyProvider_Via_Factory_InAuthorizationHeader_success() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Authorization = new AuthenticationHeaderValue(FakeApiKeys.KeyName, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Authorization = new AuthenticationHeaderValue(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await _clientWithProviderFactory.SendAsync(request); Assert.True(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -315,8 +314,8 @@ public async Task TApiKeyProvider_Via_Factory_InAuthorizationHeader_success() [Fact] public async Task TApiKeyProvider_Via_Factory_InAuthorizationHeader_invalid_key_unauthorized() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Authorization = new AuthenticationHeaderValue(FakeApiKeys.KeyName, FakeApiKeys.FakeInvalidKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Authorization = new AuthenticationHeaderValue(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeInvalidKey); using var response = await _clientWithProviderFactory.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -325,7 +324,7 @@ public async Task TApiKeyProvider_Via_Factory_InAuthorizationHeader_invalid_key_ [Fact] public async Task TApiKeyProvider_Via_Factory_InQueryParams_success() { - var uri = $"{TestServerBuilder.BaseUrl}?{FakeApiKeys.KeyName}={FakeApiKeys.FakeKey}"; + var uri = $"{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl}?{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName}={MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey}"; using var request = new HttpRequestMessage(HttpMethod.Get, uri); using var response = await _clientWithProviderFactory.SendAsync(request); Assert.True(response.IsSuccessStatusCode); @@ -335,7 +334,7 @@ public async Task TApiKeyProvider_Via_Factory_InQueryParams_success() [Fact] public async Task TApiKeyProvider_Via_Factory_InQueryParams_invalid_key_unauthorized() { - var uri = $"{TestServerBuilder.BaseUrl}?{FakeApiKeys.KeyName}={FakeApiKeys.FakeInvalidKey}"; + var uri = $"{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl}?{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName}={MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeInvalidKey}"; using var request = new HttpRequestMessage(HttpMethod.Get, uri); using var response = await _clientWithProviderFactory.SendAsync(request); Assert.False(response.IsSuccessStatusCode); diff --git a/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyInQueryParamsHandlerTests.cs b/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyInQueryParamsHandlerTests.cs index 1ab557e..9a9f641 100644 --- a/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyInQueryParamsHandlerTests.cs +++ b/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyInQueryParamsHandlerTests.cs @@ -1,19 +1,18 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using AspNetCore.Authentication.ApiKey.Tests.Infrastructure; -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.TestHost; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; -using System; -using System.Net; -using System.Net.Http; -using System.Threading.Tasks; -using Xunit; - -namespace AspNetCore.Authentication.ApiKey.Tests +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests { + using System; + using System.Net; + using System.Net.Http; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Authentication; + using Microsoft.AspNetCore.TestHost; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.Options; + using Xunit; + public class ApiKeyInQueryParamsHandlerTests : IDisposable { private readonly TestServer _server; @@ -25,13 +24,13 @@ public class ApiKeyInQueryParamsHandlerTests : IDisposable public ApiKeyInQueryParamsHandlerTests() { - _server = TestServerBuilder.BuildInQueryParamsServer(); + _server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInQueryParamsServer(); _client = _server.CreateClient(); - _serverWithProvider = TestServerBuilder.BuildInQueryParamsServerWithProvider(); + _serverWithProvider = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInQueryParamsServerWithProvider(); _clientWithProvider = _serverWithProvider.CreateClient(); - _serverWithProviderFactory = TestServerBuilder.BuildInQueryParamsServerWithProviderFactory(); + _serverWithProviderFactory = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInQueryParamsServerWithProviderFactory(); _clientWithProviderFactory = _serverWithProvider.CreateClient(); } @@ -84,11 +83,11 @@ public async Task TApiKeyProvider_Verify_Handler() Assert.NotNull(apiKeyOptions); Assert.Null(apiKeyOptions.Events?.OnValidateKey); Assert.NotNull(apiKeyOptions.ApiKeyProviderType); - Assert.Equal(typeof(FakeApiKeyAuthenticationService), apiKeyOptions.ApiKeyProviderType); + Assert.Equal(typeof(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeyAuthenticationService), apiKeyOptions.ApiKeyProviderType); var apiKeyProvider = services.GetService(); Assert.NotNull(apiKeyProvider); - Assert.Equal(typeof(FakeApiKeyAuthenticationService), apiKeyProvider.GetType()); + Assert.Equal(typeof(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeyAuthenticationService), apiKeyProvider.GetType()); } [Fact] @@ -113,13 +112,13 @@ public async Task TApiKeyProvider_Via_Factory_Verify_Handler() var apiKeyProviderFactory = services.GetService(); Assert.NotNull(apiKeyProviderFactory); - Assert.Equal(typeof(FakeApiKeyAuthenticationServiceFactory), apiKeyProviderFactory.GetType()); + Assert.Equal(typeof(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeyAuthenticationServiceFactory), apiKeyProviderFactory.GetType()); } [Fact] public async Task Verify_challenge_www_authenticate_header() { - using var response = await _client.GetAsync(TestServerBuilder.BaseUrl); + using var response = await _client.GetAsync(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); Assert.False(response.IsSuccessStatusCode); var wwwAuthenticateHeader = response.Headers.WwwAuthenticate; @@ -128,13 +127,13 @@ public async Task Verify_challenge_www_authenticate_header() var wwwAuthenticateHeaderToMatch = Assert.Single(wwwAuthenticateHeader); Assert.NotNull(wwwAuthenticateHeaderToMatch); Assert.Equal(ApiKeyDefaults.AuthenticationScheme, wwwAuthenticateHeaderToMatch.Scheme); - Assert.Equal($"realm=\"{TestServerBuilder.Realm}\", charset=\"UTF-8\", in=\"query_params\", key_name=\"{FakeApiKeys.KeyName}\"", wwwAuthenticateHeaderToMatch.Parameter); + Assert.Equal($"realm=\"{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm}\", charset=\"UTF-8\", in=\"query_params\", key_name=\"{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName}\"", wwwAuthenticateHeaderToMatch.Parameter); } [Fact] public async Task Unauthorized() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); using var response = await _client.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -143,7 +142,7 @@ public async Task Unauthorized() [Fact] public async Task Success() { - var uri = $"{TestServerBuilder.BaseUrl}?{FakeApiKeys.KeyName}={FakeApiKeys.FakeKey}"; + var uri = $"{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl}?{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName}={MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey}"; using var request = new HttpRequestMessage(HttpMethod.Get, uri); using var response = await _client.SendAsync(request); Assert.True(response.IsSuccessStatusCode); @@ -153,7 +152,7 @@ public async Task Success() [Fact] public async Task Invalid_key_unauthorized() { - var uri = $"{TestServerBuilder.BaseUrl}?{FakeApiKeys.KeyName}={FakeApiKeys.FakeInvalidKey}"; + var uri = $"{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl}?{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName}={MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeInvalidKey}"; using var request = new HttpRequestMessage(HttpMethod.Get, uri); using var response = await _client.SendAsync(request); Assert.False(response.IsSuccessStatusCode); @@ -165,7 +164,7 @@ public async Task Invalid_key_unauthorized() [Fact] public async Task TApiKeyProvider_unauthorized() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); using var response = await _clientWithProvider.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -174,7 +173,7 @@ public async Task TApiKeyProvider_unauthorized() [Fact] public async Task TApiKeyProvider_success() { - var uri = $"{TestServerBuilder.BaseUrl}?{FakeApiKeys.KeyName}={FakeApiKeys.FakeKey}"; + var uri = $"{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl}?{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName}={MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey}"; using var request = new HttpRequestMessage(HttpMethod.Get, uri); using var response = await _clientWithProvider.SendAsync(request); Assert.True(response.IsSuccessStatusCode); @@ -184,7 +183,7 @@ public async Task TApiKeyProvider_success() [Fact] public async Task TApiKeyProvider_invalid_key_unauthorized() { - var uri = $"{TestServerBuilder.BaseUrl}?{FakeApiKeys.KeyName}={FakeApiKeys.FakeInvalidKey}"; + var uri = $"{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl}?{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName}={MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeInvalidKey}"; using var request = new HttpRequestMessage(HttpMethod.Get, uri); using var response = await _clientWithProvider.SendAsync(request); Assert.False(response.IsSuccessStatusCode); @@ -196,7 +195,7 @@ public async Task TApiKeyProvider_invalid_key_unauthorized() [Fact] public async Task TApiKeyProvider_Via_Factory_unauthorized() { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); using var response = await _clientWithProviderFactory.SendAsync(request); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -205,7 +204,7 @@ public async Task TApiKeyProvider_Via_Factory_unauthorized() [Fact] public async Task TApiKeyProvider_Via_Factory_success() { - var uri = $"{TestServerBuilder.BaseUrl}?{FakeApiKeys.KeyName}={FakeApiKeys.FakeKey}"; + var uri = $"{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl}?{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName}={MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey}"; using var request = new HttpRequestMessage(HttpMethod.Get, uri); using var response = await _clientWithProviderFactory.SendAsync(request); Assert.True(response.IsSuccessStatusCode); @@ -215,7 +214,7 @@ public async Task TApiKeyProvider_Via_Factory_success() [Fact] public async Task TApiKeyProvider_Via_Factory_invalid_key_unauthorized() { - var uri = $"{TestServerBuilder.BaseUrl}?{FakeApiKeys.KeyName}={FakeApiKeys.FakeInvalidKey}"; + var uri = $"{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl}?{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName}={MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeInvalidKey}"; using var request = new HttpRequestMessage(HttpMethod.Get, uri); using var response = await _clientWithProviderFactory.SendAsync(request); Assert.False(response.IsSuccessStatusCode); diff --git a/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyOptionsTests.cs b/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyOptionsTests.cs index 8fbf3a1..a25dc2a 100644 --- a/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyOptionsTests.cs +++ b/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyOptionsTests.cs @@ -1,17 +1,16 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using AspNetCore.Authentication.ApiKey.Tests.Infrastructure; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; -using System; -using System.Net; -using System.Net.Http; -using System.Threading.Tasks; -using Xunit; - -namespace AspNetCore.Authentication.ApiKey.Tests +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests { + using System; + using System.Net; + using System.Net.Http; + using System.Threading.Tasks; + using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.Options; + using Xunit; + public class ApiKeyOptionsTests { [Fact] @@ -31,16 +30,16 @@ public void SuppressWWWAuthenticateHeader_default_false() [Fact] public async Task SuppressWWWAuthenticateHeader_verify_false() { - var realm = TestServerBuilder.Realm; - using var server = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => + var realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => { - options.KeyName = FakeApiKeys.KeyName; + options.KeyName = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName; options.Realm = realm; options.SuppressWWWAuthenticateHeader = false; }); using var client = server.CreateClient(); - using var response = await client.GetAsync(TestServerBuilder.BaseUrl); + using var response = await client.GetAsync(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); Assert.False(response.IsSuccessStatusCode); @@ -50,22 +49,22 @@ public async Task SuppressWWWAuthenticateHeader_verify_false() var wwwAuthenticateHeaderToMatch = Assert.Single(wwwAuthenticateHeader); Assert.NotNull(wwwAuthenticateHeaderToMatch); Assert.Equal(ApiKeyDefaults.AuthenticationScheme, wwwAuthenticateHeaderToMatch.Scheme); - Assert.Equal($"realm=\"{realm}\", charset=\"UTF-8\", in=\"header_or_query_params\", key_name=\"{FakeApiKeys.KeyName}\"", wwwAuthenticateHeaderToMatch.Parameter); + Assert.Equal($"realm=\"{realm}\", charset=\"UTF-8\", in=\"header_or_query_params\", key_name=\"{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName}\"", wwwAuthenticateHeaderToMatch.Parameter); } [Fact] public async Task SuppressWWWAuthenticateHeader_verify_true() { - var realm = TestServerBuilder.Realm; - using var server = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => + var realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => { - options.KeyName = FakeApiKeys.KeyName; + options.KeyName = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName; options.Realm = realm; options.SuppressWWWAuthenticateHeader = true; }); using var client = server.CreateClient(); - using var response = await client.GetAsync(TestServerBuilder.BaseUrl); + using var response = await client.GetAsync(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); Assert.False(response.IsSuccessStatusCode); Assert.Empty(response.Headers.WwwAuthenticate); @@ -81,17 +80,17 @@ public void ForLegacyIgnoreExtraValidatedApiKeyCheck_default_false() [Fact] public async Task ForLegacyIgnoreExtraValidatedApiKeyCheck_verify_false() { - var realm = TestServerBuilder.Realm; - using var server = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => + var realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => { - options.KeyName = FakeApiKeys.KeyName; + options.KeyName = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName; options.Realm = realm; options.ForLegacyIgnoreExtraValidatedApiKeyCheck = false; }); using var client = server.CreateClient(); - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeKeyForLegacyIgnoreExtraValidatedApiKeyCheck); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKeyForLegacyIgnoreExtraValidatedApiKeyCheck); using var response = await client.SendAsync(request); Assert.False(response.IsSuccessStatusCode); @@ -101,17 +100,17 @@ public async Task ForLegacyIgnoreExtraValidatedApiKeyCheck_verify_false() [Fact] public async Task ForLegacyIgnoreExtraValidatedApiKeyCheck_verify_true() { - var realm = TestServerBuilder.Realm; - using var server = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => + var realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => { - options.KeyName = FakeApiKeys.KeyName; + options.KeyName = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName; options.Realm = realm; options.ForLegacyIgnoreExtraValidatedApiKeyCheck = true; }); using var client = server.CreateClient(); - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeKeyForLegacyIgnoreExtraValidatedApiKeyCheck); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKeyForLegacyIgnoreExtraValidatedApiKeyCheck); using var response = await client.SendAsync(request); Assert.True(response.IsSuccessStatusCode); @@ -128,16 +127,16 @@ public void ForLegacyUseKeyNameAsSchemeNameOnWWWAuthenticateHeader_default_false [Fact] public async Task ForLegacyUseKeyNameAsSchemeNameOnWWWAuthenticateHeader_verify_false() { - var realm = TestServerBuilder.Realm; - using var server = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => + var realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => { - options.KeyName = FakeApiKeys.KeyName; + options.KeyName = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName; options.Realm = realm; options.ForLegacyUseKeyNameAsSchemeNameOnWWWAuthenticateHeader = false; }); using var client = server.CreateClient(); - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); using var response = await client.SendAsync(request); Assert.False(response.IsSuccessStatusCode); @@ -149,23 +148,23 @@ public async Task ForLegacyUseKeyNameAsSchemeNameOnWWWAuthenticateHeader_verify_ var wwwAuthenticateHeaderToMatch = Assert.Single(wwwAuthenticateHeader); Assert.NotNull(wwwAuthenticateHeaderToMatch); Assert.Equal(ApiKeyDefaults.AuthenticationScheme, wwwAuthenticateHeaderToMatch.Scheme); - Assert.NotEqual(FakeApiKeys.KeyName, wwwAuthenticateHeaderToMatch.Scheme); - Assert.Equal($"realm=\"{realm}\", charset=\"UTF-8\", in=\"header_or_query_params\", key_name=\"{FakeApiKeys.KeyName}\"", wwwAuthenticateHeaderToMatch.Parameter); + Assert.NotEqual(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, wwwAuthenticateHeaderToMatch.Scheme); + Assert.Equal($"realm=\"{realm}\", charset=\"UTF-8\", in=\"header_or_query_params\", key_name=\"{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName}\"", wwwAuthenticateHeaderToMatch.Parameter); } [Fact] public async Task ForLegacyUseKeyNameAsSchemeNameOnWWWAuthenticateHeader_verify_true() { - var realm = TestServerBuilder.Realm; - using var server = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => + var realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => { - options.KeyName = FakeApiKeys.KeyName; + options.KeyName = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName; options.Realm = realm; options.ForLegacyUseKeyNameAsSchemeNameOnWWWAuthenticateHeader = true; }); using var client = server.CreateClient(); - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); using var response = await client.SendAsync(request); Assert.False(response.IsSuccessStatusCode); @@ -177,8 +176,8 @@ public async Task ForLegacyUseKeyNameAsSchemeNameOnWWWAuthenticateHeader_verify_ var wwwAuthenticateHeaderToMatch = Assert.Single(wwwAuthenticateHeader); Assert.NotNull(wwwAuthenticateHeaderToMatch); Assert.NotEqual(ApiKeyDefaults.AuthenticationScheme, wwwAuthenticateHeaderToMatch.Scheme); - Assert.Equal(FakeApiKeys.KeyName, wwwAuthenticateHeaderToMatch.Scheme); - Assert.Equal($"realm=\"{realm}\", charset=\"UTF-8\", in=\"header_or_query_params\", key_name=\"{FakeApiKeys.KeyName}\"", wwwAuthenticateHeaderToMatch.Parameter); + Assert.Equal(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, wwwAuthenticateHeaderToMatch.Scheme); + Assert.Equal($"realm=\"{realm}\", charset=\"UTF-8\", in=\"header_or_query_params\", key_name=\"{MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName}\"", wwwAuthenticateHeaderToMatch.Parameter); } [Fact] @@ -191,7 +190,7 @@ public void ApiKeyProviderType_default_null() [Fact] public void ApiKeyProviderType_verify_null() { - using var server = TestServerBuilder.BuildInHeaderOrQueryParamsServer(); + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServer(); var services = server.Host.Services; var apiKeyOptionsSnapshot = services.GetService>(); @@ -206,18 +205,18 @@ public void ApiKeyProviderType_verify_null() [Fact] public void ApiKeyProviderType_verify_not_null() { - using var server = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(); + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(); var services = server.Host.Services; var apiKeyOptionsSnapshot = services.GetService>(); var apiKeyOptions = apiKeyOptionsSnapshot.Get(ApiKeyDefaults.AuthenticationScheme); Assert.NotNull(apiKeyOptions); Assert.NotNull(apiKeyOptions.ApiKeyProviderType); - Assert.Equal(typeof(FakeApiKeyAuthenticationService), apiKeyOptions.ApiKeyProviderType); + Assert.Equal(typeof(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeyAuthenticationService), apiKeyOptions.ApiKeyProviderType); var apiKeyProvider = services.GetService(); Assert.NotNull(apiKeyProvider); - Assert.Equal(typeof(FakeApiKeyAuthenticationService), apiKeyProvider.GetType()); + Assert.Equal(typeof(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeyAuthenticationService), apiKeyProvider.GetType()); } #if !(NET461 || NETSTANDARD2_0 || NETCOREAPP2_1) @@ -232,17 +231,17 @@ public void IgnoreAuthenticationIfAllowAnonymous_default_false() [Fact] public async Task IgnoreAuthenticationIfAllowAnonymous_verify_false() { - var realm = TestServerBuilder.Realm; - using var server = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => + var realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => { - options.KeyName = FakeApiKeys.KeyName; + options.KeyName = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName; options.Realm = realm; options.IgnoreAuthenticationIfAllowAnonymous = false; }); using var client = server.CreateClient(); - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.AnonymousUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeKeyIgnoreAuthenticationIfAllowAnonymous); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.AnonymousUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKeyIgnoreAuthenticationIfAllowAnonymous); var exception = await Assert.ThrowsAsync(() => client.SendAsync(request)); @@ -252,17 +251,17 @@ public async Task IgnoreAuthenticationIfAllowAnonymous_verify_false() [Fact] public async Task IgnoreAuthenticationIfAllowAnonymous_verify_true() { - var realm = TestServerBuilder.Realm; - using var server = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => + var realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => { - options.KeyName = FakeApiKeys.KeyName; + options.KeyName = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName; options.Realm = realm; options.IgnoreAuthenticationIfAllowAnonymous = true; }); using var client = server.CreateClient(); - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.AnonymousUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeKeyIgnoreAuthenticationIfAllowAnonymous); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.AnonymousUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKeyIgnoreAuthenticationIfAllowAnonymous); using var response = await client.SendAsync(request); Assert.True(response.IsSuccessStatusCode); diff --git a/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyPostConfigureOptionsTests.cs b/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyPostConfigureOptionsTests.cs index 49959ec..ab56274 100644 --- a/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyPostConfigureOptionsTests.cs +++ b/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyPostConfigureOptionsTests.cs @@ -1,14 +1,12 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using AspNetCore.Authentication.ApiKey.Tests.Infrastructure; -using Microsoft.Extensions.DependencyInjection; -using System; -using System.Threading.Tasks; -using Xunit; - -namespace AspNetCore.Authentication.ApiKey.Tests +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests { + using System; + using System.Threading.Tasks; + using Xunit; + public class ApiKeyPostConfigureOptionsTests { static string KeyName = "X-API-KEY"; @@ -122,20 +120,20 @@ await RunAuthInitWithServiceFactoryAsync(options => private async Task RunAuthInitAsync(Action configureOptions) { - var server = TestServerBuilder.BuildInHeaderOrQueryParamsServer(configureOptions); - await server.CreateClient().GetAsync(TestServerBuilder.BaseUrl); + var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServer(configureOptions); + await server.CreateClient().GetAsync(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); } private async Task RunAuthInitWithProviderAsync(Action configureOptions) { - var server = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(configureOptions); - await server.CreateClient().GetAsync(TestServerBuilder.BaseUrl); + var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(configureOptions); + await server.CreateClient().GetAsync(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); } private async Task RunAuthInitWithServiceFactoryAsync(Action configureOptions) { - var server = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProviderFactory(configureOptions); - await server.CreateClient().GetAsync(TestServerBuilder.BaseUrl); + var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProviderFactory(configureOptions); + await server.CreateClient().GetAsync(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); } } } diff --git a/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyUtilsTests.cs b/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyUtilsTests.cs index 557d534..5ef0a6d 100644 --- a/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyUtilsTests.cs +++ b/tests/AspNetCore.Authentication.ApiKey.Tests/ApiKeyUtilsTests.cs @@ -1,14 +1,14 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using Xunit; - -namespace AspNetCore.Authentication.ApiKey.Tests +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests { + using System; + using System.Collections.Generic; + using System.Linq; + using System.Security.Claims; + using Xunit; + public class ApiKeyUtilsTests { [Fact] diff --git a/tests/AspNetCore.Authentication.ApiKey.Tests/AspNetCore.Authentication.ApiKey.Tests.csproj b/tests/AspNetCore.Authentication.ApiKey.Tests/AspNetCore.Authentication.ApiKey.Tests.csproj index ac9e1ff..b0de22c 100644 --- a/tests/AspNetCore.Authentication.ApiKey.Tests/AspNetCore.Authentication.ApiKey.Tests.csproj +++ b/tests/AspNetCore.Authentication.ApiKey.Tests/AspNetCore.Authentication.ApiKey.Tests.csproj @@ -1,21 +1,23 @@  - net6.0 + net7.0 latest disable disable + MadEyeMatt.$(MSBuildProjectName) + MadEyeMatt.$(MSBuildProjectName.Replace(" ", "_")) - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/AspNetCore.Authentication.ApiKey.Tests/Events/ApiKeyAuthenticationFailedContextTests.cs b/tests/AspNetCore.Authentication.ApiKey.Tests/Events/ApiKeyAuthenticationFailedContextTests.cs index 233c95f..2cd8012 100644 --- a/tests/AspNetCore.Authentication.ApiKey.Tests/Events/ApiKeyAuthenticationFailedContextTests.cs +++ b/tests/AspNetCore.Authentication.ApiKey.Tests/Events/ApiKeyAuthenticationFailedContextTests.cs @@ -1,26 +1,25 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using AspNetCore.Authentication.ApiKey.Tests.Infrastructure; -using System; -using System.Net; -using System.Net.Http; -using System.Threading.Tasks; -using Xunit; - -namespace AspNetCore.Authentication.ApiKey.Tests.Events +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Events { + using System; + using System.Net; + using System.Net.Http; + using System.Threading.Tasks; + using Xunit; + public class ApiKeyAuthenticationFailedContext { - private static readonly string ExpectedExceptionMessage = $"Either {nameof(ApiKeyEvents.OnValidateKey)} delegate on configure options {nameof(ApiKeyOptions.Events)} should be set or use an extension method with type parameter of type {nameof(IApiKeyAuthenticationService)} or register an implementation of type {nameof(IApiKeyAuthenticationServiceFactory)} in the service collection."; + private static readonly string ExpectedExceptionMessage = $"Either {nameof(MadEyeMatt.AspNetCore.Authentication.ApiKey.Events.ApiKeyEvents.OnValidateKey)} delegate on configure options {nameof(ApiKeyOptions.Events)} should be set or use an extension method with type parameter of type {nameof(IApiKeyAuthenticationService)} or register an implementation of type {nameof(IApiKeyAuthenticationServiceFactory)} in the service collection."; [Fact] public async Task Exception_result_null() { - using var server = TestServerBuilder.BuildInHeaderOrQueryParamsServer(options => + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServer(options => { - options.Realm = TestServerBuilder.Realm; - options.KeyName = FakeApiKeys.KeyName; + options.Realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; + options.KeyName = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName; options.Events.OnValidateKey = context => { Assert.Null(context.Result); @@ -39,8 +38,8 @@ public async Task Exception_result_null() }; }); using var client = server.CreateClient(); - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); var exception = await Assert.ThrowsAsync(async () => { @@ -57,10 +56,10 @@ public async Task Exception_result_null() [Fact] public async Task Exception_result_not_null() { - using var server = TestServerBuilder.BuildInHeaderOrQueryParamsServer(options => + using var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServer(options => { - options.Realm = TestServerBuilder.Realm; - options.KeyName = FakeApiKeys.KeyName; + options.Realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; + options.KeyName = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName; options.Events.OnValidateKey = context => { Assert.Null(context.Result); @@ -83,8 +82,8 @@ public async Task Exception_result_not_null() }; }); using var client = server.CreateClient(); - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.BaseUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await client.SendAsync(request); Assert.False(response.IsSuccessStatusCode); diff --git a/tests/AspNetCore.Authentication.ApiKey.Tests/Events/ApiKeyAuthenticationSucceededContextTests.cs b/tests/AspNetCore.Authentication.ApiKey.Tests/Events/ApiKeyAuthenticationSucceededContextTests.cs index e25e803..549d927 100644 --- a/tests/AspNetCore.Authentication.ApiKey.Tests/Events/ApiKeyAuthenticationSucceededContextTests.cs +++ b/tests/AspNetCore.Authentication.ApiKey.Tests/Events/ApiKeyAuthenticationSucceededContextTests.cs @@ -1,19 +1,18 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using AspNetCore.Authentication.ApiKey.Tests.Infrastructure; -using Microsoft.AspNetCore.TestHost; -using System; -using System.Collections.Generic; -using System.Net; -using System.Net.Http; -using System.Security.Claims; -using System.Text.Json; -using System.Threading.Tasks; -using Xunit; - -namespace AspNetCore.Authentication.ApiKey.Tests.Events +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Events { + using System; + using System.Collections.Generic; + using System.Net; + using System.Net.Http; + using System.Security.Claims; + using System.Text.Json; + using System.Threading.Tasks; + using Microsoft.AspNetCore.TestHost; + using Xunit; + public class ApiKeyAuthenticationSucceededContextTests : IDisposable { private readonly List _serversToDispose = new List(); @@ -106,7 +105,7 @@ public async Task AddClaim() ); var principal = await RunSuccessTests(client); - Assert.Contains(new ClaimDto(claim), principal.Claims); + Assert.Contains(new MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.ClaimDto(claim), principal.Claims); } [Fact] @@ -130,18 +129,18 @@ public async Task AddClaims() ); var principal = await RunSuccessTests(client); - Assert.Contains(new ClaimDto(claims[0]), principal.Claims); - Assert.Contains(new ClaimDto(claims[1]), principal.Claims); + Assert.Contains(new MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.ClaimDto(claims[0]), principal.Claims); + Assert.Contains(new MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.ClaimDto(claims[1]), principal.Claims); } - private HttpClient BuildClient(Func onAuthenticationSucceeded) + private HttpClient BuildClient(Func onAuthenticationSucceeded) { - var server = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => + var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => { - options.KeyName = FakeApiKeys.KeyName; - options.Realm = TestServerBuilder.Realm; + options.KeyName = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName; + options.Realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; options.Events.OnAuthenticationSucceeded = onAuthenticationSucceeded; }); @@ -151,24 +150,24 @@ private HttpClient BuildClient(Func private async Task RunUnauthorizedTests(HttpClient client) { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.ClaimsPrincipalUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.ClaimsPrincipalUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response_unauthorized = await client.SendAsync(request); Assert.False(response_unauthorized.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response_unauthorized.StatusCode); } - private async Task RunSuccessTests(HttpClient client) + private async Task RunSuccessTests(HttpClient client) { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.ClaimsPrincipalUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.ClaimsPrincipalUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response_ok = await client.SendAsync(request); Assert.True(response_ok.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.OK, response_ok.StatusCode); var content = await response_ok.Content.ReadAsStringAsync(); Assert.False(string.IsNullOrWhiteSpace(content)); - return JsonSerializer.Deserialize(content); + return JsonSerializer.Deserialize(content); } } } diff --git a/tests/AspNetCore.Authentication.ApiKey.Tests/Events/ApiKeyHandleChallengeContextTests.cs b/tests/AspNetCore.Authentication.ApiKey.Tests/Events/ApiKeyHandleChallengeContextTests.cs index 08effe3..9292c07 100644 --- a/tests/AspNetCore.Authentication.ApiKey.Tests/Events/ApiKeyHandleChallengeContextTests.cs +++ b/tests/AspNetCore.Authentication.ApiKey.Tests/Events/ApiKeyHandleChallengeContextTests.cs @@ -1,18 +1,17 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using AspNetCore.Authentication.ApiKey.Tests.Infrastructure; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.TestHost; -using System; -using System.Collections.Generic; -using System.Net; -using System.Net.Http; -using System.Threading.Tasks; -using Xunit; - -namespace AspNetCore.Authentication.ApiKey.Tests.Events +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Events { + using System; + using System.Collections.Generic; + using System.Net; + using System.Net.Http; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Http; + using Microsoft.AspNetCore.TestHost; + using Xunit; + public class ApiKeyHandleChallengeContextTests : IDisposable { private readonly List _serversToDispose = new List(); @@ -39,7 +38,7 @@ public async Task Handled() } ); - using var response = await client.GetAsync(TestServerBuilder.BaseUrl); + using var response = await client.GetAsync(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); @@ -59,7 +58,7 @@ public async Task Handled_not_called() } ); - using var response = await client.GetAsync(TestServerBuilder.BaseUrl); + using var response = await client.GetAsync(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BaseUrl); Assert.False(response.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); @@ -67,12 +66,12 @@ public async Task Handled_not_called() - private HttpClient BuildClient(Func onHandleChallenge) + private HttpClient BuildClient(Func onHandleChallenge) { - var server = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => + var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => { - options.KeyName = FakeApiKeys.KeyName; - options.Realm = TestServerBuilder.Realm; + options.KeyName = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName; + options.Realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; options.Events.OnHandleChallenge = onHandleChallenge; }); diff --git a/tests/AspNetCore.Authentication.ApiKey.Tests/Events/ApiKeyHandleForbiddenContextTests.cs b/tests/AspNetCore.Authentication.ApiKey.Tests/Events/ApiKeyHandleForbiddenContextTests.cs index 80e3838..5621e7f 100644 --- a/tests/AspNetCore.Authentication.ApiKey.Tests/Events/ApiKeyHandleForbiddenContextTests.cs +++ b/tests/AspNetCore.Authentication.ApiKey.Tests/Events/ApiKeyHandleForbiddenContextTests.cs @@ -1,18 +1,17 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using AspNetCore.Authentication.ApiKey.Tests.Infrastructure; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.TestHost; -using System; -using System.Collections.Generic; -using System.Net; -using System.Net.Http; -using System.Threading.Tasks; -using Xunit; - -namespace AspNetCore.Authentication.ApiKey.Tests.Events +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Events { + using System; + using System.Collections.Generic; + using System.Net; + using System.Net.Http; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Http; + using Microsoft.AspNetCore.TestHost; + using Xunit; + public class ApiKeyHandleForbiddenContextTests : IDisposable { private readonly List _serversToDispose = new List(); @@ -39,8 +38,8 @@ public async Task Handled() } ); - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.ForbiddenUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.ForbiddenUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await client.SendAsync(request); Assert.False(response.IsSuccessStatusCode); @@ -61,8 +60,8 @@ public async Task Handled_not_called() } ); - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.ForbiddenUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.ForbiddenUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response = await client.SendAsync(request); Assert.False(response.IsSuccessStatusCode); @@ -71,12 +70,12 @@ public async Task Handled_not_called() - private HttpClient BuildClient(Func onHandleForbidden) + private HttpClient BuildClient(Func onHandleForbidden) { - var server = TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => + var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServerWithProvider(options => { - options.KeyName = FakeApiKeys.KeyName; - options.Realm = TestServerBuilder.Realm; + options.KeyName = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName; + options.Realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; options.Events.OnHandleForbidden = onHandleForbidden; }); diff --git a/tests/AspNetCore.Authentication.ApiKey.Tests/Events/ApiKeyValidateKeyContextTests.cs b/tests/AspNetCore.Authentication.ApiKey.Tests/Events/ApiKeyValidateKeyContextTests.cs index 099e3b9..4cc8882 100644 --- a/tests/AspNetCore.Authentication.ApiKey.Tests/Events/ApiKeyValidateKeyContextTests.cs +++ b/tests/AspNetCore.Authentication.ApiKey.Tests/Events/ApiKeyValidateKeyContextTests.cs @@ -1,20 +1,19 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using AspNetCore.Authentication.ApiKey.Tests.Infrastructure; -using Microsoft.AspNetCore.TestHost; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Net.Http; -using System.Security.Claims; -using System.Text.Json; -using System.Threading.Tasks; -using Xunit; - -namespace AspNetCore.Authentication.ApiKey.Tests.Events +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Events { + using System; + using System.Collections.Generic; + using System.Linq; + using System.Net; + using System.Net.Http; + using System.Security.Claims; + using System.Text.Json; + using System.Threading.Tasks; + using Microsoft.AspNetCore.TestHost; + using Xunit; + public class ApiKeyValidateKeyContextTests : IDisposable { private readonly List _serversToDispose = new List(); @@ -34,7 +33,7 @@ public async Task Success_and_NoResult() Assert.Null(context.Result); Assert.False(string.IsNullOrWhiteSpace(context.ApiKey)); - var apiKey = FakeApiKeys.Keys.FirstOrDefault(k => k.Key.Equals(context.ApiKey, StringComparison.OrdinalIgnoreCase)); + var apiKey = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.Keys.FirstOrDefault(k => k.Key.Equals(context.ApiKey, StringComparison.OrdinalIgnoreCase)); if (apiKey != null) { context.Principal = new ClaimsPrincipal(new ClaimsIdentity(context.Scheme.Name)); @@ -71,7 +70,7 @@ public async Task ValidationSucceeded_and_ValidationFailed() using var client = BuildClient( context => { - var apiKey = FakeApiKeys.Keys.FirstOrDefault(k => k.Key.Equals(context.ApiKey, StringComparison.OrdinalIgnoreCase)); + var apiKey = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.Keys.FirstOrDefault(k => k.Key.Equals(context.ApiKey, StringComparison.OrdinalIgnoreCase)); if (apiKey != null) { context.ValidationSucceeded(); @@ -106,8 +105,8 @@ public async Task ValidationSucceeded_with_claims() { var claimsSource = new List { - FakeApiKeys.FakeNameClaim, - FakeApiKeys.FakeRoleClaim + MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeNameClaim, + MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeRoleClaim }; using var client = BuildClient( @@ -128,8 +127,8 @@ public async Task ValidationSucceeded_with_claims() Assert.NotEmpty(principal.Claims); Assert.Equal(claimsSource.Count, principal.Claims.Count()); - Assert.Contains(new ClaimDto(FakeApiKeys.FakeNameClaim), principal.Claims); - Assert.Contains(new ClaimDto(FakeApiKeys.FakeRoleClaim), principal.Claims); + Assert.Contains(new MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.ClaimDto(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeNameClaim), principal.Claims); + Assert.Contains(new MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.ClaimDto(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeRoleClaim), principal.Claims); } [Fact] @@ -165,8 +164,8 @@ public async Task ValidationSucceeded_with_ownerName_and_claims() var ownerName = "Owner"; var claimsSource = new List { - FakeApiKeys.FakeNameClaim, - FakeApiKeys.FakeRoleClaim + MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeNameClaim, + MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeRoleClaim }; using var client = BuildClient( @@ -187,8 +186,8 @@ public async Task ValidationSucceeded_with_ownerName_and_claims() Assert.NotEmpty(principal.Claims); Assert.Equal(claimsSource.Count + 1, principal.Claims.Count()); - Assert.Contains(new ClaimDto(FakeApiKeys.FakeNameClaim), principal.Claims); - Assert.Contains(new ClaimDto(FakeApiKeys.FakeRoleClaim), principal.Claims); + Assert.Contains(new MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.ClaimDto(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeNameClaim), principal.Claims); + Assert.Contains(new MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.ClaimDto(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeRoleClaim), principal.Claims); Assert.Contains(principal.Claims, c => c.Type == ClaimTypes.NameIdentifier && c.Value == ownerName); } @@ -240,12 +239,12 @@ public async Task ValidationFailed_with_failureException() - private HttpClient BuildClient(Func onValidateKey) + private HttpClient BuildClient(Func onValidateKey) { - var server = TestServerBuilder.BuildInHeaderOrQueryParamsServer(options => + var server = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.BuildInHeaderOrQueryParamsServer(options => { - options.KeyName = FakeApiKeys.KeyName; - options.Realm = TestServerBuilder.Realm; + options.KeyName = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName; + options.Realm = MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.Realm; options.Events.OnValidateKey = onValidateKey; }); @@ -255,22 +254,22 @@ private HttpClient BuildClient(Func onValidateKe private async Task RunUnauthorizedTests(HttpClient client) { - using var response_unauthorized = await client.GetAsync(TestServerBuilder.ClaimsPrincipalUrl); + using var response_unauthorized = await client.GetAsync(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.ClaimsPrincipalUrl); Assert.False(response_unauthorized.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Unauthorized, response_unauthorized.StatusCode); } - private async Task RunSuccessTests(HttpClient client) + private async Task RunSuccessTests(HttpClient client) { - using var request = new HttpRequestMessage(HttpMethod.Get, TestServerBuilder.ClaimsPrincipalUrl); - request.Headers.Add(FakeApiKeys.KeyName, FakeApiKeys.FakeKey); + using var request = new HttpRequestMessage(HttpMethod.Get, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.TestServerBuilder.ClaimsPrincipalUrl); + request.Headers.Add(MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.KeyName, MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure.FakeApiKeys.FakeKey); using var response_ok = await client.SendAsync(request); Assert.True(response_ok.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.OK, response_ok.StatusCode); var content = await response_ok.Content.ReadAsStringAsync(); Assert.False(string.IsNullOrWhiteSpace(content)); - return JsonSerializer.Deserialize(content); + return JsonSerializer.Deserialize(content); } } } diff --git a/tests/AspNetCore.Authentication.ApiKey.Tests/Infrastructure/ClaimsPrincipalDto.cs b/tests/AspNetCore.Authentication.ApiKey.Tests/Infrastructure/ClaimsPrincipalDto.cs index cc843e2..79327ba 100644 --- a/tests/AspNetCore.Authentication.ApiKey.Tests/Infrastructure/ClaimsPrincipalDto.cs +++ b/tests/AspNetCore.Authentication.ApiKey.Tests/Infrastructure/ClaimsPrincipalDto.cs @@ -1,14 +1,14 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Security.Principal; - -namespace AspNetCore.Authentication.ApiKey.Tests.Infrastructure +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure { + using System; + using System.Collections.Generic; + using System.Linq; + using System.Security.Claims; + using System.Security.Principal; + [Serializable] struct ClaimsPrincipalDto { diff --git a/tests/AspNetCore.Authentication.ApiKey.Tests/Infrastructure/FakeApiKeyAuthenticationService.cs b/tests/AspNetCore.Authentication.ApiKey.Tests/Infrastructure/FakeApiKeyAuthenticationService.cs index 6a95377..a71451e 100644 --- a/tests/AspNetCore.Authentication.ApiKey.Tests/Infrastructure/FakeApiKeyAuthenticationService.cs +++ b/tests/AspNetCore.Authentication.ApiKey.Tests/Infrastructure/FakeApiKeyAuthenticationService.cs @@ -1,14 +1,14 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; - -namespace AspNetCore.Authentication.ApiKey.Tests.Infrastructure +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure { + using System; + using System.Collections.Generic; + using System.Linq; + using System.Security.Claims; + using System.Threading.Tasks; + class FakeApiKeyAuthenticationService : IApiKeyAuthenticationService { public Task AuthenticateAsync(string key) diff --git a/tests/AspNetCore.Authentication.ApiKey.Tests/Infrastructure/TestServerBuilder.cs b/tests/AspNetCore.Authentication.ApiKey.Tests/Infrastructure/TestServerBuilder.cs index 216006c..6553979 100644 --- a/tests/AspNetCore.Authentication.ApiKey.Tests/Infrastructure/TestServerBuilder.cs +++ b/tests/AspNetCore.Authentication.ApiKey.Tests/Infrastructure/TestServerBuilder.cs @@ -1,23 +1,20 @@ // Copyright (c) Mihir Dilip. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for license information. -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Authorization; -using Microsoft.AspNetCore.TestHost; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Primitives; -using System; -using System.Linq; -using System.Text.Json; -using System.Threading.Tasks; - -namespace AspNetCore.Authentication.ApiKey.Tests.Infrastructure +namespace MadEyeMatt.AspNetCore.Authentication.ApiKey.Tests.Infrastructure { + using System; + using System.Linq; + using System.Text.Json; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Authentication; + using Microsoft.AspNetCore.Authorization; + using Microsoft.AspNetCore.Builder; + using Microsoft.AspNetCore.Hosting; + using Microsoft.AspNetCore.Http; + using Microsoft.AspNetCore.TestHost; + using Microsoft.Extensions.DependencyInjection; + partial class TestServerBuilder { internal static string BaseUrl = "http://localhost/";