Files
Anubis/tests/Anubis.Tests/LiveSafetyTests.cs
Alby96andClaude Opus 5.5 52550ee6d1
ci / test (postgres) (push) Successful in 1m24s
ci / test (sqlite) (push) Successful in 1m35s
ci / image (push) Successful in 16s
ci / test (postgres) (pull_request) Successful in 1m11s
ci / test (sqlite) (pull_request) Successful in 1m24s
ci / image (pull_request) Successful in 14s
Close phase 0 review findings: stricter policy scans, property generator, hook
The independent review found that the policy tests could be bypassed:
Microsoft-named direct packages and GlobalPackageReference slipped past
the dependency check, the live-money scan missed the JSON, Dockerfile
and Unraid template forms, the secret scan missed short project
secrets but would have failed on the user's own ignored .env. The
scans now read only the files git would commit and cover those cases.

Also adds the fixed-seed generator for property tests, the REGISTRY
variables reserved for phase 9 in the CI, a git pre-commit hook in
place of the pre-commit tool (tasks hooks), the missing SPEC 4 facts
in API-NOTES (Fed/ECB/BLS times, USDC depth on OKX) and the full list
of today's indirect packages.

refs #3 refs #5 refs #6

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 10:05:10 +01:00

84 lines
3.2 KiB
C#

using System.Text.RegularExpressions;
namespace Anubis.Tests;
/// <summary>SPEC 2.2: real money must never be enabled during development.</summary>
[TestClass]
public sealed partial class LiveSafetyTests
{
[TestMethod]
[TestCategory(Category.Unit)]
public void AllowLiveIsNotSetInTheEnvironment()
{
var value = Environment.GetEnvironmentVariable("ANUBIS_ALLOW_LIVE");
Assert.IsFalse(value?.Trim() == "1", "ANUBIS_ALLOW_LIVE=1 è attivo: durante lo sviluppo non si attiva mai (SPEC 2.2).");
}
[TestMethod]
[TestCategory(Category.Unit)]
public void NoConfigurationFileEnablesRealMoney()
{
// Configuration-like files only: the documentation quotes the switches to forbid them.
string[] extensions =
[
".toml", ".env", ".yml", ".yaml", ".json", ".xml", ".ps1", ".sh", ".props", ".targets", ".csproj",
".runsettings", ".config", ".ini", ".conf",
];
var offenders = Repo.Files()
.Where(f => extensions.Contains(f.Extension, StringComparer.OrdinalIgnoreCase)
|| f.Name.StartsWith(".env", StringComparison.OrdinalIgnoreCase)
|| f.Name.StartsWith("Dockerfile", StringComparison.OrdinalIgnoreCase))
.Where(f => LiveSwitch().IsMatch(File.ReadAllText(f.FullName)))
.Select(Repo.Relative)
.ToList();
Assert.IsEmpty(offenders, "Soldi veri attivi in: " + string.Join(", ", offenders));
}
[TestMethod]
[TestCategory(Category.Unit)]
public void PatternRecognisesBothSwitchesInEveryFormat()
{
string[] active =
[
"ANUBIS_ALLOW_LIVE=1",
" ANUBIS_ALLOW_LIVE: \"1\"",
"\"ANUBIS_ALLOW_LIVE\": \"1\"",
"\"ANUBIS_ALLOW_LIVE\": 1",
"ENV ANUBIS_ALLOW_LIVE 1",
"$env:ANUBIS_ALLOW_LIVE = '1'",
"<Config Name=\"Soldi veri\" Target=\"ANUBIS_ALLOW_LIVE\" Default=\"0|1\" Type=\"Variable\">1</Config>",
"<Config Target=\"ANUBIS_ALLOW_LIVE\" Default=\"1|0\" Type=\"Variable\">0</Config>",
"allow_live = true",
"\"allow_live\": true",
];
string[] inactive =
[
"ANUBIS_ALLOW_LIVE=0",
"ANUBIS_ALLOW_LIVE: \"0\"",
"ENV ANUBIS_ALLOW_LIVE 10",
"<Config Name=\"Soldi veri\" Target=\"ANUBIS_ALLOW_LIVE\" Default=\"0|1\" Description=\"1: abilita\" Type=\"Variable\">0</Config>",
"allow_live = false",
];
foreach (var line in active)
{
Assert.IsTrue(LiveSwitch().IsMatch(line), "Non riconosciuto: " + line);
}
foreach (var line in inactive)
{
Assert.IsFalse(LiveSwitch().IsMatch(line), "Falso allarme: " + line);
}
}
// Assignments (=, :, JSON, ENV with a space, PowerShell) and the Unraid template's value or default.
[GeneratedRegex(
"""ANUBIS_ALLOW_LIVE["']?\s*(?:[:=]|\s)\s*["']?1\b"""
+ """|Target=["']ANUBIS_ALLOW_LIVE["'][^>]*>\s*1\s*<"""
+ """|Target=["']ANUBIS_ALLOW_LIVE["'][^>]*\bDefault=["']1\b"""
+ """|allow_live["']?\s*[:=]\s*["']?true\b""",
RegexOptions.IgnoreCase)]
private static partial Regex LiveSwitch();
}