MergeAccounts page: prove both accounts, choose the survivor against a preview, consent for both, confirm through the saga

Dark behind AccountMerge:Enabled. MergePreview is the one wording of the plan, MergeWording.Confirm the closed refusal words.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Heimdall 2026-11-14 10:29:59 +00:00
commit c0b7b6a857
7 changed files with 545 additions and 13 deletions

View file

@ -1,11 +1,89 @@
using Bifrost.Web.Domain;
namespace Bifrost.Web.Features.Membership;
/// <summary>Skeleton: the wording of a merge plan, in closed vocabulary. Written in the next commit.</summary>
/// <summary>
/// The only wording of what a merge would do, in closed vocabulary: counts by entry kind and action from <see cref="MergePlan"/>, the
/// sentence for each block code, and the statements every merge carries. It decides nothing, and names no account: the plan holds none.
/// </summary>
public static class MergePreview
{
public static IReadOnlyList<string> Lines(MergePlan plan) => [];
public static IReadOnlyList<string> Lines(MergePlan plan)
{
var lines = new List<string>();
foreach (var group in plan.Entries.GroupBy(x => (x.Kind, x.Action)))
{
var n = group.Count();
lines.Add(group.Key switch
{
(AccountMergeEntryKind.Vote, AccountMergeEntryAction.Moved) =>
$"{Count(n, "open vote")} of the other account on motions you did not vote on move to the kept account.",
(AccountMergeEntryKind.Vote, AccountMergeEntryAction.Voided) =>
$"{Count(n, "open vote")} of the other account are set aside: the kept account already voted on that motion or cannot vote.",
(AccountMergeEntryKind.ConceptAppraisal, AccountMergeEntryAction.Moved) =>
$"{Count(n, "appraisal")} of the other account move to the kept account.",
(AccountMergeEntryKind.ConceptAppraisal, AccountMergeEntryAction.Voided) =>
$"{Count(n, "appraisal")} of the other account are set aside: the kept account already appraised the same thing or cannot.",
(AccountMergeEntryKind.Membership, AccountMergeEntryAction.Closed) =>
"The other account's membership closes; the kept account's membership stays.",
(AccountMergeEntryKind.Standing, _) =>
"The kept account is suspended too, because the other account is.",
(AccountMergeEntryKind.PatronSupportEvent, AccountMergeEntryAction.Moved) =>
$"{Count(n, "patron event")} of the other account count for the kept account.",
_ => $"{Count(n, "other record")} change."
});
}
public static string Block(string code) => string.Empty;
foreach (var (key, n) in plan.Left.OrderBy(x => x.Key, StringComparer.Ordinal))
{
if (n > 0 && Remains(key) is { } noun)
{
lines.Add($"{Count(n, noun)} stay{(n == 1 ? "s" : string.Empty)} where {(n == 1 ? "it is" : "they are")}.");
}
}
public static IReadOnlyList<string> Statements => [];
if (lines.Count == 0)
{
lines.Add("No votes, appraisals or patron events change.");
}
return lines;
}
/// <summary>Why a pair cannot be merged, by the plan's block code. No account is named; a code this class does not know gets a generic line, never an echo.</summary>
public static string Block(string code) => code switch
{
"same_account" => "These are the same account.",
"account_missing" => "One of the accounts no longer exists.",
"mind_account" => "An account that belongs to a Mind cannot be merged.",
"native_account" => "An account without a Heimdall sign-in cannot be merged.",
"merge_in_flight" => "One of the accounts is already part of a merge that has not finished.",
"survivor_is_folded" => "The account you would keep was already merged into another account.",
"already_folded" => "The other account was already merged into another account.",
"folded_is_survivor" => "Another account was merged into the other account, so it cannot be folded in turn.",
"sealed_ballot_pending" => "The other account has a sealed ballot on an open motion; wait until it is revealed.",
_ => "These accounts cannot be merged now."
};
/// <summary>What every merge says, whatever the plan: what it cannot carry over, what it asks again, and how long it can be undone.</summary>
public static IReadOnlyList<string> Statements { get; } =
[
"Chat: your chat history, rooms and keys belong to one chat id and cannot be moved. Keep the account you use in chat. Whichever you keep, the other chat id stays behind: rooms you were in on it must be joined again with the kept one, and messages encrypted for it cannot be read on the kept one.",
"Your connections (Twitch, Discord and others) will ask for consent again.",
"If you stream or moderate with StreamPixels and one of these connections is the one it uses for your channel, that connection stops until you reconnect it.",
"Roles and admin rights of the other account end; a steward must grant them again.",
"You will have one membership and one vote per motion: where both accounts voted on an open motion, the kept account's vote counts and the other is set aside. Nothing is added together.",
"You can undo this for 7 days, from Merge status. After that it is final.",
"If you proved an account with ordinary sign-ins rather than a passkey, the merge is approved with ordinary sign-ins, which is the weaker proof, and a notice stays on your account until the 7 days end."
];
private static string Count(int n, string noun) => n == 1 ? $"1 {noun}" : $"{n} {noun}s";
private static string? Remains(string key) => key switch
{
"ConsentReceipts" => "consent record",
"PasskeyCredentials" => "passkey",
"LedgerEntries" => "ledger entry",
_ => null
};
}

View file

@ -67,8 +67,18 @@ public static class MergeWording
_ => string.Empty
};
/// <summary>Skeleton: the words for a closed confirm code on the merge page. Written with the page.</summary>
public static string Confirm(string code) => string.Empty;
/// <summary>The words for a closed code the merge page answers a confirm or a start with; empty for anything else.</summary>
public static string Confirm(string code) => code switch
{
"blocked" => "These accounts cannot be merged now. Nothing was changed.",
"preview_stale" => "Something changed since you looked; review the merge again. Nothing was changed and your sign-ins are kept.",
"not_party" => "Only one of the two accounts can confirm this merge. Nothing was changed.",
"proof_account_mismatch" => "A sign-in was not for the account it was meant for. Nothing was changed.",
"proofs_needed" => "Both accounts need a fresh sign-in, one for every login of the account that would be folded. Nothing was changed.",
"consent_needed" => "Tick both boxes to confirm. Nothing was changed.",
"bad_choice" => "Choose which account to keep. Nothing was changed.",
_ => string.Empty
};
public static string UndoCode(UndoOutcome outcome) => outcome switch
{

View file

@ -215,6 +215,13 @@
}
</div>
}
@if (Model.MergeEnabled)
{
<p class="muted">
Hold two accounts? <a asp-page="/Membership/MergeAccounts">Merge two accounts</a>
</p>
}
}
<div class="panel-actions">

View file

