From cb2cbf014a123a1cd0cd0f188f093e014f93647b Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Tue, 14 May 2024 15:59:08 +0100 Subject: [PATCH] cli: reject `rad id` proposals that do not verify To ensure that the `rad id` command does not modify the project payload without it being able to be deserialized into the `Project` type, the command performs this check throught the `project` method, and returns an error if this fails. Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- radicle-cli/examples/rad-id-update-delete-field.md | 7 +++++++ radicle-cli/src/commands/id.rs | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/radicle-cli/examples/rad-id-update-delete-field.md b/radicle-cli/examples/rad-id-update-delete-field.md index 548cc9c6..968dd829 100644 --- a/radicle-cli/examples/rad-id-update-delete-field.md +++ b/radicle-cli/examples/rad-id-update-delete-field.md @@ -69,3 +69,10 @@ $ rad id update --title "Delete field" --description "Delete 'web'" --payload xy "threshold": 1 } ``` + +Note that we cannot delete mandatory fields: + +``` (fails) +$ rad id update --title "Delete default branch" --payload xyz.radicle.project defaultBranch null +✗ Error: failed to verify `xyz.radicle.project`, failed with json: missing field `defaultBranch` +``` diff --git a/radicle-cli/src/commands/id.rs b/radicle-cli/src/commands/id.rs index f2333ee8..95153beb 100644 --- a/radicle-cli/src/commands/id.rs +++ b/radicle-cli/src/commands/id.rs @@ -390,6 +390,11 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { anyhow::bail!("payload `{id}` not found in identity document"); } } + // Verify that the project payload can still be parsed into the + // `Project` type. + if let Err(e) = proposal.project() { + anyhow::bail!("failed to verify `xyz.radicle.project`, failed with {e}",); + } proposal }; if proposal == current.doc {