RynthDreamWeave: per-account web profile key

WebProfile.Key(serverId, account) = serverId/ + 32 lowercase hex of SHA-256 over the server id and the trimmed, lower-cased account; null without an account. Keys pass ServerWebOpen.IsValidProfileKey.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Daniel Wallace 2026-11-07 15:01:35 -08:00
commit 2522534979
3 changed files with 49 additions and 0 deletions

View file

@ -27,6 +27,7 @@ internal static class DreamWeaveWebTests
r.Add("dreamweave web: reset keeps the throttle", ResetKeepsThrottle);
r.Add("dreamweave web: a late code is eaten while it could still be valid", LateCodeIsStale);
r.Add("dreamweave web: overlapping requests never leak a code to chat", OverlappingRequests);
r.Add("dreamweave web: profile keys separate accounts", ProfileKeys);
}
private const string Code = "AbCdEfGhIjKlMnOpQrStUvWxYz0123456789-_AbCde"; // 43 chars
@ -354,6 +355,30 @@ internal static class DreamWeaveWebTests
Check.True(u.OnChatLine(Line, 0x05, 70_000, out _, out _, out _) == LaunchLine.NotOurs, "+70,000 not ours");
}
private static void ProfileKeys()
{
string? a = WebProfile.Key("dreamweave", "Alice");
string? b = WebProfile.Key("dreamweave", "Bob");
Check.True(a != null && b != null, "keys exist");
Check.True(a != b, "different accounts -> different keys");
Check.Eq(WebProfile.Key("dreamweave", " alice "), a, "trimmed and case-folded");
Check.Eq(WebProfile.Key("dreamweave", "ALICE"), a, "case-folded");
Check.Eq(WebProfile.Key("dreamweave", "Alice"), a, "stable across calls");
Check.True(WebProfile.Key("coldeve", "Alice") != a, "same account, other server -> different key");
Check.True(a!.StartsWith("dreamweave/", StringComparison.Ordinal), "prefixed by the server id");
string[] accounts = { "Alice", "Bob", "a", "x y", "caf" + (char)0xE9, "A-very-long-account-name-0123456789-0123456789-0123456789" };
foreach (string acct in accounts)
{
string? k = WebProfile.Key("dreamweave", acct);
Check.True(ServerWebOpen.IsValidProfileKey(k), "valid key for " + acct.Length + " chars");
// A 1-2 char account could appear in the server id or the hex by chance; the rest cannot.
if (acct.Length >= 3) Check.True(!k!.Contains(acct.Trim().ToLowerInvariant()), "key never contains the account text");
}
Check.True(WebProfile.Key("dreamweave", null) == null, "null account -> null");
Check.True(WebProfile.Key("dreamweave", "") == null, "empty account -> null");
Check.True(WebProfile.Key("dreamweave", " ") == null, "blank account -> null");
}
private static void OverlappingRequests()
{
// Scenario 1: request 1 times out, request 2 begins, request 1's late code arrives.

View file

@ -38,6 +38,7 @@
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthDreamWeave\DreamWeave\DreamWeaveWeb.cs" Link="DreamWeave\DreamWeaveWeb.cs" />
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthDreamWeave\DreamWeave\LaunchWire.cs" Link="DreamWeave\LaunchWire.cs" />
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthDreamWeave\DreamWeave\WebLauncher.cs" Link="DreamWeave\WebLauncher.cs" />
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthDreamWeave\DreamWeave\WebProfile.cs" Link="DreamWeave\WebProfile.cs" />
<!-- RynthConquest's own features (pure parts) and the RynthOracle sources it links. -->
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthConquest\Conquest\ConquestData.cs" Link="Conquest\ConquestData.cs" />
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthConquest\Conquest\ConquestFeature.cs" Link="Conquest\ConquestFeature.cs" />