Le 14 osservazioni della revisione di funzione/senza-terzi, ciascuna con la prova che l'avrebbe trovata. Installatore: un aggiornamento senza /D= va nella cartella già installata (InstallLocation) invece che in quella predefinita, che lasciava la vecchia copia. Una cartella senza permessi non sembra più «Febe aperto». La dimensione in «App installate» conta solo i due file dell'installatore. I file in sola lettura si sostituiscono e si tolgono. «Febe» in Esegui all'avvio si toglie solo se avvia quella copia, non un Febe portatile. Febe parte alla fine solo con «Fine» e la casella spuntata. /PROVA= rifiuta la radice di un disco. CI: jq non c'era ed era un componente esterno. JSON letto e scritto con .gitea/scripts/json.sh (json-campi.awk e json-stringa.awk sul lettore json.awk) per gitleaks, Trivy e la release. Le credenziali del registro stanno solo in un DOCKER_CONFIG temporaneo della pubblicazione, con plugin, contesti e contesto corrente del runner, tolto alla fine. Le prove del rilascio girano in debian:trixie con Chromium, come la verifica, senza prove saltate. Ogni flusso usa shell: bash. Caratteri: tolti fonts-liberation e fonts-noto-color-emoji dall'immagine e dalle prove della CI, perché Chromium non li chiede. Resta fonts-dejavu-core. Icone: la prova della griglia legge davvero i percorsi SVG (tutti i comandi, archi e curve) e i punti. La lettura dei nomi delle icone vede ogni forma con cui l'interfaccia li chiede. Schermate: tools/schermate (Node) diventa tools/Febe.Schermate, in C# con ClientWebSocket e System.Text.Json, nessun pacchetto, solo verso indirizzi di questo computer. Provato contro una dimostrazione con Edge su Windows. Documenti: CLAUDE.md, processo, guida, LEGGIMI e docker.md aggiornati. Righe nuove in decisioni.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
279 lines
14 KiB
C#
279 lines
14 KiB
C#
using System.Text.RegularExpressions;
|
|
using Febe.Tests.Desktop.Support;
|
|
using Febe.Tests.Support;
|
|
|
|
namespace Febe.Tests.Packaging;
|
|
|
|
/// <summary>
|
|
/// The CI of the repository (.gitea/workflows/verifica.yml, pulizia.yml and the scripts of .gitea/scripts), read as
|
|
/// text: the rules that must survive later edits. Every push of every branch is verified and nothing else triggers
|
|
/// it twice; the tests run only through tests/Febe.Tests, with the browser, and again with the seed of the run; the
|
|
/// image is published only from main and never as :latest; credentials are never printed; the external tools are
|
|
/// pinned and checked; the tried container never has a network. The cleanup, which runs against fake docker and curl
|
|
/// clients, is in PipelineTests.Pulizia.cs.
|
|
/// </summary>
|
|
[TestClass]
|
|
public sealed partial class PipelineTests
|
|
{
|
|
private static readonly string[] Jobs = ["controlli", "prove", "installatore", "immagine"];
|
|
|
|
public TestContext TestContext { get; set; } = null!;
|
|
|
|
[TestMethod]
|
|
public void EveryPushOfEveryBranchIsVerifiedOnceAndTagsAreLeftToTheRelease()
|
|
{
|
|
var workflow = Workflow("verifica.yml");
|
|
StringAssert.Contains(workflow, "on:\n push:\n branches: [\"**\"]\n workflow_dispatch:");
|
|
var code = Code(workflow);
|
|
Assert.DoesNotContain("pull_request", code, "a PR shows the status of its head commit, already verified by the push");
|
|
Assert.DoesNotContain("tags:", code, "tags belong to rilascio.yml");
|
|
StringAssert.Contains(code, "cancel-in-progress: ${{ gitea.ref != 'refs/heads/main' }}", "every merge into main runs to the end");
|
|
|
|
// A run started by hand never cancels the run of a push: only that one writes the statuses a merge needs.
|
|
StringAssert.Contains(code, "group: verifica-${{ gitea.event_name }}-${{ gitea.ref }}");
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TheJobsFollowOneAnotherAndEachHasATimeout()
|
|
{
|
|
var workflow = Workflow("verifica.yml");
|
|
foreach (var job in Jobs)
|
|
{
|
|
StringAssert.Contains(Job(workflow, job), "timeout-minutes:", job);
|
|
}
|
|
|
|
StringAssert.Contains(Job(workflow, "prove"), "needs: controlli");
|
|
StringAssert.Contains(Job(workflow, "installatore"), "needs: prove");
|
|
StringAssert.Contains(Job(workflow, "immagine"), "needs: [prove, installatore]", ":main comes only from a commit whose whole verification is green");
|
|
foreach (var other in new[] { "rilascio.yml", "pulizia.yml" })
|
|
{
|
|
var text = Workflow(other);
|
|
foreach (Match job in JobHeader().Matches(text))
|
|
{
|
|
StringAssert.Contains(Job(text, job.Groups["name"].Value), "timeout-minutes:", $"{other}: {job.Groups["name"].Value}");
|
|
}
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TheWholeSolutionIsBuiltAndTheTestsRunOnlyThroughTheTestProjectWithTheBrowser()
|
|
{
|
|
var prove = Job(Workflow("verifica.yml"), "prove");
|
|
StringAssert.Contains(prove, "container:\n image: debian:trixie", "Debian: Chromium is a real package there, a snap on Ubuntu; and no Node in it");
|
|
StringAssert.Contains(prove, "bash .gitea/scripts/ambiente-prove.sh");
|
|
StringAssert.Contains(prove, "dotnet build Febe.slnx -c Release -nologo -warnaserror");
|
|
StringAssert.Contains(prove, "bash .gitea/scripts/riepilogo-prove.sh out/prove 0", "no test may skip itself in the CI");
|
|
|
|
// The second pass: the tests of the synthetic world again, with the seed of the run in the variable the helper reads.
|
|
StringAssert.Contains(prove, $"{SyntheticSite.Variable}: ${{{{ steps.semi.outputs.seme }}}}");
|
|
StringAssert.Contains(prove, $"--filter \"TestCategory={SyntheticSite.Category}\"");
|
|
|
|
var environment = Script("ambiente-prove.sh");
|
|
foreach (var package in new[] { "chromium", "xvfb", "ffmpeg", "locales" })
|
|
{
|
|
StringAssert.Contains(environment, package);
|
|
}
|
|
|
|
// The installer is ours (src/Febe.Installer): no installer tool, no zip, nothing to install for it.
|
|
foreach (var gone in new[] { "nsis", "zip" })
|
|
{
|
|
Assert.IsFalse(Regex.IsMatch(Code(environment), $@"\b{gone}\b"), $"ambiente-prove.sh: «{gone}»");
|
|
}
|
|
|
|
foreach (var (name, job) in new[] { ("verifica.yml", "installatore"), ("rilascio.yml", "windows") })
|
|
{
|
|
var steps = Job(Workflow(name), job);
|
|
StringAssert.Contains(steps, "bash installer/costruisci.sh", $"{name}: {job}");
|
|
Assert.DoesNotContain("apt-get", steps, $"{name}: {job} needs only the .NET SDK");
|
|
}
|
|
|
|
// tests/Febe.Tests.Windows runs only on Windows: never «dotnet test» on the solution or without a project.
|
|
foreach (var name in new[] { "verifica.yml", "rilascio.yml" })
|
|
{
|
|
foreach (Match test in DotnetTest().Matches(Code(Workflow(name))))
|
|
{
|
|
Assert.AreEqual("tests/Febe.Tests", test.Groups["target"].Value, $"{name}: {test.Value}");
|
|
}
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TheImageIsPublishedOnlyAfterAPushToMainAsMainAndShaNeverAsLatest()
|
|
{
|
|
var image = Job(Workflow("verifica.yml"), "immagine");
|
|
var decision = Step(image, "Pubblicare?");
|
|
StringAssert.Contains(decision, "[ \"$EVENTO\" != push ] || [ \"$RIFERIMENTO\" != refs/heads/main ]");
|
|
StringAssert.Contains(decision, "::warning::Manca il segreto REGISTRY_TOKEN");
|
|
Assert.DoesNotContain("exit 1", decision, "without the secret the job stays green");
|
|
var publish = Step(image, "Pubblicazione come :main e :sha-<commit>");
|
|
StringAssert.Contains(publish, "if: steps.segreto.outputs.presente == 'si'");
|
|
StringAssert.Contains(publish, "\"$IMAGE:sha-${GITHUB_SHA::7}\"");
|
|
StringAssert.Contains(publish, "\"$IMAGE:main\"");
|
|
StringAssert.Contains(publish, "bash .gitea/scripts/costruisci-immagine.sh pubblica");
|
|
StringAssert.Contains(publish, "| cut -f1) || CIMA=\"\"", "under bash -e an unreadable main must reach the warning and still publish :sha-");
|
|
Assert.DoesNotContain(":latest", Code(Workflow("verifica.yml")), ":latest belongs to the release");
|
|
|
|
// Built with buildx, tried without a network and scanned before anything is published; always cleaned up.
|
|
StringAssert.Contains(image, "BUILDER: febe-ci-${{ gitea.run_id }}");
|
|
StringAssert.Contains(image, "bash .gitea/scripts/costruisci-immagine.sh builder \"$REGISTRY\"");
|
|
var builder = Code(Script("costruisci-immagine.sh"));
|
|
StringAssert.Contains(builder, "http = true");
|
|
StringAssert.Contains(builder, "insecure = true");
|
|
StringAssert.Contains(builder, "--driver docker-container");
|
|
var decide = image.IndexOf("- name: Pubblicare?", StringComparison.Ordinal);
|
|
foreach (var gate in new[] { "bash .gitea/scripts/costruisci-immagine.sh archivio", "bash .gitea/scripts/prova-immagine.sh", "bash .gitea/scripts/scansione-immagine.sh" })
|
|
{
|
|
var at = image.IndexOf(gate, StringComparison.Ordinal);
|
|
Assert.IsTrue(at >= 0 && at < decide, $"«{gate}» comes before the publication");
|
|
}
|
|
var cleanup = Step(image, "Pulizia (sempre)");
|
|
StringAssert.Contains(cleanup, "if: always()");
|
|
StringAssert.Contains(cleanup, "bash .gitea/scripts/pulizia-docker.sh esecuzione \"$ESECUZIONE\"");
|
|
StringAssert.Contains(cleanup, "rm -rf \"${RUNNER_TEMP:-/tmp}/febe-docker-$ESECUZIONE\"", "the client configuration with the credentials goes, even after an interruption");
|
|
}
|
|
|
|
[TestMethod]
|
|
public void SecretsAreNeverPrintedNorTheDaemonUsedForTheRegistry()
|
|
{
|
|
foreach (var (name, text) in AllCiFiles())
|
|
{
|
|
var code = Code(text);
|
|
Assert.DoesNotContain("docker login", code, name);
|
|
Assert.DoesNotContain("docker push", code, name);
|
|
Assert.IsFalse(Trace().IsMatch(code), $"{name}: no shell tracing (it would print secrets)");
|
|
|
|
// A secret goes into echo or printf only to be piped or redirected, never to the log.
|
|
foreach (var line in code.Split('\n').Where(l => Printing().IsMatch(l)))
|
|
{
|
|
var secret = SecretReference().Match(line);
|
|
if (secret.Success)
|
|
{
|
|
var after = line[secret.Index..];
|
|
Assert.IsTrue(after.Contains('|', StringComparison.Ordinal) || after.Contains('>', StringComparison.Ordinal), $"{name}: «{line.Trim()}» would print a secret");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TheExternalToolsArePinnedAndCheckedAndNoThirdPartyActionRunsThem()
|
|
{
|
|
var tool = Script("strumento.sh");
|
|
StringAssert.Contains(tool, "versione=\"8.30.1\"");
|
|
StringAssert.Contains(tool, "versione=\"0.75.0\"");
|
|
Assert.HasCount(2, Sha256().Matches(tool), "one SHA-256 per tool");
|
|
StringAssert.Contains(tool, "sha256sum -c");
|
|
Assert.DoesNotContain("latest", Code(tool));
|
|
foreach (var (name, text) in AllCiFiles())
|
|
{
|
|
Assert.DoesNotContain("trivy-action", Code(text), name);
|
|
Assert.DoesNotContain("gitleaks-action", Code(text), name);
|
|
}
|
|
|
|
var secrets = Script("segreti.sh");
|
|
StringAssert.Contains(secrets, "--redact");
|
|
StringAssert.Contains(Step(Job(Workflow("verifica.yml"), "controlli"), "Sorgenti"), "PROFONDITA: \"0\"", "gitleaks reads the whole history");
|
|
var scan = Script("scansione-immagine.sh");
|
|
StringAssert.Contains(scan, "--severity CRITICAL --ignore-unfixed");
|
|
StringAssert.Contains(scan, "--exit-code 1");
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TheTriedContainerNeverHasANetworkAndAlwaysCarriesTheMarkNoImageHas()
|
|
{
|
|
var smoke = Code(Script("prova-immagine.sh"));
|
|
var runs = DockerRun().Matches(smoke);
|
|
Assert.IsGreaterThanOrEqualTo(4, runs.Count);
|
|
foreach (Match run in runs)
|
|
{
|
|
StringAssert.Contains(run.Value, "--network none", "rule 1: the image under test cannot reach any site");
|
|
StringAssert.Contains(run.Value, "\"${etichette[@]}\"", "every tried container carries the mark the cleanup looks for");
|
|
}
|
|
|
|
StringAssert.Contains(smoke, "etichette=(--label \"febe.ci.prova=$esecuzione\")");
|
|
StringAssert.Contains(smoke, "nome=\"febe-prova-$esecuzione\"");
|
|
|
|
// Docker copies the labels of an image into every container made from it: the mark must never be in an image.
|
|
Assert.DoesNotContain("febe.ci.prova", Code(Script("costruisci-immagine.sh")));
|
|
Assert.DoesNotContain("febe.ci.prova", Code(Read(Repository.PathOf("docker", "Dockerfile"))));
|
|
}
|
|
|
|
/// <summary>bash for the scripts of the CI: the system one on Linux, Git Bash on Windows (not the one of WSL).</summary>
|
|
private static string? BashForScripts()
|
|
{
|
|
if (OperatingSystem.IsWindows())
|
|
{
|
|
var git = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Git", "bin", "bash.exe");
|
|
return File.Exists(git) ? git : null;
|
|
}
|
|
|
|
return new[] { "/bin/bash", "/usr/bin/bash" }.FirstOrDefault(File.Exists);
|
|
}
|
|
|
|
/// <summary>The workflows and the scripts of the CI, by name.</summary>
|
|
private static List<(string Name, string Text)> AllCiFiles() =>
|
|
[.. Directory.EnumerateFiles(CiPath("workflows")).Concat(Directory.EnumerateFiles(CiPath("scripts")))
|
|
.Select(file => (Path.GetFileName(file), Read(file)))];
|
|
|
|
private static string Workflow(string name) => Read(CiPath("workflows", name));
|
|
|
|
private static string Script(string name) => Read(CiPath("scripts", name));
|
|
|
|
private static string Read(string path) => File.ReadAllText(path).Replace("\r\n", "\n", StringComparison.Ordinal);
|
|
|
|
/// <summary>A path under .gitea; inconclusive in the build of the image, whose context leaves .gitea out.</summary>
|
|
private static string CiPath(params string[] parts)
|
|
{
|
|
var path = Repository.PathOf([".gitea", .. parts]);
|
|
var root = Repository.Root()!;
|
|
if (!File.Exists(path) && !Directory.Exists(path) && !Directory.Exists(Path.Combine(root, ".git")) && !File.Exists(Path.Combine(root, ".git")))
|
|
{
|
|
Assert.Inconclusive("Questa copia del repository non ha .gitea/ (costruzione dell'immagine Docker).");
|
|
}
|
|
|
|
return path;
|
|
}
|
|
|
|
/// <summary>The text without comment lines (YAML and shell): what runs, not what the comments say.</summary>
|
|
private static string Code(string text) =>
|
|
string.Join('\n', text.Replace("\r\n", "\n", StringComparison.Ordinal).Split('\n').Where(line => !line.TrimStart().StartsWith('#')));
|
|
|
|
/// <summary>The block of a job: from « name:» to the next job.</summary>
|
|
private static string Job(string workflow, string name)
|
|
{
|
|
var match = Regex.Match(workflow, $@"^ {Regex.Escape(name)}:\n(?<body>(?:(?: .*|\s*)\n)*)", RegexOptions.Multiline);
|
|
Assert.IsTrue(match.Success, $"manca il lavoro {name}");
|
|
return match.Groups["body"].Value;
|
|
}
|
|
|
|
/// <summary>The block of a step, from its «- name:» to the next step.</summary>
|
|
private static string Step(string job, string name)
|
|
{
|
|
var start = job.IndexOf("- name: " + name, StringComparison.Ordinal);
|
|
Assert.IsGreaterThanOrEqualTo(0, start, $"manca il passo «{name}»");
|
|
var next = job.IndexOf("\n - ", start + 1, StringComparison.Ordinal);
|
|
return next < 0 ? job[start..] : job[start..next];
|
|
}
|
|
|
|
[GeneratedRegex(@"(?<=^jobs:\n(?:.*\n)*?)^ (?<name>[a-z][\w-]*):$", RegexOptions.Multiline)]
|
|
private static partial Regex JobHeader();
|
|
|
|
[GeneratedRegex(@"dotnet test(?:\s+(?<target>[^\s-][^\s]*))?")]
|
|
private static partial Regex DotnetTest();
|
|
|
|
[GeneratedRegex(@"(?m)^\s*set\s+-[a-wyz]*x|\bbash\s+-x\b")]
|
|
private static partial Regex Trace();
|
|
|
|
[GeneratedRegex(@"\b(?:echo|printf)\b")]
|
|
private static partial Regex Printing();
|
|
|
|
[GeneratedRegex(@"\$\{?(?:TOKEN|FEBE_PASSWORD|AUTH|REGISTRY_TOKEN|GITEA_TOKEN|INTESTAZIONE|GIT_CONFIG_VALUE_0|PASSWORD)\b")]
|
|
private static partial Regex SecretReference();
|
|
|
|
[GeneratedRegex(@"\b[0-9a-f]{64}\b")]
|
|
private static partial Regex Sha256();
|
|
|
|
[GeneratedRegex(@"docker run\b(?:[^\n]*\\\n)*[^\n]*")]
|
|
private static partial Regex DockerRun();
|
|
}
|