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"]; var offenders = Repo.Files() .Where(f => extensions.Contains(f.Extension, StringComparer.OrdinalIgnoreCase) || f.Name.StartsWith(".env", StringComparison.OrdinalIgnoreCase) || f.Name.Equals("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 PatternRecognisesBothSwitches() { Assert.IsTrue(LiveSwitch().IsMatch("ANUBIS_ALLOW_LIVE=1")); Assert.IsTrue(LiveSwitch().IsMatch(" ANUBIS_ALLOW_LIVE: \"1\"")); Assert.IsTrue(LiveSwitch().IsMatch("allow_live = true")); Assert.IsFalse(LiveSwitch().IsMatch("ANUBIS_ALLOW_LIVE=0")); Assert.IsFalse(LiveSwitch().IsMatch("allow_live = false")); } [GeneratedRegex("""ANUBIS_ALLOW_LIVE\s*[:=]\s*["']?1\b|allow_live\s*=\s*true\b""", RegexOptions.IgnoreCase)] private static partial Regex LiveSwitch(); }