ServerPack: card actions, web open, usage lines #1
3 changed files with 26 additions and 4 deletions
ServerPack web open: a request never prints its URL; Windows error wording
WebOpenRequest is a record, so its generated ToString printed the URL, which can carry a one-time code. It now names the title only. The browser failure reads "Couldn't open your browser (Windows error N)." Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
commit
8dda4fdf96
|
|
@ -70,12 +70,12 @@ public sealed partial class ServerPackPlugin
|
||||||
{
|
{
|
||||||
long code = ShellExecuteW(IntPtr.Zero, "open", url, null, null, 1).ToInt64();
|
long code = ShellExecuteW(IntPtr.Zero, "open", url, null, null, 1).ToInt64();
|
||||||
ok = code > 32;
|
ok = code > 32;
|
||||||
message = ok ? "Opened in your browser." : $"Couldn't open your browser (code {code}).";
|
message = ok ? "Opened in your browser." : $"Couldn't open your browser (Windows error {code}).";
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
ok = false;
|
ok = false;
|
||||||
message = "Couldn't open your browser (code 0).";
|
message = "Couldn't open your browser (Windows error 0).";
|
||||||
}
|
}
|
||||||
Finish(done, new WebOpenOutcome(WebOpenRoute.Browser, ok, message));
|
Finish(done, new WebOpenOutcome(WebOpenRoute.Browser, ok, message));
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,14 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace RynthCore.Plugin.ServerPack;
|
namespace RynthCore.Plugin.ServerPack;
|
||||||
|
|
||||||
/// <summary>A page to open. The URL comes from constants in the plugin, never from chat.</summary>
|
/// <summary>
|
||||||
internal sealed record WebOpenRequest(string Url, IReadOnlyList<string> AllowedHosts, string ProfileKey, string Title);
|
/// A page to open. The URL comes from constants in the plugin, never from chat, but it may carry a
|
||||||
|
/// one-time code, so ToString names the title only (a record's generated ToString would print the URL).
|
||||||
|
/// </summary>
|
||||||
|
internal sealed record WebOpenRequest(string Url, IReadOnlyList<string> AllowedHosts, string ProfileKey, string Title)
|
||||||
|
{
|
||||||
|
public override string ToString() => "WebOpenRequest(" + Title + ")";
|
||||||
|
}
|
||||||
|
|
||||||
internal enum WebOpenRoute { Panel, Browser, Refused }
|
internal enum WebOpenRoute { Panel, Browser, Refused }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,28 @@ internal static class ServerWebOpenTests
|
||||||
public static void Register(Runner r)
|
public static void Register(Runner r)
|
||||||
{
|
{
|
||||||
r.Add("web open: only https on an allowed host, and the route follows the engine", Rules);
|
r.Add("web open: only https on an allowed host, and the route follows the engine", Rules);
|
||||||
|
r.Add("web open: a request never prints its URL, and the browser's error says Windows", NoUrlInText);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly string[] Hosts = { "www.acdreamweave.com" };
|
private static readonly string[] Hosts = { "www.acdreamweave.com" };
|
||||||
private static readonly string[] Wild = { "*.acdreamweave.com" };
|
private static readonly string[] Wild = { "*.acdreamweave.com" };
|
||||||
private const string Key = "dreamweave/0123456789abcdef0123456789abcdef";
|
private const string Key = "dreamweave/0123456789abcdef0123456789abcdef";
|
||||||
|
|
||||||
|
private static void NoUrlInText()
|
||||||
|
{
|
||||||
|
const string secret = "AbCdEfGhIjKlMnOpQrStUvWxYz0123456789-_AbCde";
|
||||||
|
var r = new WebOpenRequest("https://www.acdreamweave.com/launch?code=" + secret + "&to=%2Fmarket", Hosts, Key, "DreamWeave");
|
||||||
|
Check.Eq(r.ToString(), "WebOpenRequest(DreamWeave)", "ToString names the title only");
|
||||||
|
Check.False(r.ToString().Contains(secret, StringComparison.Ordinal), "ToString never carries the code");
|
||||||
|
Check.False(("" + r).Contains("acdreamweave", StringComparison.Ordinal), "nor the URL");
|
||||||
|
Check.False((r with { Title = "x" }).ToString().Contains(secret, StringComparison.Ordinal), "a copy neither");
|
||||||
|
|
||||||
|
string web = System.IO.File.ReadAllText(System.IO.Path.Combine(ServerProjectsTests.PluginsDir(), "Shared", "ServerPack", "ServerPackWeb.cs"));
|
||||||
|
Check.True(web.Contains("$\"Couldn't open your browser (Windows error {code}).\"", StringComparison.Ordinal), "the browser failure names the Windows error");
|
||||||
|
Check.True(web.Contains("\"Couldn't open your browser (Windows error 0).\"", StringComparison.Ordinal), "and its exception path");
|
||||||
|
Check.False(web.Contains("(code ", StringComparison.Ordinal), "the old \"(code N)\" wording is gone");
|
||||||
|
}
|
||||||
|
|
||||||
private static void Rules()
|
private static void Rules()
|
||||||
{
|
{
|
||||||
Check.True(ServerWebOpen.IsAllowedUrl("https://www.acdreamweave.com/x", Hosts), "https on the host");
|
Check.True(ServerWebOpen.IsAllowedUrl("https://www.acdreamweave.com/x", Hosts), "https on the host");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue