|
3 | 3 | // See the LICENSE file in the project root for more information. |
4 | 4 |
|
5 | 5 | using System.Net; |
| 6 | +using System.Security.Claims; |
| 7 | +using System.Text.Encodings.Web; |
6 | 8 | using Microsoft.AspNetCore.Authentication; |
7 | 9 | using Microsoft.AspNetCore.Authorization; |
8 | 10 | using Microsoft.AspNetCore.Builder; |
|
11 | 13 | using Microsoft.Extensions.Configuration; |
12 | 14 | using Microsoft.Extensions.DependencyInjection; |
13 | 15 | using Microsoft.Extensions.Hosting; |
| 16 | +using Microsoft.Extensions.Logging; |
14 | 17 | using Microsoft.Extensions.Options; |
15 | 18 | using Steeltoe.Common.TestResources; |
16 | 19 | using Steeltoe.Management.Configuration; |
|
24 | 27 |
|
25 | 28 | namespace Steeltoe.Management.Endpoint.Test; |
26 | 29 |
|
27 | | -public sealed class ActuatorRouteBuilderExtensionsTest |
| 30 | +public sealed class EndpointAuthorizationTest |
28 | 31 | { |
29 | 32 | public static TheoryData<RegistrationMode, Type> EndpointTestData |
30 | 33 | { |
@@ -169,4 +172,20 @@ public enum RegistrationMode |
169 | 172 | UseEndpoints, |
170 | 173 | MapEndpoints |
171 | 174 | } |
| 175 | + |
| 176 | + private sealed class TestAuthHandler(IOptionsMonitor<AuthenticationSchemeOptions> optionsMonitor, ILoggerFactory loggerFactory, UrlEncoder encoder) |
| 177 | + : AuthenticationHandler<AuthenticationSchemeOptions>(optionsMonitor, loggerFactory, encoder) |
| 178 | + { |
| 179 | + public const string AuthenticationScheme = "TestScheme"; |
| 180 | + |
| 181 | + protected override Task<AuthenticateResult> HandleAuthenticateAsync() |
| 182 | + { |
| 183 | + var claim = new Claim("scope", "actuators.read"); |
| 184 | + var identity = new ClaimsIdentity([claim]); |
| 185 | + var principal = new ClaimsPrincipal(identity); |
| 186 | + var ticket = new AuthenticationTicket(principal, AuthenticationScheme); |
| 187 | + |
| 188 | + return Task.FromResult(AuthenticateResult.Success(ticket)); |
| 189 | + } |
| 190 | + } |
172 | 191 | } |
0 commit comments