@ -26,6 +26,7 @@ public sealed class LinkedAccountsModel(
PasskeyService passkeys,
ICurrentBifrostActorAccessor actors,
IOptions<BifrostHostOptions> hostOptions,
IOptions<AccountMergeOptions> mergeOptions,
ILogger<LinkedAccountsModel> logger) : PageModel
{
private static readonly Dictionary<string, string> ProviderNames = new(StringComparer.Ordinal)
@ -52,6 +53,9 @@ public sealed class LinkedAccountsModel(
private string? AccountId => User.FindFirstValue(BifrostClaimTypes.HeimdallAccountId) is { Length: > 0 } id ? id : null;
/// <summary>Whether the merge page exists on this server (a flag, dark until Heimdall can move logins).</summary>
public bool MergeEnabled => mergeOptions.Value.Enabled;
/// <summary>The wording of the outcome the page was sent back with: a closed set, null for anything else.</summary>
public string? ResultMessage { get; private set; }

View file

@ -0,0 +1,148 @@
@page
@model Bifrost.Web.Pages.Membership.MergeAccountsModel
@{
ViewData["Title"] = "Merge two accounts";
}
<section class="panel">
<span class="eyebrow">Account merge</span>
<h1>Merge two accounts</h1>
<p class="panel-intro">
If one person holds two accounts, they can be merged into one. You prove both accounts with a fresh sign-in each, choose
which one stays, see what changes and confirm; nothing is named until both proofs exist, and the other account is only
ever the one Heimdall identified from your second sign-in.
</p>
@if (Model.ResultMessage is not null)
{
<div class="callout" role="status">@Model.ResultMessage</div>
}
@if (Model.ConfirmMessage is not null)
{
<div class="callout warning" role="status">@Model.ConfirmMessage</div>
}
@if (Model.Stage == Bifrost.Web.Pages.Membership.MergeAccountsModel.MergeStage.Prove)
{
<h2>Prove both accounts</h2>
<p class="muted">
Sign-ins are held in memory for a few minutes and then dropped. For each account, name a provider that account holds:
signing in through a provider it does not hold would make an unrelated account.
</p>
<h3>This account</h3>
@if (Model.SelfProved)
{
<p>This account is proved.</p>
}
else
{
<div class="panel-actions">
@foreach (var provider in Model.LinkableProviders)
{
<form method="post" asp-page-handler="ProveSelf" class="inline-actions">
<input type="hidden" name="via" value="@provider" />
<button class="button secondary" type="submit">Prove this account with @Bifrost.Web.Pages.Membership.MergeAccountsModel.ProviderName(provider)</button>
</form>
}
</div>
}
<h3>The other account</h3>
@if (Model.OtherProved)
{
<p>The other account is proved.</p>
}
else
{
<div class="panel-actions">
@foreach (var provider in Model.LinkableProviders)
{
<form method="post" asp-page-handler="ProveOther" class="inline-actions">
<input type="hidden" name="via" value="@provider" />
<button class="button secondary" type="submit">Prove the other account with @Bifrost.Web.Pages.Membership.MergeAccountsModel.ProviderName(provider)</button>
</form>
}
</div>
}
}
else
{
<h2>The two accounts</h2>
<ul>
<li>This account: <strong>@Model.SelfName</strong></li>
<li>The other account: <strong>@Model.OtherName</strong></li>
</ul>
@if (Model.Keep is null)
{
<p>Choose the account that stays. The other one is folded into it.</p>
<div class="panel-actions">
<a class="button" asp-page="/Membership/MergeAccounts" asp-route-keep="self">Keep this account</a>
<a class="button" asp-page="/Membership/MergeAccounts" asp-route-keep="other">Keep the other account</a>
</div>
}
else
{
<h2>Keep @Model.KeptName</h2>
<p>@Model.FoldedName is folded into it.</p>
<ul>
@foreach (var line in Model.PreviewLines)
{
<li>@line</li>
}
</ul>
@foreach (var statement in Model.Statements)
{
<p class="muted">@statement</p>
}
<p>
<a asp-page="/Membership/MergeAccounts" asp-route-keep="@(Model.Keep == "self" ? "other" : "self")">Keep @Model.FoldedName instead</a>
</p>
@if (Model.BlockWords.Count > 0)
{
<div class="callout warning">
<ul>
@foreach (var words in Model.BlockWords)
{
<li>@words</li>
}
</ul>
</div>
}
else if (Model.Stage == Bifrost.Web.Pages.Membership.MergeAccountsModel.MergeStage.ProveRemaining)
{
<p>
@Model.FoldedName holds more logins. Sign in once more through each one, so Heimdall knows the whole account agrees.
</p>
<div class="panel-actions">
@foreach (var provider in Model.ProvidersToProve)
{
<form method="post" asp-page-handler="ProveRemaining" class="inline-actions">
<input type="hidden" name="via" value="@provider" />
<input type="hidden" name="keep" value="@Model.Keep" />
<button class="button secondary" type="submit">Sign in with @Bifrost.Web.Pages.Membership.MergeAccountsModel.ProviderName(provider)</button>
</form>
}
</div>
}
else if (Model.Stage == Bifrost.Web.Pages.Membership.MergeAccountsModel.MergeStage.Confirm)
{
<form method="post" asp-page-handler="Confirm">
<input type="hidden" name="keep" value="@Model.Keep" />
<input type="hidden" name="digest" value="@Model.Digest" />
<p>
<label><input type="checkbox" name="consentSelf" value="true" /> I agree, for the account @Model.SelfName.</label>
</p>
<p>
<label><input type="checkbox" name="consentOther" value="true" /> I agree, for the account @Model.OtherName.</label>
</p>
<button class="button" type="submit">Merge into @Model.KeptName</button>
</form>
}
}
}
</section>

View file

@ -0,0 +1,261 @@
using System.Security.Claims;
using Bifrost.Web.Configuration;
using Bifrost.Web.Data;
using Bifrost.Web.Features.Heimdall;
using Bifrost.Web.Features.Membership;
using Bifrost.Web.Features.Shared;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
namespace Bifrost.Web.Pages.Membership;
/// <summary>
/// Where a member merges two accounts: proves both by fresh sign-ins, chooses which one stays against a preview, ticks one box for each
/// account and confirms. The page owns only that choice and that consent. Its stage is derived from <see cref="MergeProofs"/> and the
/// query on every request, nothing about progress is kept in a cookie or a hidden field except the chosen direction and the preview's
/// digest, and both are re-checked by the saga. The other account is named (by display name only) once both proofs are held, and
/// found by no email, name or login string: it is the account Heimdall identified from the second proof. The page writes no merge,
/// vote, membership or journal row: <see cref="AccountMergeSaga.ConfirmAsync"/> inserts the one Confirmed row that is the consent.
/// </summary>
[Authorize]
[ResponseCache(NoStore = true, Location = ResponseCacheLocation.None)]
public sealed class MergeAccountsModel(
ICurrentBifrostActorAccessor actors,
BifrostDbContext dbContext,
AccountMergeLedger ledger,
AccountMergeSaga saga,
MergeProofs proofs,
HeimdallAuthService heimdallAuthService,
IOptions<BifrostHostOptions> hostOptions,
IOptions<AccountMergeOptions> mergeOptions,
ILogger<MergeAccountsModel> logger) : PageModel
{
private const string KeepParameter = "keep";
private const string MergeParameter = "merge";
private const string Self = "self";
private const string Other = "other";
public enum MergeStage
{
/// <summary>One side or both lack a proof: nothing is named.</summary>
Prove,
/// <summary>Both sides are proved: the member chooses which stays.</summary>
Choose,
/// <summary>A direction is chosen and the folded account's remaining logins are asked one sign-in each.</summary>
ProveRemaining,
/// <summary>Everything the saga needs is held: the confirm form.</summary>
Confirm
}
public MergeStage Stage { get; private set; } = MergeStage.Prove;
public string? ResultMessage { get; private set; }
public string? ConfirmMessage { get; private set; }
public bool SelfProved { get; private set; }
public bool OtherProved { get; private set; }
/// <summary>Display names, set only once both sides are proved.</summary>
public string? SelfName { get; private set; }
public string? OtherName { get; private set; }
/// <summary>The chosen direction, "self" or "other", or null.</summary>
public string? Keep { get; private set; }
public string? KeptName => Keep == Self ? SelfName : Keep == Other ? OtherName : null;
public string? FoldedName => Keep == Self ? OtherName : Keep == Other ? SelfName : null;
public IReadOnlyList<string> PreviewLines { get; private set; } = [];
public IReadOnlyList<string> BlockWords { get; private set; } = [];
public IReadOnlyList<string> Statements => MergePreview.Statements;
public IReadOnlyList<string> ProvidersToProve { get; private set; } = [];
public string Digest { get; private set; } = string.Empty;
public IReadOnlyList<string> LinkableProviders => HeimdallAuthService.LinkableProviders;
public static string ProviderName(string provider) => MergeStatusModel.ProviderName(provider);
private string? AccountId => User.FindFirstValue(BifrostClaimTypes.HeimdallAccountId) is { Length: > 0 } id ? id : null;
/// <summary>Off, the page does not exist; a folded or frozen account is forbidden it, as it is Linked accounts.</summary>
public override async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
{
if (!mergeOptions.Value.Enabled)
{
context.Result = NotFound();
return;
}
var actor = await actors.GetAsync(context.HttpContext.RequestAborted);
if (actor.Merge is not null || actor.UserAccount is null || AccountId is null)
{
context.Result = Forbid();
return;
}
await base.OnPageHandlerExecutionAsync(context, next);
}
public async Task OnGetAsync(CancellationToken cancellationToken)
{
ResultMessage = HeimdallLinkOutcomes.Wording(Request.Query[HeimdallLinkOutcomes.ResultParameter].ToString());
ConfirmMessage = MergeWording.Confirm(Request.Query[MergeParameter].ToString()) is { Length: > 0 } words ? words : null;
var me = (await actors.GetAsync(cancellationToken)).UserAccount!.Id;
var held = proofs.Snapshot(me);
SelfProved = held.Self is not null;
OtherProved = held.Other is not null;
if (held.Self is not { } self || held.Other is not { } other)
{
return;
}
var names = await dbContext.UserAccounts.AsNoTracking()
.Where(x => x.Id == self.UserAccountId || x.Id == other.UserAccountId)
.ToDictionaryAsync(x => x.Id, x => x.DisplayName, cancellationToken);
SelfName = names.GetValueOrDefault(self.UserAccountId);
OtherName = names.GetValueOrDefault(other.UserAccountId);
Stage = MergeStage.Choose;
if (SideOf(Request.Query[KeepParameter].ToString()) is not { } survivorSide)
{
return;
}
Keep = survivorSide == MergeSide.Self ? Self : Other;
var (survivor, folded) = survivorSide == MergeSide.Self ? (self, other) : (other, self);
var plan = await ledger.PlanAsync(survivor.UserAccountId, folded.UserAccountId, cancellationToken);
Digest = plan.Digest(survivor.UserAccountId, folded.UserAccountId);
PreviewLines = MergePreview.Lines(plan);
BlockWords = [.. plan.Blocks.Select(MergePreview.Block)];
switch (proofs.Peek(me, survivorSide))
{
case PeekResult.Ready when plan.Blocks.Count == 0:
Stage = MergeStage.Confirm;
break;
case PeekResult.LoginsUnproved unproved:
ProvidersToProve = unproved.Providers;
Stage = MergeStage.ProveRemaining;
break;
}
}
/// <summary>Starts a fresh sign-in of the account signed in here.</summary>
public Task<IActionResult> OnPostProveSelfAsync(string? via, CancellationToken cancellationToken) => BeginAsync(MergeSide.Self, via, cancellationToken);
/// <summary>Starts a fresh sign-in of the other account. The member names the provider: Bifrost never guesses one.</summary>
public Task<IActionResult> OnPostProveOtherAsync(string? via, CancellationToken cancellationToken) => BeginAsync(MergeSide.Other, via, cancellationToken);
/// <summary>Starts the next sign-in the chosen folded account still owes; its side follows from the chosen direction.</summary>
public Task<IActionResult> OnPostProveRemainingAsync(string? via, string? keep, CancellationToken cancellationToken) =>
SideOf(keep) is { } survivorSide
? BeginAsync(survivorSide == MergeSide.Self ? MergeSide.Other : MergeSide.Self, via, cancellationToken)
: Task.FromResult(Refused(null, "bad_choice"));
/// <summary>
/// The member's consent: both boxes, the direction and the digest of the preview they saw. A refusal writes nothing and keeps the
/// proofs; only a Confirmed row spends them.
/// </summary>
public async Task<IActionResult> OnPostConfirmAsync(string? keep, string? digest, bool consentSelf, bool consentOther, CancellationToken cancellationToken)
{
if (SideOf(keep) is not { } survivorSide)
{
return Refused(null, "bad_choice");
}
if (!consentSelf || !consentOther)
{
return Refused(keep, "consent_needed");
}
var me = (await actors.GetAsync(cancellationToken)).UserAccount!.Id;
var held = proofs.Snapshot(me);
if (held.Self is not { } self || held.Other is not { } other || proofs.Peek(me, survivorSide) is not PeekResult.Ready ready)
{
return Refused(keep, "proofs_needed");
}
var (survivor, folded) = survivorSide == MergeSide.Self ? (self, other) : (other, self);
var outcome = await saga.ConfirmAsync(
new ConfirmMergeRequest(me, survivor.UserAccountId, folded.UserAccountId, digest ?? string.Empty, ready.Survivor, ready.Folded), cancellationToken);
switch (outcome)
{
case ConfirmOutcome.Confirmed confirmed:
proofs.Clear(me);
try
{
await saga.AdvanceAsync(confirmed.MergeId, cancellationToken);
}
catch (Exception error) when (error is not OperationCanceledException)
{
// The stored state is the truth and the sweeper resumes it.
logger.LogWarning("Account merge {MergeId} inline advance failed: {Error}", confirmed.MergeId, error.GetType().Name);
}
return RedirectToPage("/Membership/MergeStatus");
case ConfirmOutcome.Blocked:
return Refused(keep, "blocked");
case ConfirmOutcome.PreviewStale:
return Refused(keep, "preview_stale");
case ConfirmOutcome.NotParty:
return Refused(keep, "not_party");
default:
return Refused(keep, "proof_account_mismatch");
}
}
private static MergeSide? SideOf(string? keep) => keep switch
{
Self => MergeSide.Self,
Other => MergeSide.Other,
_ => null
};
private async Task<IActionResult> BeginAsync(MergeSide side, string? via, CancellationToken cancellationToken)
{
try
{
var start = side == MergeSide.Self
? (Func<string, Task<HeimdallAuthStartResult>>)(id => heimdallAuthService.StartMergeProveSelfAsync(
id, via, ReturnPath, hostOptions.Value.PublicBaseUrl, Request.Cookies, cancellationToken))
: id => heimdallAuthService.StartMergeProveOtherAsync(
id, via, ReturnPath, hostOptions.Value.PublicBaseUrl, Request.Cookies, cancellationToken);
var started = await start(AccountId!);
Response.Cookies.Append(started.CookieName, started.CookieValue, HeimdallAttemptCookie.Options());
return Redirect(started.AuthorizationUrl.ToString());
}
catch (HeimdallAuthException error)
{
logger.LogWarning("Merge proof start refused: {Reason}", error.Message);
return RedirectToPage(null, new Dictionary<string, string?> { [HeimdallLinkOutcomes.ResultParameter] = HeimdallLinkOutcomes.Code(HeimdallLinkOutcome.Error) });
}
}
private const string ReturnPath = "/Membership/MergeAccounts";
private IActionResult Refused(string? keep, string code)
{
var query = new Dictionary<string, string?>();
if (keep is Self or Other)
{
query[KeepParameter] = keep;
}
query[MergeParameter] = code;
return RedirectToPage(null, query);
}
}

View file

@ -19,7 +19,6 @@ namespace Bifrost.Web.Tests;
public sealed class MergeAccountsPageTests
{
private const string Url = MergePage.AccountsUrl;
private const string MyName = "quill-9f3a";
private const string OtherName = "banks-2d7c";
private static string Enc(string text) => System.Text.Encodings.Web.HtmlEncoder.Default.Encode(text);
@ -34,6 +33,9 @@ public sealed class MergeAccountsPageTests
public string Session { get; private init; } = string.Empty;
/// <summary>The name the account carries after signing in (a sign-in refreshes it from Heimdall).</summary>
public string MyName { get; private init; } = string.Empty;
public MergePage.Antiforgery? Token { get; private set; }
public HeimdallHost Host => Rig.Host;
@ -47,10 +49,11 @@ public sealed class MergeAccountsPageTests
public static async Task<World> Make(bool enabled = true)
{
var rig = new Rig(realSessions: true, accountMerge: enabled);
var me = await rig.AccountAsync(MyName, "discord");
var me = await rig.AccountAsync("quill-9f3a", "discord");
var other = await rig.AccountAsync(OtherName, "patreon", "google");
var session = await rig.Host.SignInSessionAsync(me.HeimdallId, "discord");
var world = new World { Rig = rig, Me = me, Other = other, Session = session };
var myName = await rig.InScopeAsync(async sp => (await sp.GetRequiredService<BifrostDbContext>().UserAccounts.AsNoTracking().SingleAsync(x => x.Id == me.Id)).DisplayName);
var world = new World { Rig = rig, Me = me, Other = other, Session = session, MyName = myName };
if (enabled)
{
world.Token = await MergePage.TokenAsync(rig.Host, session, Url);
@ -175,9 +178,13 @@ public sealed class MergeAccountsPageTests
var (response, _) = await w.Get(session: folded);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
AssertRefused(response);
}
/// <summary>Forbid answers 403 or sends the browser to the access-denied page; either way the page is not served.</summary>
private static void AssertRefused(HttpResponseMessage response) =>
Assert.True(response.StatusCode is HttpStatusCode.Forbidden or HttpStatusCode.Found, response.StatusCode.ToString());
// ---- stages derive from the proofs held ----
[Fact]
@ -229,7 +236,7 @@ public sealed class MergeAccountsPageTests
var page = await w.Page();
Assert.Contains(MyName, page);
Assert.Contains(w.MyName, page);
Assert.Contains(OtherName, page);
Assert.Contains("Keep this account", page);
Assert.Contains("Keep the other account", page);
@ -456,7 +463,7 @@ public sealed class MergeAccountsPageTests
Assert.Equal(survivor.Id, merge.SurvivorUserAccountId);
Assert.Equal(w.Me.Id, merge.ConfirmedByUserAccountId);
Assert.Equal(digest, merge.PreviewDigest);
Assert.NotNull(merge.SealedProofs);
Assert.Null(merge.SealedProofs); // spent by the move that landed
if (keep == "self")
{
Assert.Equal("discord", merge.SurvivorProofProvider);
@ -471,6 +478,23 @@ public sealed class MergeAccountsPageTests
Assert.Equal(new MergeProofsView(null, null), w.Proofs.Snapshot(w.Me.Id));
}
[Fact]
public async Task A_confirm_while_Heimdall_is_unreachable_still_lands_on_Merge_status_with_the_row_Confirmed_and_the_proofs_sealed()
{
using var w = await World.Make();
await w.ProveAll();
var digest = World.DigestIn(await w.Page("?keep=self"));
w.Rig.Moves.MoveDown = new HttpRequestException("down");
var response = await w.Confirm("self", digest);
Assert.Equal(MergePage.Url, MergePage.Location(response));
var merge = Assert.Single(await w.Rig.InScopeAsync(sp => sp.GetRequiredService<BifrostDbContext>().AccountMerges.AsNoTracking().ToListAsync()));
Assert.Equal(AccountMergeState.Confirmed, merge.State);
Assert.NotNull(merge.SealedProofs);
Assert.Equal(new MergeProofsView(null, null), w.Proofs.Snapshot(w.Me.Id));
}
[Fact]
public async Task The_whole_flow_by_sign_ins_ends_on_the_survivors_status_with_a_notice_and_the_folded_cookie_has_no_actor()
{
@ -489,7 +513,7 @@ public sealed class MergeAccountsPageTests
Assert.Contains("Undo window ends", status);
Assert.Contains("can still be undone", status);
var (foldedResponse, _) = await w.Host.GetLinkedAccountsAsync(foldedSession);
Assert.Equal(HttpStatusCode.Forbidden, foldedResponse.StatusCode);
AssertRefused(foldedResponse);
var everything = string.Join('\n', w.Surface) + status;
Assert.All(w.Bearers, bearer => Assert.DoesNotContain(bearer, everything));