diff --git a/api/init.go b/api/init.go index cb55bf7..dd8fbca 100644 --- a/api/init.go +++ b/api/init.go @@ -49,10 +49,6 @@ func init() { Router.Use(cfg.Auth.Login()) Router.After(common.JsonResponse, common.JsonErrorResponse) - // 初始化角色 - cfg.Auth.AddRole("admin", "管理员", "*:7") - cfg.Auth.AddRole("user", "普通用户") - // 子路由挂载 Router.Extend("/auth", apiAuth.Router) Router.Extend("/users", user.Router) diff --git a/init.go b/init.go index a6d2c5d..6d7558f 100644 --- a/init.go +++ b/init.go @@ -27,19 +27,19 @@ var ( ) func init() { - // 初始化 VBaseProvider 并设置到全局 Auth - auth.VBaseProvider = auth.Factory.New("vb") - cfg.Auth.SetProvider(auth.VBaseProvider) - Router.Extend("/api", api.Router) Router.Extend("v", vhtmlui.Router) Router.Extend("vhtml", vhtml.Router) - vhtml.WrapUI(Router, uifs) } type Options = cfg.Options func Init() error { + // 初始化 VBaseProvider 并设置到全局 Auth + cfg.Auth.SetProvider(NewAuth("vb")) + // 初始化角色 + cfg.Auth.AddRole("admin", "管理员", "*:7") + cfg.Auth.AddRole("user", "普通用户") return models.Migrate() } diff --git a/tests/scoped_auth_test.go b/tests/scoped_auth_test.go index 49ccd2b..e5401b9 100644 --- a/tests/scoped_auth_test.go +++ b/tests/scoped_auth_test.go @@ -29,11 +29,6 @@ func TestScopedAuth(t *testing.T) { if !testAuth.Check(ctx, User1ID, permID, level) { t.Errorf("Expected User1 to have %s in %s scope", permID, scope) } - - // Verify Check in global VBaseProvider scope (should be false) - if auth.VBaseProvider.Check(ctx, User1ID, permID, level) { - t.Errorf("Expected User1 NOT to have %s in 'vb' scope", permID) - } }) // 2. Test Hierarchy (Admin Inheritance vs Normal Strictness)