2026-04-21 20:08:49 +01:00
|
|
|
using System.Net;
|
2026-10-10 09:56:08 +02:00
|
|
|
using Bifrost.Web.Configuration;
|
|
|
|
|
using Bifrost.Web.Features.ConceptVotes;
|
|
|
|
|
using Bifrost.Web.Features.Shared;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
2026-06-17 04:03:14 +01:00
|
|
|
using Bifrost.Web.Data;
|
|
|
|
|
using Bifrost.Web.Domain;
|
2026-04-21 20:08:49 +01:00
|
|
|
using Bifrost.Web.Tests.Support;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.Testing;
|
2026-06-17 04:03:14 +01:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2026-04-21 20:08:49 +01:00
|
|
|
|
|
|
|
|
namespace Bifrost.Web.Tests;
|
|
|
|
|
|
|
|
|
|
public sealed class MemberConsoleTests : IClassFixture<TestWebApplicationFactory>
|
|
|
|
|
{
|
|
|
|
|
private readonly TestWebApplicationFactory _factory;
|
|
|
|
|
|
|
|
|
|
public MemberConsoleTests(TestWebApplicationFactory factory)
|
|
|
|
|
{
|
|
|
|
|
_factory = factory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Active_member_can_open_console()
|
|
|
|
|
{
|
|
|
|
|
using var client = _factory.CreateClient();
|
|
|
|
|
using var response = await client.GetAsync("/App");
|
|
|
|
|
|
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
|
var html = await response.Content.ReadAsStringAsync();
|
|
|
|
|
Assert.Contains("Operational picture", html);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Anonymous_user_is_redirected_to_sign_in()
|
|
|
|
|
{
|
|
|
|
|
using var client = _factory.CreateClient(new WebApplicationFactoryClientOptions
|
|
|
|
|
{
|
|
|
|
|
AllowAutoRedirect = false
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
client.DefaultRequestHeaders.Add("X-Test-Anonymous", "true");
|
|
|
|
|
using var response = await client.GetAsync("/App");
|
|
|
|
|
|
|
|
|
|
Assert.Equal(HttpStatusCode.Redirect, response.StatusCode);
|
|
|
|
|
Assert.Contains("/auth/sign-in", response.Headers.Location?.OriginalString);
|
|
|
|
|
}
|
2026-06-17 04:03:14 +01:00
|
|
|
|
2026-10-10 09:56:08 +02:00
|
|
|
[Fact]
|
|
|
|
|
public async Task Member_console_activity_shows_a_purge_without_its_network_tag()
|
|
|
|
|
{
|
|
|
|
|
using (var warmupClient = _factory.CreateClient())
|
|
|
|
|
{
|
|
|
|
|
_ = await warmupClient.GetAsync("/App");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string tag;
|
|
|
|
|
using (var scope = _factory.Services.CreateScope())
|
|
|
|
|
{
|
|
|
|
|
var dbContext = scope.ServiceProvider.GetRequiredService<BifrostDbContext>();
|
|
|
|
|
var admin = await dbContext.UserAccounts
|
|
|
|
|
.Include(x => x.Membership)
|
|
|
|
|
.SingleAsync(x => x.NormalizedGitHubLogin == "TEST-ADMIN");
|
|
|
|
|
var now = DateTimeOffset.UtcNow;
|
|
|
|
|
dbContext.ConceptSubjects.Add(new ConceptSubject
|
|
|
|
|
{
|
|
|
|
|
Collection = "aetheria-concept-mill",
|
|
|
|
|
Key = "ship-a",
|
|
|
|
|
Title = "ship-a",
|
|
|
|
|
RegisteredAtUtc = now
|
|
|
|
|
});
|
|
|
|
|
await dbContext.SaveChangesAsync();
|
|
|
|
|
|
|
|
|
|
var service = scope.ServiceProvider.GetRequiredService<ConceptAppraisalService>();
|
|
|
|
|
var options = scope.ServiceProvider.GetRequiredService<IOptions<ConceptVoteOptions>>().Value;
|
|
|
|
|
var client = System.Net.IPAddress.Parse("203.0.113.7");
|
|
|
|
|
tag = NetworkPrefix.Tag(client, options.IPv4PrefixLength, options.IPv6PrefixLength, options.NetworkTagSecret);
|
|
|
|
|
var voter = VoterIdentity.For(CurrentBifrostActor.Anonymous, "member-view-device")!;
|
|
|
|
|
await service.CastAsync("aetheria-concept-mill", "ship-a", voter, ConceptStance.Up, client, default);
|
|
|
|
|
|
|
|
|
|
var removed = await service.PurgeAsync(
|
|
|
|
|
new CurrentBifrostActor(true, admin), tag, now.AddHours(-1), now.AddHours(1), default);
|
|
|
|
|
Assert.Equal(1, removed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using var memberClient = _factory.CreateClient();
|
|
|
|
|
using var response = await memberClient.GetAsync("/App");
|
|
|
|
|
var html = await response.Content.ReadAsStringAsync();
|
|
|
|
|
|
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
|
Assert.Contains("Purge", html);
|
|
|
|
|
Assert.Contains("count", html);
|
|
|
|
|
Assert.DoesNotContain(tag, html);
|
|
|
|
|
}
|
2026-04-21 20:08:49 +01:00
|
|
|
}
|