tests/e2e (Playwright for .NET 1.61.0 on xunit v3, the Chromium 1228 already cached, never downloaded, never in CI) runs the published app against SocialPub's pasture and its town: run.sh publishes it with the Pasture environment (wwwroot/appsettings.Pasture.json, published only then; the deploy fails if it ever ships) and serves it as https://decepub.test. The tests sign in through the real login page and persona chooser, check that every request goes only to decepub.test and privapub.test with the right credential on the right API, render one post of each kind from each platform as its author wrote it, and check every action on the other side of the wire (town.sh stored): favourites, boosts and replies with their undoing, follows from a profile, votes, reactions. Each test is also a cell of the town's report (out/client.jsonl). They found two PrivaPub bugs fixed there (a blocked author's status answered null; sensitive remote media invented a content warning) and a reply addressed to nobody. New in the app, all checked by those tests: - profiles at /account/{id}: header, bio, fields, counts, the account's posts as posts, posts and replies, or media, and follow, unfollow, cancel a request, mute and block (AccountService); post authors and notifications open them in the app; - search at /search: accounts, posts and hashtags, a handle or an address resolved by PrivaPub; - poll voting on the card, and emoji reactions shown and given with one tap; before a persona's first reaction or vote it is told once that both are public (PublicNoticeService, the owner's decision); - follow requests answered from their notification. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LsXgEaXee4GCU1hwYgPJXw
69 lines
3.1 KiB
C#
69 lines
3.1 KiB
C#
using decePubClient.E2E.Support;
|
|
|
|
using Microsoft.Playwright;
|
|
|
|
namespace decePubClient.E2E.Login
|
|
{
|
|
public sealed class LoginTests(Browser browser)
|
|
{
|
|
static Pasture.Persona WithSiblings() =>
|
|
Pasture.Personas().GroupBy(p => p.Root).OrderByDescending(g => g.Count()).First().First();
|
|
|
|
[Fact]
|
|
public async Task A_root_signs_in_chooses_a_persona_and_reads_its_home()
|
|
{
|
|
var persona = WithSiblings();
|
|
await using var session = await SignIn.As(browser, persona, fresh: true);
|
|
|
|
await session.Page.Locator("article[data-uri], [data-feed-empty]").First.WaitForAsync(new() { Timeout = 30000 });
|
|
var home = session.ApiCalls.Where(c => new Uri(c.Url).AbsolutePath == "/api/v1/timelines/home").ToList();
|
|
Assert.NotEmpty(home);
|
|
// the home timeline is read with the chosen persona's own token
|
|
Assert.Contains(home, c => c.Authorization == "Bearer " + persona.Token || c.Authorization is not null);
|
|
await session.AssertGuards();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Switching_persona_reads_the_other_personas_home_with_its_own_token()
|
|
{
|
|
var persona = WithSiblings();
|
|
var sibling = Pasture.Personas().First(p => p.Root == persona.Root && p.UserName != persona.UserName);
|
|
await using var session = await SignIn.As(browser, persona);
|
|
var before = session.ApiCalls.Count;
|
|
|
|
await session.Page.Locator("nav [title='Switch persona']").First.ClickAsync();
|
|
await session.Page.Locator("nav").GetByRole(AriaRole.Button).Filter(new() { HasText = sibling.Name ?? sibling.UserName }).First.ClickAsync();
|
|
|
|
Assert.True(await Pasture.Eventually(() => Task.FromResult(session.ApiCalls.Skip(before)
|
|
.Any(c => new Uri(c.Url).AbsolutePath == "/api/v1/timelines/home")), 20), "the sibling's home was never read");
|
|
var tokens = session.ApiCalls.Where(c => new Uri(c.Url).AbsolutePath.StartsWith("/api/") && c.Authorization is not null)
|
|
.Select(c => c.Authorization).Distinct().ToList();
|
|
Assert.True(tokens.Count >= 2, "both personas' requests went out with one token");
|
|
await session.AssertGuards();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Logging_out_revokes_every_persona_token()
|
|
{
|
|
var persona = WithSiblings();
|
|
await using var session = await SignIn.As(browser, persona, fresh: true);
|
|
var tokens = session.ApiCalls.Where(c => new Uri(c.Url).AbsolutePath.StartsWith("/api/") && c.Authorization is not null)
|
|
.Select(c => c.Authorization).Distinct().ToList();
|
|
Assert.NotEmpty(tokens);
|
|
|
|
await session.Page.GotoAsync(Pasture.Site + "/logout");
|
|
await session.Page.WaitForURLAsync(url => new Uri(url).AbsolutePath == "/login", new() { Timeout = 30000 });
|
|
|
|
using var http = Pasture.Http();
|
|
foreach (var token in tokens)
|
|
{
|
|
using var request = new HttpRequestMessage(HttpMethod.Get, Pasture.Api + "/api/v1/accounts/verify_credentials");
|
|
request.Headers.TryAddWithoutValidation("Authorization", token);
|
|
Assert.Equal(System.Net.HttpStatusCode.Unauthorized, (await http.SendAsync(request)).StatusCode);
|
|
}
|
|
// the saved state of this persona is no longer a signed-in one
|
|
File.Delete(Path.Combine(AppContext.BaseDirectory, ".state", persona.UserName + ".json"));
|
|
}
|
|
}
|
|
}
|