48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package service
|
|
|
|
import (
|
|
"SciencesServer/app/common/model"
|
|
"SciencesServer/serve/orm"
|
|
"SciencesServer/serve/orm/logic"
|
|
"gorm.io/gorm"
|
|
"testing"
|
|
)
|
|
|
|
func mysql() *gorm.DB {
|
|
instance := orm.NewInstance(
|
|
orm.WithDebug(false),
|
|
orm.WithDBMode("mysql"),
|
|
orm.WithTablePrefix(""),
|
|
orm.WithSingularTable(false),
|
|
orm.WithMaxIdleConns(3600),
|
|
orm.WithMaxOpenConns(2000),
|
|
orm.WithMaxLifetime(1000),
|
|
orm.WithMysqlOption(&logic.Mysql{
|
|
Username: "appuser", Password: "ABCabc01", Host: "192.168.0.188", Port: 3306,
|
|
Database: "sciences", Parameters: "charset=utf8mb4,utf8&parseTime=True&loc=Local",
|
|
}),
|
|
).Init()
|
|
return instance.Engine
|
|
}
|
|
|
|
func TestNewPermission(t *testing.T) {
|
|
mysql := mysql()
|
|
NewAuth().Register()("mysql", mysql, model.NewSysAuthRule().TableName())
|
|
|
|
permission := NewPermission(
|
|
WithAuthTenant("0"),
|
|
WithAuthUser("123"),
|
|
WithAuthRoles([]string{"1", "2"}),
|
|
WithAuthRequest([]*AuthRequest{&AuthRequest{
|
|
Url: "/admin/123",
|
|
Method: "*",
|
|
}}),
|
|
)
|
|
//status, err := permission.AddPolicies()
|
|
//status, err := permission.AddRoleForUser()
|
|
//status, err := permission.RemoveRolePolicies()
|
|
status, err := permission.Enforce()
|
|
t.Log(status)
|
|
t.Log(err)
|
|
}
|