mirror of
https://github.com/profullstack/agentbbs.git
synced 2026-12-01 09:24:46 +00:00
feat: let an account sign in with more than one SSH key (#178)
A member was bound to the single key they first signed in with, so a new machine got the finger card and could not reach the hub (or renew a plan). Extra keys live in user_keys; EnsureUser, UserByFingerprint and the finger check accept them. Operators add one with: agentbbs add-key NAME <pubkey|fp>. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
8a6e2f905f
commit
fc8206d0e2
4 changed files with 149 additions and 4 deletions
|
|
@ -194,3 +194,39 @@ func TestEnsureUserRejectsUnsafeNames(t *testing.T) {
|
|||
t.Fatalf("EnsureUser(okname): %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtraUserKeys(t *testing.T) {
|
||||
st := openTest(t)
|
||||
a, _ := st.EnsureUser("alice", "member", "SHA256:laptop")
|
||||
b, _ := st.EnsureUser("bob", "member", "SHA256:bob")
|
||||
|
||||
if _, err := st.EnsureUser("alice", "member", "SHA256:desktop"); !errors.Is(err, ErrKeyMismatch) {
|
||||
t.Fatalf("unknown key must mismatch, got %v", err)
|
||||
}
|
||||
if err := st.AddUserKey(a.ID, "SHA256:desktop"); err != nil {
|
||||
t.Fatalf("add: %v", err)
|
||||
}
|
||||
if err := st.AddUserKey(a.ID, "SHA256:desktop"); err != nil {
|
||||
t.Fatalf("re-add must be idempotent: %v", err)
|
||||
}
|
||||
if u, err := st.EnsureUser("alice", "member", "SHA256:desktop"); err != nil || u.ID != a.ID {
|
||||
t.Fatalf("extra key must sign in as alice: %v %+v", err, u)
|
||||
}
|
||||
if u, ok, err := st.UserByFingerprint("SHA256:desktop"); err != nil || !ok || u.ID != a.ID {
|
||||
t.Fatalf("lookup by extra key: %v %v %+v", err, ok, u)
|
||||
}
|
||||
if u, ok, _ := st.UserByFingerprint("SHA256:laptop"); !ok || u.ID != a.ID {
|
||||
t.Fatal("primary key must still work")
|
||||
}
|
||||
for fp, want := range map[string]bool{"SHA256:laptop": true, "SHA256:desktop": true, "SHA256:bob": false, "": false} {
|
||||
if got, _ := st.UserHasKey(a.ID, fp); got != want {
|
||||
t.Fatalf("UserHasKey(%q)=%v want %v", fp, got, want)
|
||||
}
|
||||
}
|
||||
if err := st.AddUserKey(a.ID, "SHA256:bob"); !errors.Is(err, ErrKeyInUse) {
|
||||
t.Fatalf("bob's primary key must not attach to alice: %v", err)
|
||||
}
|
||||
if err := st.AddUserKey(b.ID, "SHA256:desktop"); !errors.Is(err, ErrKeyInUse) {
|
||||
t.Fatalf("alice's extra key must not attach to bob: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue