Empty but complete solution so every later phase starts from a working toolchain: analyzers as errors, locked restore, format check, policy tests that keep packages within ADR 0004 and keep live trading switched off, a /health endpoint served from Docker, and a Gitea workflow with only run steps. API facts of SPEC section 4 re-checked in docs/API-NOTES.md; ADR 0006 records what changed (MSTest base packages, Ubuntu images, OKX WebSocket on 443, Alpaca margin-only accounts). refs #1 refs #2 refs #3 refs #4 refs #5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
65 lines
2.7 KiB
C#
65 lines
2.7 KiB
C#
using System.Text.RegularExpressions;
|
|
|
|
namespace Anubis.Tests;
|
|
|
|
/// <summary>SPEC 2.2: no secret in the repository. Only .env.example with fake values.</summary>
|
|
[TestClass]
|
|
public sealed partial class SecretScanTests
|
|
{
|
|
private static readonly HashSet<string> _binaryExtensions = new(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
".png", ".jpg", ".jpeg", ".ico", ".gif", ".webp", ".ttf", ".woff", ".woff2", ".onnx", ".dll", ".exe", ".pdb", ".zip", ".gz",
|
|
};
|
|
|
|
[TestMethod]
|
|
[TestCategory(Category.Unit)]
|
|
public void RepositoryContainsNoSecrets()
|
|
{
|
|
var findings = new List<string>();
|
|
foreach (var file in Repo.Files().Where(f => !_binaryExtensions.Contains(f.Extension)))
|
|
{
|
|
var lineNumber = 0;
|
|
foreach (var line in File.ReadLines(file.FullName))
|
|
{
|
|
lineNumber++;
|
|
if (LooksLikeSecret(line))
|
|
{
|
|
findings.Add($"{Repo.Relative(file)}:{lineNumber}");
|
|
}
|
|
}
|
|
}
|
|
|
|
Assert.IsEmpty(findings, "Possibili segreti: " + string.Join(", ", findings));
|
|
}
|
|
|
|
[TestMethod]
|
|
[TestCategory(Category.Unit)]
|
|
public void DetectorFindsTypicalSecretsAndIgnoresPlaceholders()
|
|
{
|
|
Assert.IsTrue(LooksLikeSecret("-----BEGIN " + "PRIVATE KEY-----"));
|
|
Assert.IsTrue(LooksLikeSecret("APCA-API-SECRET-KEY: " + new string('a', 40)));
|
|
Assert.IsTrue(LooksLikeSecret("OK-ACCESS-PASSPHRASE=" + "Sup3rS3cretPass"));
|
|
Assert.IsTrue(LooksLikeSecret("TELEGRAM_BOT_TOKEN=123456789:" + new string('A', 35)));
|
|
Assert.IsTrue(LooksLikeSecret("api_key = \"" + "AKZXCVBNMASDFGHJKLQWERTY12" + "\""));
|
|
|
|
Assert.IsFalse(LooksLikeSecret("ANUBIS_SECRET_KEY=replace-with-random"));
|
|
Assert.IsFalse(LooksLikeSecret("APCA-API-SECRET-KEY: <your-secret>"));
|
|
Assert.IsFalse(LooksLikeSecret("POSTGRES_PASSWORD: anubis-dev"));
|
|
}
|
|
|
|
private static bool LooksLikeSecret(string line) =>
|
|
PrivateKey().IsMatch(line) || BrokerHeader().IsMatch(line) || TelegramToken().IsMatch(line) || GenericSecret().IsMatch(line);
|
|
|
|
[GeneratedRegex("-----BEGIN (RSA |EC |OPENSSH |DSA )?PRIVATE KEY-----")]
|
|
private static partial Regex PrivateKey();
|
|
|
|
[GeneratedRegex("""(APCA-API-(KEY-ID|SECRET-KEY)|OK-ACCESS-(KEY|SIGN|PASSPHRASE))\s*[:=]\s*["']?[A-Za-z0-9/+=_\-]{12,}""")]
|
|
private static partial Regex BrokerHeader();
|
|
|
|
[GeneratedRegex(@"\b\d{8,10}:[A-Za-z0-9_\-]{35}\b")]
|
|
private static partial Regex TelegramToken();
|
|
|
|
[GeneratedRegex("""(?i)(api[_-]?key|secret|token|passphrase|password)["']?\s*[:=]\s*["']?(?=[A-Za-z0-9/+=_\-]*\d)(?=[A-Za-z0-9/+=_\-]*[A-Za-z])[A-Za-z0-9/+=_\-]{24,}""")]
|
|
private static partial Regex GenericSecret();
|
|
}
|