Why: Administrator-issued password and login-key paths could take over target accounts, while old credentials and plugin handles ignored current account state. Evidence: SELF receipts /tmp/iam-u3-backend-all-replay.json, /tmp/iam-u3-backend-final-pg-core.json, /tmp/iam-u3-backend-build.json, and focused HTTP/concurrency receipts in /tmp/iam-u3-*.json. Impact: Adds trusted pending-account initialization and reissue, preexisting owner-session proof, proposal/rotation/grant transactions, server-side admin search, current Host guards, and legacy HTTP/CLI closure. Production cutover and downstream pins remain pending. Refs: IAM U3 r1 stages 4-5; Dev feature/iam-u3-account-directory-recovery
38 lines
1.3 KiB
Go
38 lines
1.3 KiB
Go
package store
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func TestAdminAccountSearchSnapshotRequiresCurrentSystemAuthority(t *testing.T) {
|
|
st := openTestStore(t)
|
|
t.Logf("admin directory dialect=%s", st.Dialect())
|
|
if err := st.CreateAccount("admin", "", "hash", true); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := st.CreateAccount("ordinary", "", "hash", false); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
pending, err := st.CreatePendingAccount("admin", "alice", AccountProfile{Email: "alice@example.test", Notes: "private"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
accounts, revision, err := st.ListAdminAccountsForActor("admin")
|
|
if err != nil || len(accounts) != 3 || revision.Private == "" {
|
|
t.Fatalf("authorized snapshot: accounts=%d rev=%+v err=%v", len(accounts), revision, err)
|
|
}
|
|
if accounts[1].ID != pending.ID || accounts[1].Profile.Email != "alice@example.test" {
|
|
t.Fatalf("profile snapshot or stable sort: %+v", accounts)
|
|
}
|
|
if _, _, err := st.ListAdminAccountsForActor("ordinary"); !errors.Is(err, ErrAccountForbidden) {
|
|
t.Fatalf("ordinary account read protected profiles: %v", err)
|
|
}
|
|
if _, err := st.DB().Exec(st.q(`UPDATE users SET enabled=? WHERE owner=?`), false, "admin"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, _, err := st.ListAdminAccountsForActor("admin"); !errors.Is(err, ErrAccountForbidden) {
|
|
t.Fatalf("disabled administrator read protected profiles: %v", err)
|
|
}
|
|
}
|