web: Add admin user management
This commit is contained in:
1 parent
232d48c7fc
commit
fcf7cd0596
11 files changed
+410
-18
No files matched your search
@@ -2,12 +2,10 @@ using System.Net;
|
||||
using System.Text;
|
||||
using Helpdesk.Web.Api;
|
||||
using Helpdesk.Web.Auth;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using static Helpdesk.Web.Tests.WebTestSession;
|
||||
|
||||
namespace Helpdesk.Web.Tests;
|
||||
|
||||
@@ -59,20 +57,6 @@ public sealed class SwaggerAccessTests
|
||||
Assert.True(document.Headers.CacheControl?.NoStore == true);
|
||||
}
|
||||
|
||||
private static void SignIn(IServiceProvider services, HttpClient client, string role)
|
||||
{
|
||||
var scheme = CookieAuthenticationDefaults.AuthenticationScheme;
|
||||
var options = services.GetRequiredService<IOptionsMonitor<CookieAuthenticationOptions>>().Get(scheme);
|
||||
var now = DateTimeOffset.UtcNow;
|
||||
var properties = new AuthenticationProperties { IssuedUtc = now, ExpiresUtc = now.AddHours(1) };
|
||||
AuthCookie.StoreTokens(properties, new TokenSet("test-access", now.AddMinutes(15), "test-refresh", now.AddDays(1)));
|
||||
var user = new UserDto(1, "[email protected]", "Test", "User", null, role, true);
|
||||
var ticket = new AuthenticationTicket(AuthCookie.CreatePrincipal(user), properties, scheme);
|
||||
|
||||
client.DefaultRequestHeaders.Remove("Cookie");
|
||||
client.DefaultRequestHeaders.Add("Cookie", $"{AuthCookie.Name}={options.TicketDataFormat.Protect(ticket)}");
|
||||
}
|
||||
|
||||
private sealed class OpenApiBackend : HttpMessageHandler
|
||||
{
|
||||
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
|
||||
Reference in new issue
Block a user