using System.Text.RegularExpressions; namespace Anubis.Tests; /// SPEC 2.2: real money must never be enabled during development. [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'", "1", "0", "allow_live = true", "\"allow_live\": true", ]; string[] inactive = [ "ANUBIS_ALLOW_LIVE=0", "ANUBIS_ALLOW_LIVE: \"0\"", "ENV ANUBIS_ALLOW_LIVE 10", "0", "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(); }