Piattaforme: istanza unica dopo lo spostamento dei dati, avvio sicuro del contenitore, rilascio con prove e immagine, accesso senza reindirizzamenti esterni (pkg-1, pkg-2, pkg-3, pkg-4, pkg-5, pkg-6, websec-2, web-8, websec-3)
Registro di casa 192.168.30.23:3000 (HTTP) nel modello Unraid, in compose e nel rilascio con buildx; profilo seccomp fuori da /dati. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
This commit is contained in:
36 files changed
+1683
-152
No files matched your search
@@ -295,6 +295,170 @@ public sealed class DesktopLogicTests
|
||||
Assert.IsNull(store.Pending);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AfterAMoveThisFebeHoldsTheNewFolderSoASecondLaunchDoesNotStartASecondFebe()
|
||||
{
|
||||
// pkg-1: the guard is named after the Data folder. After a move every launch reads the new folder: this Febe
|
||||
// must hold its guard, or the next launch would start a second interface, browser and engine on it.
|
||||
using var temp = new TempFolder("desktop-sposta");
|
||||
var from = temp.Combine("vecchia");
|
||||
var to = temp.Combine("nuova");
|
||||
Directory.CreateDirectory(from);
|
||||
File.WriteAllText(Path.Combine(from, "febe.sqlite"), "database");
|
||||
var guards = new FakeInstanceGuards();
|
||||
var store = new MemoryLocationStore { Pending = to };
|
||||
using var started = guards.TryAcquire(from);
|
||||
Assert.IsNotNull(started, "Program: the guard of the folder this Febe started on");
|
||||
|
||||
(string? Recorded, bool Written)? atClaim = null;
|
||||
var result = DataFolderMove.ApplyPending(store, from, claimTarget: folder =>
|
||||
{
|
||||
atClaim = (store.Current, Directory.Exists(folder));
|
||||
return guards.TryAcquire(folder);
|
||||
});
|
||||
Assert.AreEqual(DataFolderMoveOutcome.Moved, result.Outcome, result.Message);
|
||||
Assert.AreEqual((null, false), atClaim, "the guard comes before the folder is recorded and before anything is written in it");
|
||||
Assert.IsNotNull(result.TargetGuard);
|
||||
Assert.AreEqual(Path.GetFullPath(to), store.Current);
|
||||
|
||||
// The next launch (Start menu, a start with the computer) reads the recorded folder and finds this Febe.
|
||||
Assert.IsNull(guards.TryAcquire(store.Current!), "a second launch signals this Febe instead of starting another");
|
||||
result.TargetGuard!.Dispose();
|
||||
using var afterExit = guards.TryAcquire(store.Current!);
|
||||
Assert.IsNotNull(afterExit, "after Esci the folder is free again");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AMoveIntoAFolderAnotherFebeHoldsDoesNotHappenAndAFailedMoveGivesTheGuardBack()
|
||||
{
|
||||
using var temp = new TempFolder("desktop-sposta");
|
||||
var from = temp.Combine("vecchia");
|
||||
Directory.CreateDirectory(from);
|
||||
File.WriteAllText(Path.Combine(from, "febe.sqlite"), "database");
|
||||
var guards = new FakeInstanceGuards();
|
||||
|
||||
// Another Febe (started with --dati) already holds the new folder: nothing is copied, the old folder stays.
|
||||
var taken = temp.Combine("presa");
|
||||
using (guards.TryAcquire(taken))
|
||||
{
|
||||
var store = new MemoryLocationStore { Pending = taken };
|
||||
var refused = DataFolderMove.ApplyPending(store, from, claimTarget: guards.TryAcquire);
|
||||
Assert.AreEqual(DataFolderMoveOutcome.Failed, refused.Outcome);
|
||||
StringAssert.Contains(refused.Message, "un altro Febe la sta già usando");
|
||||
Assert.IsNull(refused.TargetGuard);
|
||||
Assert.IsNull(store.Pending);
|
||||
Assert.IsNull(store.Current);
|
||||
Assert.IsFalse(Directory.Exists(taken), "nothing written there");
|
||||
Assert.IsTrue(File.Exists(Path.Combine(from, "febe.sqlite")));
|
||||
}
|
||||
|
||||
// A copy that fails: Febe stays on the old folder and does not keep the guard of the new one.
|
||||
var halfway = temp.Combine("a-meta");
|
||||
var failing = new MemoryLocationStore { Pending = halfway };
|
||||
var failed = DataFolderMove.ApplyPending(failing, from, new SyncProgress(_ => throw new IOException("disco pieno")), claimTarget: guards.TryAcquire);
|
||||
Assert.AreEqual(DataFolderMoveOutcome.Failed, failed.Outcome);
|
||||
Assert.IsNull(failed.TargetGuard);
|
||||
using var free = guards.TryAcquire(halfway);
|
||||
Assert.IsNotNull(free, "the guard of a move that did not happen is given back");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TheDataFolderLockLetsOneFebeOpenTheFolderWhateverItsSpelling()
|
||||
{
|
||||
using var temp = new TempFolder("desktop-blocco");
|
||||
var data = temp.Combine("dati");
|
||||
Assert.AreEqual(DataFolderLockOutcome.Acquired, DataFolderLock.TryAcquire(data, out var first, TimeSpan.Zero));
|
||||
Assert.IsNotNull(first);
|
||||
Assert.AreEqual(Path.Combine(data, DataFolderLock.FileName), first.Path);
|
||||
Assert.IsTrue(File.Exists(first.Path));
|
||||
|
||||
// The same folder under another name (on Windows: a short 8.3 name, subst, a junction; here a symbolic link):
|
||||
// the guards are named after the path and differ, the lock is the same file.
|
||||
var alias = temp.Combine("alias");
|
||||
Directory.CreateSymbolicLink(alias, data);
|
||||
Assert.AreNotEqual(InstanceIdentity.For(data), InstanceIdentity.For(alias));
|
||||
Assert.AreEqual(DataFolderLockOutcome.HeldByAnother, DataFolderLock.TryAcquire(alias, out var second, TimeSpan.Zero));
|
||||
Assert.IsNull(second);
|
||||
|
||||
// Held for a moment only (an antivirus looking at the file): the start waits instead of giving up.
|
||||
var release = Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(300, TestContext.CancellationToken);
|
||||
first.Dispose();
|
||||
}, TestContext.CancellationToken);
|
||||
Assert.AreEqual(DataFolderLockOutcome.Acquired, DataFolderLock.TryAcquire(alias, out var later, TimeSpan.FromSeconds(10)));
|
||||
release.Wait(TestContext.CancellationToken);
|
||||
later!.Dispose();
|
||||
|
||||
// A Data folder where nothing can be written: the start-up checks explain it, the lock does not decide.
|
||||
var file = temp.Combine("un-file");
|
||||
File.WriteAllText(file, "x");
|
||||
Assert.AreEqual(DataFolderLockOutcome.Unavailable, DataFolderLock.TryAcquire(file, out var none, TimeSpan.Zero));
|
||||
Assert.IsNull(none);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AFebeStartedWithItsOwnDataFolderHasItsOwnStartWithTheComputer()
|
||||
{
|
||||
// pkg-5: «Febe.exe --dati D:\FebeSecondo» (a second account) must start that folder at the next login, and its
|
||||
// switch must neither show nor remove the start of the usual Febe.
|
||||
var exe = Path.Combine(Path.GetTempPath(), "Programmi", "Febe", "Febe.exe");
|
||||
var second = Path.Combine(Path.GetTempPath(), "Febe Secondo");
|
||||
Assert.AreEqual("Febe", Autostart.ValueNameFor(null));
|
||||
Assert.AreEqual(InstanceIdentity.For(second), Autostart.ValueNameFor(second));
|
||||
StringAssert.StartsWith(Autostart.ValueNameFor(second), "Febe-");
|
||||
Assert.AreNotEqual(Autostart.ValueNameFor(second), Autostart.ValueNameFor(second + "2"));
|
||||
|
||||
var command = Autostart.Command(exe, second);
|
||||
Assert.AreEqual($"\"{exe}\" --nascosto --dati \"{second}\"", command);
|
||||
Assert.IsTrue(Autostart.PointsTo(command, exe, second));
|
||||
Assert.IsTrue(Autostart.PointsTo(command, exe, second + Path.DirectorySeparatorChar), "the same folder");
|
||||
Assert.IsFalse(Autostart.PointsTo(command, exe), "the usual Febe does not take it for its own");
|
||||
Assert.IsFalse(Autostart.PointsTo(Autostart.Command(exe), exe, second), "nor the reverse: that command starts the usual folder");
|
||||
Assert.IsFalse(Autostart.PointsTo(Autostart.Command(exe, second + "2"), exe, second), "another account");
|
||||
Assert.IsFalse(Autostart.PointsTo($"\"{exe}\" --nascosto --dati", exe, second));
|
||||
|
||||
// Febe.exe reads the command back as written: hidden, on that Data folder.
|
||||
var words = Autostart.Split(command)!;
|
||||
Assert.AreEqual(exe, words[0]);
|
||||
Assert.IsTrue(DesktopCommandLine.TryParse([.. words.Skip(1)], out var options, out var problem), problem);
|
||||
Assert.IsTrue(options.StartHidden);
|
||||
Assert.AreEqual(Path.GetFullPath(second), options.DataFolder);
|
||||
|
||||
// A folder at the root of a drive: the backslash before the closing quote is doubled, so it reads back whole.
|
||||
CollectionAssert.AreEqual(new[] { exe, "--nascosto", "--dati", @"D:\" }, Autostart.Split(Autostart.Command(exe, @"D:\")));
|
||||
CollectionAssert.AreEqual(new[] { "a", "b\"c", @"d\e" }, Autostart.Split("a \"b\\\"c\" d\\e"));
|
||||
Assert.ThrowsExactly<ArgumentException>(() => Autostart.Command(exe, "C:\\a\"b"));
|
||||
}
|
||||
|
||||
/// <summary>The single-instance guards of Windows (named mutexes), by Data folder, in memory.</summary>
|
||||
private sealed class FakeInstanceGuards
|
||||
{
|
||||
private readonly HashSet<string> _held = [];
|
||||
|
||||
public IDisposable? TryAcquire(string dataFolder)
|
||||
{
|
||||
var name = InstanceIdentity.MutexName(dataFolder);
|
||||
lock (_held)
|
||||
{
|
||||
return _held.Add(name) ? new Guard(this, name) : null;
|
||||
}
|
||||
}
|
||||
|
||||
private void Release(string name)
|
||||
{
|
||||
lock (_held)
|
||||
{
|
||||
_held.Remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class Guard(FakeInstanceGuards owner, string name) : IDisposable
|
||||
{
|
||||
public void Dispose() => owner.Release(name);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class SyncProgress(Action<DataFolderMoveProgress> report) : IProgress<DataFolderMoveProgress>
|
||||
{
|
||||
public void Report(DataFolderMoveProgress value) => report(value);
|
||||
|
||||
Reference in new issue
Block a user