Public Access
M2's file transfer, built bottom-up: an SFTP session on the SSH layer, a transfer queue in a project of its own, and the two-pane browser the design asked for replacing the screen that said it did not exist. Remote listings carry names, sizes, modification times and a real drwxr-xr-x — nothing in this repository could render a POSIX mode before — and the queue moves one file at a time with progress, throughput and resume. The design import assumed this would be an SFTP subsystem channel on ISshConnection, beside the shell on a transport that is already up. SSH.NET does not offer that: SftpClient derives from BaseClient and owns its own transport, and there is no supported way to hand it an SshClient's session. So file transfer opens a second authenticated connection, and it is named for that rather than dressed up as a channel — OpenSftpAsync is on ISftpSessionFactory, not on a connection. The difference is visible to a user: the host records a second login, and a host whose password is typed each time asks for it again on this screen. It goes through the same host key gate, the same pin and the same two refusals a shell does, so a fingerprint approved for a terminal is approved here and one approved here reaches the other machines with the next sync. docs/design-import-gaps.md is corrected, and marked as the one row where what shipped differs from what it predicted. Nothing is written at its final name until it is complete. Every transfer goes to a .dodossh-part file beside its destination and is renamed into place at the end, so an interrupted transfer can never be mistaken for a finished one — which matters most for what this screen is actually for, which is copying a build artefact onto a server and then running it. A destination that already exists is refused outright rather than overwritten: the queue has no way to ask, and silently replacing a file somebody's process is serving is the worse of the two failures. The remote pane has DELETE and MKDIR so that refusal is not a dead end. A test against the container pins the assumption underneath all of this — that SFTP's rename does not clobber. Resume works within a run of the application and not across a restart, and the limit is deliberate rather than unfinished. Nothing records which source wrote a part file, and resuming one on the strength of its name matching is how a corrupt artefact gets delivered with nothing reporting a failure; a part file found at startup is started over. Making it survive a restart needs the preferences store this client still has not got. The offset a resume starts at is the part file's own length rather than the transfer's recorded progress: a cancellation can land between a write completing and the counter moving, and only one of those two is a fact about the bytes that are there. The queue and its connection outlive a lock, as shells do. LockAsync already argues that locking must not destroy work in flight — it is what somebody does when they walk away from the machine, which is exactly when a long transfer is most likely to be running — so TransfersViewModel is created once and the vault is attached on unlock and detached on lock. What locking takes is the host list, and it has to: those rows carry decrypted secrets. DodoSSH.Client.Transfer is a new project rather than more of Client.Ssh. The two answer different questions — one is about reaching a host, the other about moving bytes and what to do when moving them stops halfway — and this is the only client project that deliberately touches the local filesystem. Three defects the tests found, none of which review would have. SftpPath.Name answered an empty string for the root. NavigateRemoteAsync wrapped itself in the busy guard, so navigating from inside another command did nothing at all and the remote pane simply stayed empty after connecting, with no failure anywhere to explain it. And opening an SFTP session per test made two handshakes per test — this client learns a host key by being refused — which pushed the SSH assembly past sshd's MaxStartups and failed a different few unrelated tests each run; the session is shared through the fixture now, with the reason written where the next person will hit it. 1004 tests green across 18 projects, 24 of them new: the SFTP subsystem against the OpenSSH container, the queue against a real temporary directory and a fake host, and three more layout measurements because a screen this window has never laid out is a screen never checked. Not verified: the screen has not been looked at running. The layout harness measures it at the window's minimum in three shapes, which is the class of defect that has shipped here before, but reaching it in the application needs the compose stack, the migrations, the API and a browser sign-in. What is still absent — the status bar's transfer count, dragging between the panes, transferring a directory, and sftp over a bastion — is in docs/design-import-gaps.md.
597 lines
24 KiB
C#
597 lines
24 KiB
C#
using Avalonia.Controls;
|
|
using Avalonia.VisualTree;
|
|
using DodoSSH.Client.App.ViewModels;
|
|
using DodoSSH.Client.App.Views;
|
|
using DodoSSH.Client.Session;
|
|
using DodoSSH.Client.Session.Tests;
|
|
using DodoSSH.Client.Ssh;
|
|
using DodoSSH.Client.Storage;
|
|
using DodoSSH.Client.Terminal;
|
|
using DodoSSH.Client.Transfer;
|
|
using DodoSSH.Crypto;
|
|
using NSubstitute;
|
|
|
|
namespace DodoSSH.Client.App.Layout.Tests;
|
|
|
|
/// <summary>
|
|
/// Whether each screen fits in the space the window gives it.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This suite used to measure one control, <c>VaultColumn</c>, because there was one. The design import
|
|
/// split it in two — the host list lives beside the terminal, and everything else in the vault has a screen
|
|
/// of its own — and added a titlebar, a nav rail and a status bar. That is five things to measure, and the
|
|
/// split is what keeps every one of them measurable: none contains the terminal's WebView, and
|
|
/// <c>MainWindow</c> still cannot be laid out here at all, because WebView2's adapter refuses the headless
|
|
/// dispatcher's MTA thread. <see cref="LayoutHarnessTests"/> pins that.
|
|
/// </para>
|
|
/// <para>
|
|
/// One test per shape a user can put a screen into, because a shape that is never laid out is a shape never
|
|
/// checked. The host sidebar has three — list, list with the editor open, and list folded away — and the
|
|
/// vault screen has one per category plus one per editor.
|
|
/// </para>
|
|
/// <para>
|
|
/// A real <c>VaultViewModel</c> over a real unlocked vault, rather than a stand-in. Compiled bindings
|
|
/// resolve against the declared data type, so a stand-in would have to be the same type anyway — and the
|
|
/// editors' height depends on real content: a key with a real armour block in the box is taller than an
|
|
/// empty one.
|
|
/// </para>
|
|
/// </remarks>
|
|
public sealed class ScreenLayoutTests : IAsyncLifetime
|
|
{
|
|
private const string Passphrase = "a sufficiently long passphrase";
|
|
private const string ServerUrl = "https://dodossh.example";
|
|
|
|
/// <remarks>Far below the shipped profile: nothing here attacks a wrap.</remarks>
|
|
private static readonly Argon2Profile CheapProfile =
|
|
Argon2Profile.FromStoredParameters(memoryKibibytes: 8 * 1024, passes: 1, parallelism: 1);
|
|
|
|
private readonly FakeAccountServer server = new();
|
|
private readonly StubKeyBinding keyBinding = new();
|
|
private readonly VaultKnownHostStore knownHosts = new();
|
|
|
|
private ClientCacheFactory caches = null!;
|
|
private TerminalWorkspace workspace = null!;
|
|
private VaultSession session = null!;
|
|
private VaultViewModel vault = null!;
|
|
|
|
/// <remarks>
|
|
/// Over a substitute factory that is never asked for a session. Every shape measured here is one the
|
|
/// screen is in before a connection exists or after one has failed, which is deliberate: the two panes
|
|
/// are at their widest with the local one full and the remote one carrying its explanation, and a
|
|
/// connected pane is the same template with shorter names in it.
|
|
/// </remarks>
|
|
private TransfersViewModel transfers = null!;
|
|
|
|
private static CancellationToken Token => TestContext.Current.CancellationToken;
|
|
|
|
/// <inheritdoc />
|
|
public async ValueTask InitializeAsync()
|
|
{
|
|
caches = ClientCacheFactory.ForMemory($"layout-{Guid.CreateVersion7():N}");
|
|
await caches.MigrateAsync(Token);
|
|
|
|
await new AccountProvisioner(server, keyBinding, caches, TimeProvider.System, CheapProfile)
|
|
.EnrollAsync(ServerUrl, Passphrase, "laptop", "Personal", Token);
|
|
|
|
var outcome = await new SessionOpener(caches, TimeProvider.System).UnlockAsync(Passphrase, Token);
|
|
outcome.IsUnlocked.ShouldBeTrue(outcome.Message);
|
|
session = outcome.Session!;
|
|
|
|
// Never started and never connected through: no screen's layout depends on the terminal, and the
|
|
// substitute is here only because the view model's constructor asks for one.
|
|
workspace = new TerminalWorkspace(
|
|
new InMemoryTerminalAssetProvider(new Dictionary<string, TerminalAsset>(StringComparer.Ordinal)),
|
|
Substitute.For<ISshConnectionFactory>(),
|
|
TimeProvider.System);
|
|
|
|
await knownHosts.OpenAsync(session, Token);
|
|
|
|
// Offline. A null connection is what these screens show on a laptop with no network, and it keeps
|
|
// every sync pass out of a suite that is only measuring rectangles.
|
|
vault = new VaultViewModel(session, workspace, knownHosts, static () => null);
|
|
|
|
transfers = new TransfersViewModel(
|
|
Substitute.For<ISftpSessionFactory>(), TimeProvider.System);
|
|
|
|
await SeedAsync();
|
|
|
|
// Attached after seeding, so the host picker has something in it and the local pane has listed this
|
|
// machine's home directory — which is what puts real names of real length into the row template.
|
|
transfers.Attach(vault, knownHosts);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async ValueTask DisposeAsync()
|
|
{
|
|
await transfers.DisposeAsync();
|
|
await vault.DisposeAsync();
|
|
knownHosts.Close();
|
|
await workspace.DisposeAsync();
|
|
await session.DisposeAsync();
|
|
caches.Dispose();
|
|
}
|
|
|
|
// ---- The host sidebar ----
|
|
|
|
[Fact]
|
|
public async Task TheHostSidebarFitsWithNoEditorOpen()
|
|
{
|
|
await MeasureSidebarAsync(faults => faults.ShouldBeEmpty());
|
|
}
|
|
|
|
/// <remarks>
|
|
/// The tight one, and the reason this suite still exists. The sidebar is 268 pixels wide against the old
|
|
/// column's 340, and the host editor is the tallest thing in it: six fields, an authentication picker
|
|
/// with a two-line item template, a checkbox, a paragraph of hint text and three buttons, all sharing a
|
|
/// column with the list above them.
|
|
/// </remarks>
|
|
[Fact]
|
|
public async Task TheHostSidebarFitsWithItsEditorOpen()
|
|
{
|
|
vault.SelectedHost = vault.Hosts[0];
|
|
vault.EditSelectedHostCommand.Execute(null);
|
|
|
|
vault.EditorAuthenticationChoices.Count
|
|
.ShouldBeGreaterThan(1, "the picker has to be populated for this to measure anything");
|
|
|
|
// Measured with a credential selected, because an empty picker is shorter than one showing a
|
|
// qualifier beside a label.
|
|
vault.EditorSelectedAuthentication = vault.EditorAuthenticationChoices
|
|
.First(choice => choice.Kind is AuthenticationKind.Credential);
|
|
|
|
await MeasureSidebarAsync(faults => faults.ShouldBeEmpty());
|
|
}
|
|
|
|
/// <remarks>
|
|
/// Folding the list away is the one thing a user can do to this control that changes which of its parts
|
|
/// is on screen, so it is a shape worth laying out on its own.
|
|
/// </remarks>
|
|
[Fact]
|
|
public async Task TheHostSidebarFitsWithItsListFoldedAway()
|
|
{
|
|
vault.ToggleHostsCommand.Execute(null);
|
|
vault.AreHostsExpanded.ShouldBeFalse();
|
|
|
|
await MeasureSidebarAsync(faults => faults.ShouldBeEmpty());
|
|
}
|
|
|
|
/// <remarks>
|
|
/// <para>
|
|
/// The one thing a wrong answer here breaks is unrecoverable from the keyboard: <c>MainWindow</c> takes
|
|
/// the keyboard off the terminal's native child window first and then focuses this target, so a target
|
|
/// that cannot take focus leaves the user with no focused element and no way back except the mouse.
|
|
/// </para>
|
|
/// <para>
|
|
/// Which is why this asserts that focus was <i>taken</i> rather than that the right control was named.
|
|
/// A <c>ListBox</c> is not focusable by default, so the call returns false against a list that has not
|
|
/// asked to be — and <c>Focus()</c> on a collapsed control is a no-op that is not replayed when it is
|
|
/// revealed, which is exactly what the folded-away case would hit.
|
|
/// </para>
|
|
/// </remarks>
|
|
[Fact]
|
|
public async Task TheSidebarsKeyboardTargetTakesFocusInBothOfItsShapes()
|
|
{
|
|
await OnTheSidebarAsync((sidebar, _) =>
|
|
{
|
|
sidebar.KeyboardTarget.ShouldBeSameAs(sidebar.HostList);
|
|
sidebar.KeyboardTarget.Focus().ShouldBeTrue("the list is showing");
|
|
});
|
|
|
|
vault.ToggleHostsCommand.Execute(null);
|
|
|
|
await OnTheSidebarAsync((sidebar, _) =>
|
|
{
|
|
sidebar.KeyboardTarget.ShouldBeSameAs(sidebar.HostFilter);
|
|
sidebar.KeyboardTarget.Focus().ShouldBeTrue("the list is folded away, so the filter takes it");
|
|
});
|
|
}
|
|
|
|
/// <remarks>
|
|
/// The editor open with the list still on screen behind it, which is the state a user is most likely to
|
|
/// leave the sidebar in — so it is the state the keyboard answer most has to hold in.
|
|
/// </remarks>
|
|
[Fact]
|
|
public async Task TheSidebarsKeyboardTargetStillTakesFocusWithTheEditorOpen()
|
|
{
|
|
vault.NewHostCommand.Execute(null);
|
|
|
|
await OnTheSidebarAsync((sidebar, _) =>
|
|
{
|
|
sidebar.HostList.IsEffectivelyVisible.ShouldBeTrue();
|
|
sidebar.KeyboardTarget.Focus().ShouldBeTrue();
|
|
});
|
|
}
|
|
|
|
// ---- The vault screen ----
|
|
|
|
[Fact]
|
|
public async Task TheVaultScreenFitsInEveryCategory()
|
|
{
|
|
foreach (var section in new[]
|
|
{
|
|
VaultSection.All, VaultSection.Keys, VaultSection.Credentials, VaultSection.KnownHosts,
|
|
})
|
|
{
|
|
vault.Section = section;
|
|
|
|
await MeasureVaultAsync(faults => faults.ShouldBeEmpty($"the {section} category"));
|
|
}
|
|
}
|
|
|
|
/// <remarks>
|
|
/// The tall one: a private key needs a real text area, and the vault screen's detail pane is 244 pixels
|
|
/// wide — the narrowest column any form in this application has to fit into.
|
|
/// </remarks>
|
|
[Fact]
|
|
public async Task TheVaultScreenFitsWithTheKeyEditorOpen()
|
|
{
|
|
vault.NewKeyCommand.Execute(null);
|
|
vault.IsEditingKey.ShouldBeTrue();
|
|
vault.ShowsKeys.ShouldBeTrue("opening an editor has to bring its own category into view");
|
|
|
|
vault.KeyEditorPrivateKey = string.Join(
|
|
'\n',
|
|
Enumerable.Repeat("b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gt", 6));
|
|
|
|
await MeasureVaultAsync(faults => faults.ShouldBeEmpty());
|
|
}
|
|
|
|
[Fact]
|
|
public async Task TheVaultScreenFitsWithThePasswordEditorOpen()
|
|
{
|
|
vault.NewCredentialCommand.Execute(null);
|
|
vault.IsEditingCredential.ShouldBeTrue();
|
|
vault.ShowsCredentials.ShouldBeTrue("opening an editor has to bring its own category into view");
|
|
|
|
await MeasureVaultAsync(faults => faults.ShouldBeEmpty());
|
|
}
|
|
|
|
/// <remarks>
|
|
/// The detail pane with something selected, which is what the design's right-hand column is really about
|
|
/// — and the pin is the one carrying a full fingerprint on a wrapped monospace line.
|
|
/// </remarks>
|
|
[Fact]
|
|
public async Task TheVaultScreenFitsWithAPinSelected()
|
|
{
|
|
vault.Section = VaultSection.KnownHosts;
|
|
vault.VaultItems.ShouldNotBeEmpty("an empty list is the easy case and proves nothing here");
|
|
|
|
vault.SelectedVaultItem = vault.VaultItems[0];
|
|
vault.SelectedItemIsPin.ShouldBeTrue();
|
|
|
|
await MeasureVaultAsync(faults => faults.ShouldBeEmpty());
|
|
}
|
|
|
|
/// <remarks>
|
|
/// The rail is the only way to reach a category, so a button that lands on nothing walls off three
|
|
/// quarters of the screen. The fit tests above prove the buttons are inside the window; this proves they
|
|
/// are the size a pointer can find, which a zero-height row in a collapsed border would not be.
|
|
/// </remarks>
|
|
[Fact]
|
|
public async Task TheCategoryRailIsBigEnoughToClick()
|
|
{
|
|
await OnTheVaultAsync((screen, _) =>
|
|
{
|
|
var buttons = screen.GetVisualDescendants()
|
|
.OfType<Button>()
|
|
.Where(button => button.Classes.Contains("cat"))
|
|
.ToList();
|
|
|
|
buttons.Count.ShouldBe(4, "one per category that exists");
|
|
|
|
foreach (var button in buttons)
|
|
{
|
|
button.Bounds.Height.ShouldBeGreaterThan(20);
|
|
button.Bounds.Width.ShouldBeGreaterThan(120);
|
|
}
|
|
});
|
|
}
|
|
|
|
// ---- The transfers screen ----
|
|
|
|
/// <remarks>
|
|
/// <para>
|
|
/// The widest thing in this window and the one with the least room to give: two file listings side by
|
|
/// side, each with four columns, and a queue underneath — all inside 826 pixels once the nav rail has
|
|
/// taken its column. The header row is the tight part, because it holds a host picker, a password box,
|
|
/// a button and a chip on one line.
|
|
/// </para>
|
|
/// <para>
|
|
/// Measured disconnected, which is the state the screen opens in and the one where the local pane is at
|
|
/// its fullest: it lists this machine's home directory, so the row template is exercised with real names
|
|
/// of real length rather than with fixtures chosen to fit.
|
|
/// </para>
|
|
/// </remarks>
|
|
[Fact]
|
|
public async Task TheTransfersScreenFitsBeforeAnythingIsConnected()
|
|
{
|
|
await MeasureTransfersAsync(faults => faults.ShouldBeEmpty());
|
|
}
|
|
|
|
/// <remarks>
|
|
/// <para>
|
|
/// The queue is the half of this screen that only exists once something has been asked for, so a shape
|
|
/// nothing puts a row into is a shape never laid out. Three rows, because the row template changes with
|
|
/// the state: a running one shows a bar and a STOP, a stopped one shows RESUME and DISCARD, and a failed
|
|
/// one carries the server's own sentence in the column the other two put a byte count in.
|
|
/// </para>
|
|
/// <para>
|
|
/// The rows are placed directly rather than driven through the queue. What is being measured is the
|
|
/// template at each state, and running a real transfer to reach those states would put a thread-pool
|
|
/// hand-off and a filesystem in the middle of a test about rectangles. What the queue does is measured in
|
|
/// <c>DodoSSH.Client.Transfer.Tests</c>.
|
|
/// </para>
|
|
/// </remarks>
|
|
[Fact]
|
|
public async Task TheTransfersScreenFitsWithTransfersInTheQueue()
|
|
{
|
|
Enqueue(TransferDirection.Download, "artefact.tar.gz", 402_653_184, 149_000_000,
|
|
TransferState.Running, bytesPerSecond: 6_500_000);
|
|
|
|
Enqueue(TransferDirection.Upload, "site-backup-2026-07-30.sql.gz", 8_100_000_000, 3_200_000_000,
|
|
TransferState.Cancelled);
|
|
|
|
Enqueue(TransferDirection.Upload, "deploy.sh", 4_096, 0, TransferState.Failed,
|
|
failure: "deploy.sh is already in that directory on the host. Rename or remove it first — "
|
|
+ "nothing here overwrites a file that is already there.");
|
|
|
|
transfers.Transfers.Count.ShouldBe(3);
|
|
|
|
await MeasureTransfersAsync(faults => faults.ShouldBeEmpty());
|
|
}
|
|
|
|
/// <remarks>
|
|
/// The trust card covers the whole screen, and it is the one thing here a user cannot get past without
|
|
/// pressing something — so a button of its own that fell outside the window would leave the screen
|
|
/// permanently blocked.
|
|
/// </remarks>
|
|
[Fact]
|
|
public async Task TheTransfersScreenFitsWithTheHostKeyCardShowing()
|
|
{
|
|
transfers.PendingHostKey = new HostKeyPresentation(
|
|
"db.internal", 22, "ssh-ed25519", "SHA256:0123456789abcdefghijklmnopqrstuvwxyzABCDEFG");
|
|
|
|
await MeasureTransfersAsync(faults => faults.ShouldBeEmpty());
|
|
}
|
|
|
|
// ---- The chrome ----
|
|
|
|
/// <remarks>
|
|
/// <para>
|
|
/// The two constants the whole height budget is subtracted from, held against the markup that declares
|
|
/// them. If either bar grows, every screen gets less room than this suite thinks it does and every
|
|
/// measurement above quietly becomes optimistic.
|
|
/// </para>
|
|
/// <para>
|
|
/// Laid out with no data context, which is the point: these are fixed-height strips and their geometry
|
|
/// must not depend on what is bound into them. A binding that made one of them grow with its contents
|
|
/// would fail here.
|
|
/// </para>
|
|
/// </remarks>
|
|
[Fact]
|
|
public async Task TheChromeIsTheHeightTheBudgetAssumes()
|
|
{
|
|
await LayoutHarness.OnTheUiThreadAsync(
|
|
() =>
|
|
{
|
|
var titleBar = new TitleBar();
|
|
var titleWindow = LayoutHarness.HostAtMinimumSize(
|
|
titleBar, LayoutHarness.MinimumWidth, LayoutHarness.TitleBarHeight);
|
|
|
|
try
|
|
{
|
|
titleBar.Bounds.Height.ShouldBe(LayoutHarness.TitleBarHeight);
|
|
LayoutHarness.Unreachable(titleWindow).ShouldBeEmpty();
|
|
}
|
|
finally
|
|
{
|
|
titleWindow.Close();
|
|
}
|
|
|
|
var statusBar = new StatusBar();
|
|
var statusWindow = LayoutHarness.HostAtMinimumSize(
|
|
statusBar, LayoutHarness.MinimumWidth, LayoutHarness.StatusBarHeight);
|
|
|
|
try
|
|
{
|
|
statusBar.Bounds.Height.ShouldBe(LayoutHarness.StatusBarHeight);
|
|
}
|
|
finally
|
|
{
|
|
statusWindow.Close();
|
|
}
|
|
},
|
|
Token);
|
|
}
|
|
|
|
/// <remarks>
|
|
/// Five destinations in a 54-pixel column. The rail runs vertically, so what runs out here is height
|
|
/// rather than width — at the window's minimum the five entries have to leave room for each other, which
|
|
/// is the same failure the old four-button selector was one label away from.
|
|
/// </remarks>
|
|
[Fact]
|
|
public async Task TheNavRailHoldsFiveDestinationsAtTheWindowsMinimum()
|
|
{
|
|
await LayoutHarness.OnTheUiThreadAsync(
|
|
() =>
|
|
{
|
|
var rail = new NavRail();
|
|
var window = LayoutHarness.HostAtMinimumSize(
|
|
rail, LayoutHarness.NavRailWidth, LayoutHarness.ScreenHeight);
|
|
|
|
try
|
|
{
|
|
var buttons = rail.GetVisualDescendants().OfType<Button>().ToList();
|
|
|
|
buttons.Count.ShouldBe(5, "one per screen the rail reaches");
|
|
|
|
foreach (var button in buttons)
|
|
{
|
|
button.Bounds.Height.ShouldBeGreaterThan(20);
|
|
|
|
// One pixel narrower than the rail, because the rail draws its own divider down its
|
|
// right edge and that comes out of the content. Stated exactly rather than as a
|
|
// lower bound: a button that stopped filling the rail would leave a dead strip
|
|
// beside every destination, which is precisely the kind of near-miss a bound hides.
|
|
button.Bounds.Width.ShouldBe(LayoutHarness.NavRailWidth - 1);
|
|
}
|
|
|
|
LayoutHarness.Unreachable(window).ShouldBeEmpty();
|
|
}
|
|
finally
|
|
{
|
|
window.Close();
|
|
}
|
|
},
|
|
Token);
|
|
}
|
|
|
|
// ---- Helpers ----
|
|
|
|
/// <summary>Lays the sidebar out at the width the hosts screen gives it.</summary>
|
|
private Task MeasureSidebarAsync(Action<IReadOnlyList<string>> assert) =>
|
|
OnTheSidebarAsync((_, window) => assert(LayoutHarness.Unreachable(window)));
|
|
|
|
private Task OnTheSidebarAsync(Action<HostSidebar, Window> body) =>
|
|
LayoutHarness.OnTheUiThreadAsync(
|
|
() =>
|
|
{
|
|
var sidebar = new HostSidebar { DataContext = vault };
|
|
|
|
var window = LayoutHarness.HostAtMinimumSize(
|
|
sidebar, LayoutHarness.HostSidebarWidth, LayoutHarness.ScreenHeight);
|
|
|
|
try
|
|
{
|
|
body(sidebar, window);
|
|
}
|
|
finally
|
|
{
|
|
window.Close();
|
|
}
|
|
},
|
|
Token);
|
|
|
|
/// <summary>Lays the transfers screen out at the width it gets beside the nav rail.</summary>
|
|
private Task MeasureTransfersAsync(Action<IReadOnlyList<string>> assert) =>
|
|
LayoutHarness.OnTheUiThreadAsync(
|
|
() =>
|
|
{
|
|
var screen = new TransfersScreen { DataContext = transfers };
|
|
|
|
var window = LayoutHarness.HostAtMinimumSize(
|
|
screen, LayoutHarness.ScreenWidth, LayoutHarness.ScreenHeight);
|
|
|
|
try
|
|
{
|
|
assert(LayoutHarness.Unreachable(window));
|
|
}
|
|
finally
|
|
{
|
|
window.Close();
|
|
}
|
|
},
|
|
Token);
|
|
|
|
/// <summary>Puts one transfer on the queue in a given state, without moving a byte.</summary>
|
|
private void Enqueue(
|
|
TransferDirection direction,
|
|
string name,
|
|
long length,
|
|
long transferred,
|
|
TransferState state,
|
|
double bytesPerSecond = 0,
|
|
string? failure = null) =>
|
|
transfers.Transfers.Add(new TransferRowViewModel(new TransferSnapshot(
|
|
Guid.CreateVersion7(),
|
|
direction,
|
|
name,
|
|
Path.Combine(Path.GetTempPath(), name),
|
|
SftpPath.Combine("/srv/releases", name),
|
|
length,
|
|
transferred,
|
|
state,
|
|
bytesPerSecond,
|
|
failure)));
|
|
|
|
/// <summary>Lays the vault screen out at the width it gets once the nav rail has taken its column.</summary>
|
|
private Task MeasureVaultAsync(Action<IReadOnlyList<string>> assert) =>
|
|
OnTheVaultAsync((_, window) => assert(LayoutHarness.Unreachable(window)));
|
|
|
|
private Task OnTheVaultAsync(Action<VaultScreen, Window> body) =>
|
|
LayoutHarness.OnTheUiThreadAsync(
|
|
() =>
|
|
{
|
|
var screen = new VaultScreen { DataContext = vault };
|
|
|
|
var window = LayoutHarness.HostAtMinimumSize(
|
|
screen, LayoutHarness.ScreenWidth, LayoutHarness.ScreenHeight);
|
|
|
|
try
|
|
{
|
|
body(screen, window);
|
|
}
|
|
finally
|
|
{
|
|
window.Close();
|
|
}
|
|
},
|
|
Token);
|
|
|
|
/// <remarks>
|
|
/// Enough rows in every list that none is empty, because an empty list is the easiest case and the one
|
|
/// least worth certifying.
|
|
/// </remarks>
|
|
private async Task SeedAsync()
|
|
{
|
|
for (var i = 0; i < 6; i++)
|
|
{
|
|
vault.NewHostCommand.Execute(null);
|
|
vault.EditorLabel = $"host-{i}";
|
|
vault.EditorHostname = $"host-{i}.internal";
|
|
vault.EditorUsername = "deploy";
|
|
await vault.SaveHostCommand.ExecuteAsync(null);
|
|
}
|
|
|
|
for (var i = 0; i < 4; i++)
|
|
{
|
|
vault.NewKeyCommand.Execute(null);
|
|
vault.KeyEditorLabel = $"key-{i}";
|
|
vault.KeyEditorPrivateKey =
|
|
$"-----BEGIN OPENSSH PRIVATE KEY-----\nMATERIAL-{i}\n-----END OPENSSH PRIVATE KEY-----\n";
|
|
await vault.SaveKeyCommand.ExecuteAsync(null);
|
|
}
|
|
|
|
for (var i = 0; i < 3; i++)
|
|
{
|
|
vault.NewCredentialCommand.Execute(null);
|
|
vault.CredentialEditorLabel = $"credential-{i}";
|
|
vault.CredentialEditorPassword = $"password-{i}";
|
|
vault.CredentialEditorUsername = $"account-{i}";
|
|
await vault.SaveCredentialCommand.ExecuteAsync(null);
|
|
}
|
|
|
|
// Pins come from approving a fingerprint at connect time, not from an editor, so they are seeded
|
|
// through the store the connect path writes to. Two for one endpoint, because a host offering keys
|
|
// of two algorithms is ordinary and the duplicate is one of the things this list has to show.
|
|
foreach (var (host, algorithm) in new[]
|
|
{
|
|
("host-0.internal", "ssh-ed25519"),
|
|
("host-0.internal", "ecdsa-sha2-nistp256"),
|
|
("gone.internal", "ssh-ed25519"),
|
|
})
|
|
{
|
|
await knownHosts.TrustAsync(
|
|
new HostKeyPresentation(
|
|
host, 22, algorithm, $"SHA256:{algorithm}-fingerprint-0123456789abcdefghijklmnop"),
|
|
Token);
|
|
}
|
|
|
|
// Back to where the vault screen opens, so every test starts from the state a user would see.
|
|
vault.Section = VaultSection.All;
|
|
|
|
await vault.LoadAsync(Token);
|
|
}
|
|
}
|