Public Access
Build the three things the phone's + needs, before the + exists
Steps 1 to 3 of docs/adding-hosts-on-the-phone.md: the domain half. Nothing on either head has changed, which is deliberate — the plan orders these first because everything the editors will bind to has to exist and be merge-safe before a screen can offer it. HostGroupSecret gains a parent and four defaults, and the codec gains the version rule it never had. It stamped CurrentSchemaVersion unconditionally, which was harmless with one field and one version and stops being harmless here: upgrading one machine and renaming any group would have made that group uneditable on every machine still on the old build. It now emits the lowest version that loses nothing, so a flat group with no defaults still encodes at version 1, byte for byte, pinned against a literal. Tags become a real item over the reserved slot. Secret, codec, merge, cipher, repository, both registries, the EF entity and a generated AddTagItem migration. TagCipher names AadResourceType.Tag as a constant rather than casting the wire type, because Tag is 5 on the wire and 8 in the crypto enum and 5 there is Credential — a cast would seal every tag under the resource type for a password, encrypt and decrypt perfectly on the machine that wrote it, and only fail when another implementation refused the item, by which time the AAD is frozen into stored ciphertext. HostTag stays reserved and unused: the one thing the join buys over a set on the host is bought instead by merging TagIds per id. HostSecret grows TagIds and Port goes nullable, which is the change with the widest blast radius and the only one that loses an item rather than locking one. A host with no port of its own omits the property, an older build reads int Port as 0, and TryValidate refuses it — unreadable rather than read-only. That cost is confined to hosts which actually inherit, because the version is a maximum over the fields present; the alternative, writing 22 into every host, is the lie inheritance exists to stop telling. One decision the plan did not specify. "Three states where there were two" is four — key, credential, typed password, or the group's answer — and two nullable ids carry three. Naming neither id now means inherit, so AsksForPassword says "a typed password even under a group that lends a key" out loud. Only true is ever written and a decoded false folds back to null, so a host that never touched it encodes as it always did. Nothing already stored changed meaning: no group could lend a binding before this build, so every existing host resolves exactly as it did. HostInheritance is the resolver, and its visited set is load-bearing rather than defensive. Two clients can each re-parent A under B and B under A while offline; the merge sees one item against one item and the server sees ciphertext, so nothing upstream can refuse the pair. With inheritance the chain is walked at connect time, so an unguarded cycle is not an undrawable sidebar — it is a shell that never opens. Stopping at the first repeat degrades it to a group that reads as a root, and clearing the parent is the repair. A tag set turns out to be the one field on a host that can never ask the user anything. TagSet.ToIdMap keys by the value, so no key can hold two values, so the both-sides-moved-differently branch of the keyed merge is unreachable — asserted over the whole eight-row matrix. The conflict loop is kept anyway, because that proof is one edit from ceasing to hold and what it would cause is a discarded tag nothing records. Three guard tests failed by design and were fixed rather than relaxed: the ordered pull filter, the AAD pinning table, and the server's refusal of a plaintext parent — that last one survives with its reason rewritten, because the refusal now means "the parent is not the server's to hold" rather than "there is no such thing as a parent". The prose that said groups are flat is rewritten in all four places it appeared, not deleted. The five view-model sites that read Port directly now go through the resolver, which is a down payment on step 4 rather than the whole of it. HostFields.From still emits the stored port, and that is the one remaining place where an unresolved read would be a wrong wire rather than a wrong label. Verified by the whole suite: 1382 tests over nineteen projects, none failing. Both heads build. Nothing seen on a display, because nothing on a display has changed yet. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -16,9 +16,10 @@ public sealed class HostSecretCodecTests
|
||||
{
|
||||
/// <remarks>
|
||||
/// "Full" cannot mean every field: the two authentication bindings are mutually exclusive, so a host may
|
||||
/// carry a key or a credential and never both. This one carries the credential, because that is the newer
|
||||
/// of the two, plus a group — which is orthogonal to both and is what makes this host reach the highest
|
||||
/// schema version a valid host can.
|
||||
/// carry a key or a credential and never both, and neither may sit beside <c>AsksForPassword</c>. This
|
||||
/// one carries the credential, because that is the newer of the two, plus a group and a pair of tags —
|
||||
/// which are orthogonal to the binding and are what make this host reach the highest schema version a
|
||||
/// valid host can.
|
||||
/// </remarks>
|
||||
[Fact]
|
||||
public void AFullHost_RoundTrips()
|
||||
@@ -35,7 +36,8 @@ public sealed class HostSecretCodecTests
|
||||
options: [("ServerAliveInterval", "30"), ("Compression", "yes")],
|
||||
relayEnabled: true,
|
||||
credentialId: credentialId,
|
||||
groupId: Production);
|
||||
groupId: Production,
|
||||
tags: [Pci, EuWest]);
|
||||
|
||||
HostSecretCodec.TryDecode(HostSecretCodec.Encode(host), out var document).ShouldBeTrue();
|
||||
|
||||
@@ -146,6 +148,149 @@ public sealed class HostSecretCodecTests
|
||||
document.Host.ShouldBe(host);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AHostThatInheritsItsPort_IsWrittenAtTheVersionThatIntroducedInheritance()
|
||||
{
|
||||
HostSecretCodec.TryDecode(HostSecretCodec.Encode(Host(port: null)), out var document)
|
||||
.ShouldBeTrue();
|
||||
|
||||
document.ShouldNotBeNull();
|
||||
document.SchemaVersion.ShouldBe(
|
||||
HostSecretCodec.PortInheritSchemaVersion,
|
||||
"a host stamped at 4 with its port omitted is not read-only on an older build — it is "
|
||||
+ "undecodable there, because int Port reads 0 and TryValidate refuses it");
|
||||
|
||||
document.Host.Port.ShouldBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AHostPinnedToATypedPassword_IsWrittenAtTheSameVersionAsAnInheritedPort()
|
||||
{
|
||||
// Both halves of inheritance share a version because they arrive together and answer the same
|
||||
// question: what a host says when it declines to take its group's answer.
|
||||
HostSecretCodec
|
||||
.TryDecode(HostSecretCodec.Encode(Host(asksForPassword: true)), out var document)
|
||||
.ShouldBeTrue();
|
||||
|
||||
document.ShouldNotBeNull();
|
||||
document.SchemaVersion.ShouldBe(HostSecretCodec.PortInheritSchemaVersion);
|
||||
document.Host.AsksForPassword.ShouldBe(true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AHostWearingTags_IsWrittenAtTheVersionThatIntroducedThem()
|
||||
{
|
||||
HostSecretCodec.TryDecode(HostSecretCodec.Encode(Host(tags: [Pci])), out var document)
|
||||
.ShouldBeTrue();
|
||||
|
||||
document.ShouldNotBeNull();
|
||||
document.SchemaVersion.ShouldBe(HostSecretCodec.TagIdsSchemaVersion);
|
||||
document.Host.TagIds.ShouldBe(TagSet.Create([Pci]));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ATaggedHostThatPinsItsPort_IsNotDraggedOntoTheInheritanceVersionOrBelowIt()
|
||||
{
|
||||
// The maximum, from both directions. Tags are independent of inheritance, so a host that only wears
|
||||
// one must not be written at 5 — and a host that only inherits must not be written at 6, which would
|
||||
// make it undecodable on a build that could have read it.
|
||||
HostSecretCodec.TryDecode(HostSecretCodec.Encode(Host(tags: [Pci])), out var tagged)
|
||||
.ShouldBeTrue();
|
||||
|
||||
HostSecretCodec.TryDecode(HostSecretCodec.Encode(Host(port: null)), out var inheriting)
|
||||
.ShouldBeTrue();
|
||||
|
||||
tagged.ShouldNotBeNull().SchemaVersion
|
||||
.ShouldBeGreaterThan(HostSecretCodec.PortInheritSchemaVersion);
|
||||
|
||||
inheriting.ShouldNotBeNull().SchemaVersion
|
||||
.ShouldBeLessThan(HostSecretCodec.TagIdsSchemaVersion);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AHostWithAnEmptyTagSet_IsWrittenAtTheVersionItWouldHaveHadWithout()
|
||||
{
|
||||
// Wearing no tags is not using the feature. If an empty set bumped the version, adding tags would
|
||||
// have made every host in every vault read-only on every machine that had not upgraded.
|
||||
HostSecretCodec.TryDecode(HostSecretCodec.Encode(Host(tags: [])), out var document)
|
||||
.ShouldBeTrue();
|
||||
|
||||
document.ShouldNotBeNull();
|
||||
document.SchemaVersion.ShouldBe(HostSecretCodec.BaseSchemaVersion);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddingInheritanceAndTags_DidNotChangeTheBytesOfAHostUsingNeither()
|
||||
{
|
||||
// The companion to the pin below, and the one that matters most for these two fields: a set that
|
||||
// serialised as [] and a flag that serialised as false would both land in every host in every vault,
|
||||
// and the first sync after the upgrade would push all of them as changed.
|
||||
var bytes = HostSecretCodec.Encode(Host(username: null, notes: null, tags: []));
|
||||
|
||||
Encoding.UTF8.GetString(bytes).ShouldBe(
|
||||
"""
|
||||
{"schemaVersion":1,"label":"prod-db","hostname":"db.internal","port":22,"jumpHostIds":[],"options":{},"relayEnabled":false}
|
||||
""");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AHostThatInheritsItsPort_OmitsTheKeyRatherThanWritingANull()
|
||||
{
|
||||
// The companion pin the old one could not be edited into. What an inheriting host must produce is
|
||||
// the absence of "port", not "port":null and not "port":22 — the first would decode as 0 on any
|
||||
// build, and the second is what inheritance exists to stop writing.
|
||||
var bytes = HostSecretCodec.Encode(Host(username: null, notes: null, port: null));
|
||||
|
||||
Encoding.UTF8.GetString(bytes).ShouldBe(
|
||||
"""
|
||||
{"schemaVersion":5,"label":"prod-db","hostname":"db.internal","jumpHostIds":[],"options":{},"relayEnabled":false}
|
||||
""");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AHostWearingTags_WritesThemLastAndSorted()
|
||||
{
|
||||
// Last, so every field that existed before them keeps its bytes; sorted, so two users who tapped the
|
||||
// same two chips in opposite orders produce one value and nothing to push.
|
||||
var bytes = HostSecretCodec.Encode(
|
||||
Host(username: null, notes: null, tags: [EuWest, Pci]));
|
||||
|
||||
Encoding.UTF8.GetString(bytes).ShouldBe(
|
||||
"""
|
||||
{"schemaVersion":6,"label":"prod-db","hostname":"db.internal","port":22,"jumpHostIds":[],"options":{},"relayEnabled":false,"tagIds":["0192f0c8-8888-7c3d-8e4f-5a6b7c8d9e08","0192f0c8-9999-7c3d-8e4f-5a6b7c8d9e09"]}
|
||||
""");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void APayloadSayingItAsksForNoPassword_DecodesAsHavingSaidNothing()
|
||||
{
|
||||
// False and null mean the same thing — take the group's binding — so only one may reach the record.
|
||||
// Two spellings of one state is a difference the merge would report as a change nobody made.
|
||||
var payload = Encoding.UTF8.GetBytes(
|
||||
"""
|
||||
{"schemaVersion":5,"label":"prod-db","hostname":"db.internal","port":22,"asksForPassword":false}
|
||||
""");
|
||||
|
||||
HostSecretCodec.TryDecode(payload, out var document).ShouldBeTrue();
|
||||
|
||||
document.ShouldNotBeNull().Host.AsksForPassword.ShouldBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void APayloadRepeatingATag_DecodesAsTheSetItMeant()
|
||||
{
|
||||
// Written by some other client, and it must not compare unequal to the same set written once — or
|
||||
// the engine would push this host as changed on every pass for ever.
|
||||
var payload = Encoding.UTF8.GetBytes(
|
||||
$$"""
|
||||
{"schemaVersion":6,"label":"prod-db","hostname":"db.internal","port":22,"tagIds":["{{Pci}}","{{Pci}}"]}
|
||||
""");
|
||||
|
||||
HostSecretCodec.TryDecode(payload, out var document).ShouldBeTrue();
|
||||
|
||||
document.ShouldNotBeNull().Host.TagIds.ShouldBe(TagSet.Create([Pci]));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddingTheKeyField_DidNotChangeTheBytesOfAHostWithoutOne()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user