feat(auth): support tenantless provisioning and gated self-service workspace creation
Allow deployments to register users without auto-creating a personal tenant, expose creation policy via /auth/me, and guide tenantless accounts through a workspace onboarding flow.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
)
|
||||
|
||||
func TestTenantOptionalAPISurface(t *testing.T) {
|
||||
tests := []struct {
|
||||
method string
|
||||
path string
|
||||
want bool
|
||||
}{
|
||||
{http.MethodGet, "/api/v1/auth/me", true},
|
||||
{http.MethodPut, "/api/v1/auth/me", true},
|
||||
{http.MethodPost, "/api/v1/tenants", true},
|
||||
{http.MethodGet, "/api/v1/me/invitations", true},
|
||||
{http.MethodPost, "/api/v1/me/invitations/12/accept", true},
|
||||
{http.MethodGet, "/api/v1/knowledge-bases", false},
|
||||
{http.MethodGet, "/api/v1/tenants", false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
if got := isTenantOptionalAPI(tt.path, tt.method); got != tt.want {
|
||||
t.Errorf("isTenantOptionalAPI(%s %s) = %v, want %v", tt.method, tt.path, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveFirstMembershipTarget(t *testing.T) {
|
||||
members := newFakeMemberService()
|
||||
members.seedActive("tenantless-user", 42, types.TenantRoleViewer)
|
||||
tenants := &fakeTenantService{tenant: &types.Tenant{ID: 42}}
|
||||
|
||||
got := resolveFirstMembershipTarget(
|
||||
context.Background(),
|
||||
&types.User{ID: "tenantless-user"},
|
||||
members,
|
||||
tenants,
|
||||
)
|
||||
if got != 42 {
|
||||
t.Fatalf("resolved tenant = %d, want 42", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user