Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions pkgs/id/src/boards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,16 @@ impl BoardGraph {
value.version == 1,
"the first listing for a host starts at version 1"
);
let duplicate_first = self.objects.values().any(|signed| {
matches!(&signed.object,
BoardObject::BoardListing(existing)
if existing.board == value.board
&& existing.host == value.host)
});
ensure!(
!duplicate_first,
"a first listing already exists for this host"
);
Comment thread
dezren39 marked this conversation as resolved.
Resolved
}
}
BoardObject::Tombstone(value) => {
Expand Down Expand Up @@ -3102,6 +3112,45 @@ mod tests {
assert!(!latest.listed);
}

#[test]
fn second_first_listing_for_same_host_is_rejected() {
let owner = key(7);
let host = key(9);
let other_host = key(10);
let mut graph = BoardGraph::default();
let root = graph.insert(board(&owner)).unwrap();

// The first listing for a host is accepted ...
graph
.insert(listing(&owner, 1, root.clone(), &host, 1, true, None))
.unwrap();

// ... but a second chain-less v1 for the same host is rejected,
// whether the copy publishes or withdraws.
for (seq, listed) in [(2, true), (3, false)] {
let second_first = listing(&owner, seq, root.clone(), &host, 1, listed, None);
let err = graph.insert(second_first).unwrap_err();
assert!(
err.to_string()
.contains("a first listing already exists for this host"),
"unexpected error: {err}"
);
}

// A first listing for a different host on the same board is fine.
graph
.insert(listing(
&owner,
4,
root.clone(),
&other_host,
1,
false,
None,
))
.unwrap();
}

#[test]
fn two_hosts_converge_via_replication() {
let owner = key(7);
Expand Down
Loading