feat(store): add totp columns, org totp policy and global scope
Orgs are created inside their own tenant scope, so signup needs no system scope. Refs #3 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
caff396264
commit
99e9b1e57d
12 files changed
+203
-31
No files matched your search
@@ -52,10 +52,10 @@ func seed(t *testing.T, db *tenant.DB) fixture {
|
||||
suffix := uuid.NewString()[:8]
|
||||
err := db.Tx(ctx, tenant.System(), func(q *store.Queries) error {
|
||||
var err error
|
||||
if f.orgA, err = q.CreateOrg(ctx, store.CreateOrgParams{Slug: "a-" + suffix, Name: "A"}); err != nil {
|
||||
if f.orgA, err = q.CreateOrg(ctx, store.CreateOrgParams{ID: uuid.New(), Slug: "a-" + suffix, Name: "A"}); err != nil {
|
||||
return err
|
||||
}
|
||||
if f.orgB, err = q.CreateOrg(ctx, store.CreateOrgParams{Slug: "b-" + suffix, Name: "B"}); err != nil {
|
||||
if f.orgB, err = q.CreateOrg(ctx, store.CreateOrgParams{ID: uuid.New(), Slug: "b-" + suffix, Name: "B"}); err != nil {
|
||||
return err
|
||||
}
|
||||
if f.alice, err = q.CreateUser(ctx, store.CreateUserParams{Email: "alice-" + suffix + "@example.test"}); err != nil {
|
||||
@@ -79,6 +79,11 @@ func seed(t *testing.T, db *tenant.DB) fixture {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, id := range []uuid.UUID{f.alice.ID, f.bob.ID} {
|
||||
if _, err := q.DeleteUser(context.Background(), id); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
})
|
||||
@@ -186,3 +191,45 @@ func TestSingleOwnerPerOrg(t *testing.T) {
|
||||
t.Fatal("second owner accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGlobalScopeSeesNoTenantRows(t *testing.T) {
|
||||
db, _ := setup(t)
|
||||
f := seed(t, db)
|
||||
ctx := context.Background()
|
||||
err := db.Tx(ctx, tenant.Global(), func(q *store.Queries) error {
|
||||
if _, err := q.GetOrg(ctx, f.orgA.ID); !errors.Is(err, pgx.ErrNoRows) {
|
||||
t.Errorf("org visible in global scope: %v", err)
|
||||
}
|
||||
if _, err := q.GetUser(ctx, f.alice.ID); err != nil {
|
||||
t.Errorf("users must be readable in global scope: %v", err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewOrgCanBeCreatedInItsOwnScope(t *testing.T) {
|
||||
db, _ := setup(t)
|
||||
ctx := context.Background()
|
||||
id := uuid.New()
|
||||
err := db.Tx(ctx, tenant.Org(id, uuid.Nil), func(q *store.Queries) error {
|
||||
_, err := q.CreateOrg(ctx, store.CreateOrgParams{ID: id, Slug: "n-" + id.String()[:8], Name: "N"})
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_ = db.Tx(ctx, tenant.Org(id, uuid.Nil), func(q *store.Queries) error {
|
||||
_, err := q.DeleteOrg(ctx, id)
|
||||
return err
|
||||
})
|
||||
err = db.Tx(ctx, tenant.Org(uuid.New(), uuid.Nil), func(q *store.Queries) error {
|
||||
_, err := q.CreateOrg(ctx, store.CreateOrgParams{ID: uuid.New(), Slug: "x-" + id.String()[:8], Name: "X"})
|
||||
return err
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatal("org created outside its own scope")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user