对接
This commit is contained in:
@@ -25,16 +25,16 @@ func TestCatalogContainsBuiltInModulesInDependencyOrder(t *testing.T) {
|
||||
t.Fatalf("definition[%d] = %q, want %q", index, got, name)
|
||||
}
|
||||
}
|
||||
if got := catalog.MigrationSteps(); len(got) != 22 {
|
||||
t.Fatalf("module migrations = %d, want 22", len(got))
|
||||
if got := catalog.MigrationSteps(); len(got) != 26 {
|
||||
t.Fatalf("module migrations = %d, want 26", len(got))
|
||||
}
|
||||
var menus, apis int
|
||||
for _, definition := range catalog.Definitions {
|
||||
menus += len(definition.Surface.Menus)
|
||||
apis += len(definition.Surface.APIs)
|
||||
}
|
||||
if menus != 11 || apis != 50 {
|
||||
t.Fatalf("admin surface = %d menus/%d APIs, want 11/50", menus, apis)
|
||||
if menus != 11 || apis != 69 {
|
||||
t.Fatalf("admin surface = %d menus/%d APIs, want 11/69", menus, apis)
|
||||
}
|
||||
if got := catalog.DefaultTimedTasks(); len(got) != 2 {
|
||||
t.Fatalf("default timed tasks = %d, want 2", len(got))
|
||||
|
||||
@@ -39,10 +39,24 @@ func Definition() module.Definition {
|
||||
steps = append(steps, migration.Step{ID: "202609210001_remove_live_dashboard_menu", Migrate: func(db *gorm.DB) error {
|
||||
return datasystem.RemoveAdminMenus(db, "liveDashboard")
|
||||
}})
|
||||
steps = append(steps, migration.Step{ID: "202609220004_live_client_policies", Migrate: func(db *gorm.DB) error {
|
||||
// Existing live-client accounts do not pass through the registration
|
||||
// path after an upgrade, so add newly introduced client endpoints to
|
||||
// their role without replacing any administrator-managed policies.
|
||||
return datasystem.GrantAuthorityAPIs(db, 1000, []module.API{
|
||||
{Method: "POST", Path: "/live/client/auth/logout"},
|
||||
{Method: "GET", Path: "/live/client/balance"},
|
||||
{Method: "GET", Path: "/live/rooms/:id/follow"},
|
||||
{Method: "POST", Path: "/live/rooms/:id/follow"},
|
||||
{Method: "DELETE", Path: "/live/rooms/:id/follow"},
|
||||
{Method: "GET", Path: "/live/recharge/orders/:orderNo"},
|
||||
{Method: "GET", Path: "/live/recharge/orders/:orderNo/status"},
|
||||
})
|
||||
}})
|
||||
return module.Definition{Name: "live", Migrations: steps, Surface: module.Surface{Menus: menus, APIs: apis}}
|
||||
}
|
||||
func APIs() []module.API {
|
||||
defs := []struct{ m, p, d string }{{"GET", "/live/admin/dashboard", "直播数据概览"}, {"GET", "/live/admin/categories", "查询直播分类"}, {"POST", "/live/admin/categories", "新建直播分类"}, {"PUT", "/live/admin/categories/:id", "更新直播分类"}, {"DELETE", "/live/admin/categories/:id", "删除直播分类"}, {"GET", "/live/admin/rooms", "查询直播间"}, {"GET", "/live/admin/rooms/:id", "查询直播间详情"}, {"POST", "/live/admin/rooms", "新建直播间"}, {"PUT", "/live/admin/rooms/:id", "更新直播间"}, {"DELETE", "/live/admin/rooms/:id", "删除直播间"}, {"PATCH", "/live/admin/rooms/:id/status", "启停直播间"}, {"PUT", "/live/admin/rooms/sort", "保存直播间排序"}, {"GET", "/live/admin/gifts", "查询礼物"}, {"GET", "/live/admin/gifts/:id", "查询礼物详情"}, {"POST", "/live/admin/gifts", "新建礼物"}, {"PUT", "/live/admin/gifts/:id", "更新礼物"}, {"DELETE", "/live/admin/gifts/:id", "删除礼物"}, {"PATCH", "/live/admin/gifts/:id/status", "上下架礼物"}, {"PUT", "/live/admin/gifts/sort", "保存礼物排序"}, {"GET", "/live/admin/sends", "查询打赏流水"}, {"GET", "/live/admin/orders", "查询充值订单"}, {"GET", "/live/admin/orders/:orderNo", "查询充值订单详情"}, {"PUT", "/live/admin/recharge/plans", "保存充值档位"}, {"GET", "/live/admin/users", "查询用户资产"}, {"GET", "/live/admin/users/:id", "查询用户详情"}, {"PATCH", "/live/admin/users/:id/status", "启停用户"}, {"POST", "/live/admin/users/:id/balance", "调整钻石余额"}, {"PUT", "/live/admin/settings", "保存全站设置"}, {"GET", "/live/client/me", "获取直播用户资料"}, {"PUT", "/live/client/me", "更新直播用户资料"}, {"PUT", "/live/client/me/password", "修改直播用户密码"}, {"POST", "/live/rooms/:id/gifts", "直播间送礼"}, {"POST", "/live/recharge/orders", "创建充值订单"}}
|
||||
defs := []struct{ m, p, d string }{{"GET", "/live/streams", "获取在线直播列表"}, {"GET", "/live/streams/:streamId", "获取直播间状态"}, {"GET", "/live/categories", "获取直播分类"}, {"GET", "/live/rooms", "分页获取热门直播间"}, {"GET", "/live/rooms/:id", "获取直播间详情"}, {"POST", "/live/rooms/:id/like", "直播间点赞"}, {"GET", "/live/rooms/:id/follow", "查询关注状态"}, {"POST", "/live/rooms/:id/follow", "关注直播间"}, {"DELETE", "/live/rooms/:id/follow", "取消关注"}, {"GET", "/live/rooms/:id/messages", "获取直播间聊天记录"}, {"GET", "/live/gifts", "获取可用礼物"}, {"GET", "/live/recharge/providers", "获取可用充值支付渠道"}, {"GET", "/live/recharge/plans", "获取充值档位"}, {"POST", "/live/client/auth/login", "直播用户登录"}, {"POST", "/live/client/auth/register", "直播用户注册"}, {"POST", "/live/client/auth/logout", "直播用户退出"}, {"GET", "/live/client/me", "获取直播用户资料"}, {"GET", "/live/client/balance", "获取钻石余额"}, {"PUT", "/live/client/me", "更新直播用户资料"}, {"PUT", "/live/client/me/password", "修改直播用户密码"}, {"GET", "/live/recharge/orders/:orderNo", "查询我的充值订单"}, {"GET", "/live/recharge/orders/:orderNo/status", "查询我的充值支付状态"}, {"POST", "/live/rooms/:id/gifts", "直播间送礼"}, {"POST", "/live/recharge/orders", "创建充值订单"}, {"GET", "/live/admin/dashboard", "直播数据概览"}, {"GET", "/live/admin/categories", "查询直播分类"}, {"POST", "/live/admin/categories", "新建直播分类"}, {"PUT", "/live/admin/categories/:id", "更新直播分类"}, {"DELETE", "/live/admin/categories/:id", "删除直播分类"}, {"GET", "/live/admin/rooms", "查询直播间"}, {"GET", "/live/admin/rooms/:id", "查询直播间详情"}, {"POST", "/live/admin/rooms", "新建直播间"}, {"PUT", "/live/admin/rooms/:id", "更新直播间"}, {"DELETE", "/live/admin/rooms/:id", "删除直播间"}, {"PATCH", "/live/admin/rooms/:id/status", "启停直播间"}, {"PUT", "/live/admin/rooms/sort", "保存直播间排序"}, {"GET", "/live/admin/gifts", "查询礼物"}, {"GET", "/live/admin/gifts/:id", "查询礼物详情"}, {"POST", "/live/admin/gifts", "新建礼物"}, {"PUT", "/live/admin/gifts/:id", "更新礼物"}, {"DELETE", "/live/admin/gifts/:id", "删除礼物"}, {"PATCH", "/live/admin/gifts/:id/status", "上下架礼物"}, {"PUT", "/live/admin/gifts/sort", "保存礼物排序"}, {"GET", "/live/admin/sends", "查询打赏流水"}, {"GET", "/live/admin/orders", "查询充值订单"}, {"GET", "/live/admin/orders/:orderNo", "查询充值订单详情"}, {"PUT", "/live/admin/recharge/plans", "保存充值档位"}, {"GET", "/live/admin/users", "查询用户资产"}, {"GET", "/live/admin/users/:id", "查询用户详情"}, {"PATCH", "/live/admin/users/:id/status", "启停用户"}, {"POST", "/live/admin/users/:id/balance", "调整钻石余额"}, {"PUT", "/live/admin/settings", "保存全站设置"}}
|
||||
out := make([]module.API, 0, len(defs))
|
||||
for _, v := range defs {
|
||||
out = append(out, module.API{Path: v.p, Method: v.m, Group: "宇宙直播", Description: v.d})
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package live
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/glebarez/sqlite"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func TestLiveClientPolicyMigrationAddsNewPrivateRoutes(t *testing.T) {
|
||||
db, err := gorm.Open(sqlite.Open("file:"+t.Name()+"?mode=memory&cache=shared"), &gorm.Config{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = db.Exec(`CREATE TABLE casbin_rule (
|
||||
id integer primary key autoincrement,
|
||||
ptype text,
|
||||
v0 text,
|
||||
v1 text,
|
||||
v2 text,
|
||||
v3 text,
|
||||
v4 text,
|
||||
v5 text
|
||||
)`).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var migrate func(*gorm.DB) error
|
||||
for _, step := range Definition().Migrations {
|
||||
if step.ID == "202609220004_live_client_policies" {
|
||||
migrate = step.Migrate
|
||||
break
|
||||
}
|
||||
}
|
||||
if migrate == nil {
|
||||
t.Fatal("live client policy migration is missing")
|
||||
}
|
||||
if err = migrate(db); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = migrate(db); err != nil {
|
||||
t.Fatalf("policy migration is not idempotent: %v", err)
|
||||
}
|
||||
|
||||
want := []struct{ method, path string }{
|
||||
{method: "POST", path: "/live/client/auth/logout"},
|
||||
{method: "GET", path: "/live/client/balance"},
|
||||
{method: "GET", path: "/live/rooms/:id/follow"},
|
||||
{method: "POST", path: "/live/rooms/:id/follow"},
|
||||
{method: "DELETE", path: "/live/rooms/:id/follow"},
|
||||
{method: "GET", path: "/live/recharge/orders/:orderNo"},
|
||||
{method: "GET", path: "/live/recharge/orders/:orderNo/status"},
|
||||
}
|
||||
for _, route := range want {
|
||||
var count int64
|
||||
if err = db.Table("casbin_rule").Where("ptype = ? AND v0 = ? AND v1 = ? AND v2 = ?", "p", "1000", route.path, route.method).Count(&count).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if count != 1 {
|
||||
t.Errorf("policy %s %s count = %d, want 1", route.method, route.path, count)
|
||||
}
|
||||
}
|
||||
|
||||
var publicProviderPolicies int64
|
||||
if err = db.Table("casbin_rule").Where("v0 = ? AND v1 = ?", "1000", "/live/recharge/providers").Count(&publicProviderPolicies).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if publicProviderPolicies != 0 {
|
||||
t.Fatalf("public provider discovery unexpectedly received a client policy: %d", publicProviderPolicies)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user