Public Access
Wire the Avalonia shell to the vault
The host list now comes from the vault instead of from a form. A fresh machine takes a server URL, signs in through the browser, enrolls, and from then on opens with the passphrase alone. DodoSSH.Client.Session is the composition layer: where a profile lives, how it unlocks, and how a machine gets one. ClientPaths picks a non-roaming per-OS directory — %LOCALAPPDATA% and never %APPDATA%, because a SQLite cache that roams between two machines is a corrupt one, and each machine's outbox is its own. SessionOpener needs no transport at all and could not reach one if it wanted to; that is the offline unlock, asserted rather than asserted about. A wrong passphrase, a stale KDF and a grant revoked by a rekey are three different answers, because the remedies are three different things and telling someone to retype a passphrase that was never the problem is worse than saying nothing. The shell's states are the onboarding story. The recovery code gets its own state that cannot be clicked past: it exists for one moment, losing it with the passphrase loses the vault, and there is no server-side reset by design. It is dropped from memory on confirmation rather than merely hidden. Sign-in is a delegate over IVaultServer, so the whole state machine runs in a test against an in-memory server — no browser, no identity provider, no toolkit. The view models are plain observable objects, which is what makes that possible. What it does not cover is whether the XAML binds to the right names; that needs a rendered tree and Avalonia.Headless, and is its own piece of work. Three things found by doing it rather than by reading it: - Pooled SQLite connections keep the database file open after the last context is disposed. On Windows that means locked, so the application could never replace its own cache — and a test could not clean up after itself, which is how it surfaced. Dispose now clears the pool. - EF's SQLite provider puts the database in WAL mode, so the cache is three files. A comment in ClientCacheFactory claimed the opposite; reading PRAGMA journal_mode off a real launch settled it. WAL is the right mode here — a sync pass writes while the interface reads — so the comment was wrong on the merits as well as on the fact. - Enrolling a device key with nowhere to keep the private half would put a wrap on the server nobody can open and make the device list claim this machine can unlock without a passphrase. Device binding is now optional and the shell declines it until the OS keystore is wired. Verified on Windows: the client created %LOCALAPPDATA%\DodoSSH\cache.db and migrated it on first launch, and msedgewebview2 held an established connection to the data plane while the unlock overlay covered it — which is the point of covering the WebView rather than collapsing it, since a NativeWebView that is never laid out is never realised. 630 tests, up from 593. The recovery-code gate and the offline unlock were each verified by breaking them and watching the right test fail. Still to do for M1's actual definition of done: the manual run against the real API and a real Keycloak. Credentials are not a synced entity type yet, so a connection still asks for a password, and the interface says so rather than implying otherwise.
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
using DodoSSH.Contracts;
|
||||
using DodoSSH.Crypto;
|
||||
|
||||
namespace DodoSSH.Client.Storage.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// The cache as it is actually deployed: a file on disk.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Every other suite here uses an in-memory database because it is faster and isolated. That leaves the
|
||||
/// production path — <see cref="ClientCacheFactory.ForFile"/>, a real migration against a file that does
|
||||
/// not exist yet, and data surviving the process that wrote it — untested, which is exactly the shape of
|
||||
/// bug that only appears on a user's first launch.
|
||||
/// </remarks>
|
||||
public sealed class FileBackedCacheTests : IDisposable
|
||||
{
|
||||
private readonly string directory =
|
||||
Path.Combine(Path.GetTempPath(), $"dodossh-cache-{Guid.CreateVersion7():N}");
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
if (Directory.Exists(directory))
|
||||
{
|
||||
Directory.Delete(directory, recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AMigrationCreatesTheFileAndTheDataOutlivesTheFactory()
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
var path = Path.Combine(directory, "cache.db");
|
||||
|
||||
var material = Material();
|
||||
|
||||
using (var first = ClientCacheFactory.ForFile(path))
|
||||
{
|
||||
await first.MigrateAsync(Token);
|
||||
|
||||
File.Exists(path).ShouldBeTrue("the migration should have created the database");
|
||||
|
||||
await new UnlockStore(first, TimeProvider.System).SaveAsync(material, Token);
|
||||
}
|
||||
|
||||
// A second factory over the same file, as a later launch of the application is.
|
||||
using var second = ClientCacheFactory.ForFile(path);
|
||||
|
||||
// Migrating again is what every launch does, and it has to be a no-op rather than an error.
|
||||
await second.MigrateAsync(Token);
|
||||
|
||||
var read = await new UnlockStore(second, TimeProvider.System).ReadAsync(Token);
|
||||
|
||||
read.ShouldNotBeNull();
|
||||
read.UserId.ShouldBe(material.UserId);
|
||||
read.WrappedPrivateKey.ShouldBe(material.WrappedPrivateKey);
|
||||
read.KdfParameters.Salt.ShouldBe(material.KdfParameters.Salt);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AMissingDirectory_FailsClearlyRatherThanSilently()
|
||||
{
|
||||
// The application creates the profile directory before opening the cache. If that order were ever
|
||||
// reversed, this is the error it would produce — worth pinning so the failure stays diagnosable
|
||||
// instead of turning into an empty vault.
|
||||
using var factory = ClientCacheFactory.ForFile(
|
||||
Path.Combine(directory, "missing", "cache.db"));
|
||||
|
||||
await Should.ThrowAsync<Microsoft.Data.Sqlite.SqliteException>(
|
||||
async () => await factory.MigrateAsync(Token));
|
||||
}
|
||||
|
||||
private static CancellationToken Token => TestContext.Current.CancellationToken;
|
||||
|
||||
private static StoredUnlockMaterial Material() =>
|
||||
new(
|
||||
"https://dodossh.example",
|
||||
Guid.CreateVersion7(),
|
||||
"https://idp.example",
|
||||
"alice",
|
||||
"alice@example.com",
|
||||
"Alice",
|
||||
KeyGeneration: 1,
|
||||
WrappedPrivateKey: [1, 2, 3, 4],
|
||||
new KdfParameters("argon2id", [5, 6, 7, 8], 262144, 4, 1),
|
||||
DateTimeOffset.FromUnixTimeSeconds(1_750_000_000));
|
||||
}
|
||||
Reference in New Issue
Block a user