Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
radicle-cli: return more helpful error when non-delegate attempts to update id document
✗ CI failure Adrian Duke committed 3 months ago
commit 47459af430effa1ab3953fed06b9ab05e8fcf6ee
parent 70ac659f099a27338f77515c7228fafee8816f0d
2 failed (2 total) View logs
3 files changed +78 -1
added crates/radicle-cli/examples/rad-id-unauthorized-delegate.md
@@ -0,0 +1,8 @@
+
Alice has created a new repository `rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji` with only herself as the sole delegate. After Bob has cloned it, let's ensure he can't add himself as a delegate too:
+

+
``` ~bob (fail)
+
$ rad id update --repo rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji --title "Add myself!" --delegate did:key:z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk --no-confirm
+
✗ Error: store: update error: apply failed: non-delegate not authorized to perform this action
+
✗ Hint: You are not currently a delegate of this repository!
+
```
+

modified crates/radicle-cli/src/commands/id.rs
@@ -427,7 +427,9 @@ where
    G: crypto::signature::Signer<crypto::Signature>,
{
    if let Some((title, description)) = edit_title_description(title, description)? {
-
        let id = current.update(title, description, &doc, signer)?;
+
        let id = current
+
            .update(title, description, &doc, signer)
+
            .map_err(on_identity_err)?;
        let revision = current
            .revision(&id)
            .ok_or(anyhow!("update failed: revision {id} is missing"))?;
@@ -438,6 +440,23 @@ where
    }
}

+
fn on_identity_err(e: identity::Error) -> anyhow::Error {
+
    let e = anyhow::Error::from(e);
+

+
    let apply_err = e
+
        .chain()
+
        .find_map(|c| c.downcast_ref::<identity::ApplyError>());
+

+
    match apply_err {
+
        Some(identity::ApplyError::NonDelegateUnauthorized) => Error::WithHint {
+
            err: e,
+
            hint: "You are not currently a delegate of this repository!",
+
        }
+
        .into(),
+
        _ => e,
+
    }
+
}
+

fn print_diff(
    previous: Option<&RevisionId>,
    current: &RevisionId,
modified crates/radicle-cli/tests/commands.rs
@@ -603,6 +603,56 @@ fn rad_id_multi_delegate() {
}

#[test]
+
fn rad_id_unauthorized_delegate() {
+
    let mut environment = Environment::new();
+
    let alice = environment.node("alice");
+
    let bob = environment.node("bob");
+
    let acme = RepoId::from_str("z42hL2jL4XNk6K8oHQaSWfMgCL7ji").unwrap();
+

+
    environment.repository(&alice);
+

+
    test(
+
        "examples/rad-init.md",
+
        environment.work(&alice),
+
        Some(&alice.home),
+
        [],
+
    )
+
    .unwrap();
+

+
    let mut alice = alice.spawn();
+
    let mut bob = bob.spawn();
+

+
    // Alice sets up the seed
+
    alice.handle.seed(acme, Scope::Followed).unwrap();
+

+
    bob.connect(&alice).converge([&alice]);
+
    bob.rad(
+
        "clone",
+
        &[acme.to_string().as_str()],
+
        environment.work(&bob),
+
    )
+
    .unwrap();
+

+
    formula(
+
        &environment.tempdir(),
+
        "examples/rad-id-unauthorized-delegate.md",
+
    )
+
    .unwrap()
+
    .home(
+
        "alice",
+
        environment.work(&alice),
+
        [("RAD_HOME", alice.home.path().display())],
+
    )
+
    .home(
+
        "bob",
+
        environment.work(&bob),
+
        [("RAD_HOME", bob.home.path().display())],
+
    )
+
    .run()
+
    .unwrap();
+
}
+

+
#[test]
#[ignore = "slow"]
fn rad_id_collaboration() {
    let mut environment = Environment::new();