git-ents.gitmain
⌘K
foforge
commit 6f95295
roots: resolve account create's default member from the given key

account create without --member resolved the owning member via members::check(root, None), ignoring the --key argument entirely and falling back to the host’s default signing key resolution. Passing a non-default --key could silently attribute the account to whatever member the default key resolved to, rather than the one the given key actually belongs to.

Assisted-by: Claude:claude-sonnet-5

Joseph D. Carpinelli · 1 month ago

Reviews

No reviews of this commit yet — record a verdict below.

Start a review

verdict

crates/git-ents/tests/account.rs @@ -31,3 +31,29 @@ assert_eq!(account.member, ents_model::MemberId::new("jdc")); assert_eq!(account.login, "joseph.carpinelli@icloud.com"); } + +/// Omitting `--member` resolves the owning member from the *given* `--key`, +/// not from whatever key the host's own default resolution would pick — +/// otherwise `create` could silently attribute the account to the wrong +/// member when signing with a non-default key. +// @relation(roots.local, model.account, scope=function, role=Verifies) +#[test] +fn create_without_member_resolves_from_the_given_key() { + let fixture = common::Fixture::new(1); + let root = LocalRoot::open(fixture.path()).expect("opens"); + members::add(&root, "jdc", None, Some(fixture.key_path.clone())).expect("bootstrap jdc"); + + let other_key_path = common::write_key_in(fixture.path(), 2); + members::add(&root, "other", None, Some(other_key_path.clone())).expect("bootstrap other"); + + account::create( + &root, + None, + "other@example.com".to_owned(), + Some(other_key_path), + ) + .expect("creates"); + + let account = account::show(&root).expect("shows"); + assert_eq!(account.member, ents_model::MemberId::new("other")); +}
crates/git-ents/src/commands/account.rs @@ -50,12 +50,12 @@ login: String, key: Option<std::path::PathBuf>, ) -> Result<()> { - let signer = signer(root, key)?; + let signer = signer(root, key.clone())?; let member_id = match member { Some(username) => MemberId::new(username), None => { let (username, _) = - super::members::check(root, None)?.ok_or_else(|| Error::NotFound { + super::members::check(root, key)?.ok_or_else(|| Error::NotFound { what: "member for the current signing key".to_owned(), })?; MemberId::new(username)