Repository navigation
Grey out opening a private channel that has other members #3145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
loganj
wants to merge
5
commits into
main
Choose a base branch
from
loganj/private-open-guard
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,002
−377
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bf6f5c7
Explain why a private channel with other members cannot be opened
loganj 73c511e
Refuse an open access pick the opening check closes later
loganj 17696e0
Cover opening-check wiring and the already-open boundary
loganj bc7ff81
Prefer a verified owner over the agent inventory when predicting opening
loganj 8099f1f
Cover each opening rule and use one "create a new channel" reason
loganj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import { expect, it } from "vitest"; | ||
| import { openingBlocked } from "./general-access"; | ||
|
|
||
| const viewer = "a".repeat(64); | ||
| const ownAgent = "b".repeat(64); | ||
| const inventoryAgent = "c".repeat(64); | ||
| const person = "d".repeat(64); | ||
| const othersAgent = "e".repeat(64); | ||
| const claimedAgent = "f".repeat(64); | ||
| const unloaded = "1".repeat(64); | ||
| const listedOthersAgent = "2".repeat(64); | ||
| const flaggedAgent = "3".repeat(64); | ||
| const verified = new Map([ | ||
| [ownAgent, viewer], | ||
| [othersAgent, person], | ||
| [listedOthersAgent, person], | ||
| ]); | ||
| const session = { | ||
| viewer, | ||
| profiles: { | ||
| snapshot: () => | ||
| new Map<string, { isAgent?: true; ownerPubkey?: string }>([ | ||
| [ownAgent, { isAgent: true, ownerPubkey: viewer }], | ||
| [othersAgent, { isAgent: true, ownerPubkey: person }], | ||
| // An agent whose attestation is missing or does not verify. | ||
| [claimedAgent, { isAgent: true, ownerPubkey: viewer }], | ||
| [person, {}], | ||
| // Listed in the viewer's inventory; its profile claims no agent. | ||
| [inventoryAgent, {}], | ||
| // An agent only by its profile content: no auth tag, no inventory entry. | ||
| [flaggedAgent, { isAgent: true }], | ||
| ]), | ||
| owner: (pubkey: string) => verified.get(pubkey), | ||
| }, | ||
| agentChoices: { | ||
| snapshot: () => ({ | ||
| identities: [{ pubkey: inventoryAgent }, { pubkey: listedOthersAgent }], | ||
| complete: true, | ||
| }), | ||
| }, | ||
| }; | ||
|
|
||
| it.each([ | ||
| ["only the viewer", [viewer], false], | ||
| ["the viewer and their agents", [viewer, ownAgent, inventoryAgent], false], | ||
| ["another person", [viewer, person], true], | ||
| ["someone else's verified agent", [viewer, othersAgent], true], | ||
| [ | ||
| "someone else's verified agent in the viewer's inventory", | ||
| [viewer, listedOthersAgent], | ||
| true, | ||
| ], | ||
| ["an agent with unverified ownership", [viewer, claimedAgent], false], | ||
| ["an agent flagged only in its profile", [viewer, flaggedAgent], false], | ||
| ["a member whose profile has not loaded", [viewer, unloaded], false], | ||
| ["an unknown roster", undefined, false], | ||
| ] as const)("%s", (_, members, blocked) => { | ||
| expect(openingBlocked(session, members)).toBe(blocked); | ||
| }); | ||
|
|
||
| it("blocks once a member's profile shows a person", () => { | ||
| const loaded = new Map(session.profiles.snapshot()); | ||
| const later = { | ||
| ...session, | ||
| profiles: { ...session.profiles, snapshot: () => loaded }, | ||
| }; | ||
| expect(openingBlocked(later, [viewer, unloaded])).toBe(false); | ||
| loaded.set(unloaded, {}); | ||
| expect(openingBlocked(later, [viewer, unloaded])).toBe(true); | ||
| }); | ||
|
|
||
| it("leaves an untagged member to the relay while the inventory is incomplete", () => { | ||
| const loading = { | ||
| ...session, | ||
| agentChoices: { | ||
| snapshot: () => ({ identities: [], complete: false }), | ||
| }, | ||
| }; | ||
| expect(openingBlocked(loading, [viewer, person])).toBe(false); | ||
| expect(openingBlocked(loading, [viewer, othersAgent])).toBe(true); | ||
| }); | ||
|
|
||
| it("never blocks without a viewer", () => { | ||
| expect(openingBlocked({ ...session, viewer: undefined }, [person])).toBe( | ||
| false, | ||
| ); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.