feat: 新增共库模式下登录失败日志表及相关功能
- 新增登录失败日志表(共库多租户版),添加 tenant_id 列实现租户隔离 - 调整登录失败日志逻辑,仅记录触发账号锁定的事件 - 新增管理端接口功能,为登录失败日志补充实时锁定状态 - 更新测试用例适配共库模式下的租户过滤逻辑
This commit is contained in:
@@ -74,7 +74,7 @@ func TestMessageQuerySpecsExposeAdminFields(t *testing.T) {
|
||||
|
||||
func TestGroupMessageQuerySupportsOperationalFilters(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/?seq_id=42&sender_username=alice&sender_nickname=%E5%B0%8F%E6%98%8E&group_name=%E6%B5%8B%E8%AF%95%E7%BE%A4", nil)
|
||||
query, _, args, _, _, err := buildInternalAdminListQuery(req, groupMessagesInternalQuerySpec(), "")
|
||||
query, _, args, _, _, err := buildInternalAdminListQuery(req, groupMessagesInternalQuerySpec(), "", types.TenantID(1))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -83,7 +83,7 @@ func TestGroupMessageQuerySupportsOperationalFilters(t *testing.T) {
|
||||
t.Errorf("group message query missing %q: %s", clause, query)
|
||||
}
|
||||
}
|
||||
want := []any{int64(42), "%alice%", "%小明%", "%测试群%"}
|
||||
want := []any{int64(1), int64(42), "%alice%", "%小明%", "%测试群%"}
|
||||
if !reflect.DeepEqual(args, want) {
|
||||
t.Fatalf("unexpected filter arguments: got %#v, want %#v", args, want)
|
||||
}
|
||||
@@ -97,14 +97,20 @@ func TestLoginAuditQuerySpecsExposeUserIDAsString(t *testing.T) {
|
||||
if !strings.Contains(spec.Select, "CAST(user_id AS CHAR) AS user_id") {
|
||||
t.Fatalf("user-login-logs query must expose 64-bit user IDs as strings: %s", spec.Select)
|
||||
}
|
||||
if internalTenantResourceSpecs["login-failure-logs"] != nil {
|
||||
t.Fatal("login-failure-logs query spec must be removed with im_login_failure_logs")
|
||||
// login-failure-logs 保留(仅记录触发锁定的事件,见 session.go lockedNow 分支),
|
||||
// 但共库模式必须带 tenant_id 隔离列,防止跨租户看到彼此的失败日志。
|
||||
failureSpec := internalTenantResourceSpecs["login-failure-logs"]
|
||||
if failureSpec == nil {
|
||||
t.Fatal("login-failure-logs query spec missing")
|
||||
}
|
||||
if failureSpec.TenantColumn != "tenant_id" {
|
||||
t.Fatalf("login-failure-logs query spec must filter by tenant_id: %+v", failureSpec)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUserQuerySupportsKeywordAndUserIDs(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/?keyword=alice&user_ids=101,202&account_no=1000", nil)
|
||||
query, countQuery, args, _, _, err := buildInternalAdminListQuery(req, usersInternalQuerySpec(), "")
|
||||
query, countQuery, args, _, _, err := buildInternalAdminListQuery(req, usersInternalQuerySpec(), "", types.TenantID(1))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -113,7 +119,7 @@ func TestUserQuerySupportsKeywordAndUserIDs(t *testing.T) {
|
||||
t.Fatalf("user query missing %q: %s", clause, query)
|
||||
}
|
||||
}
|
||||
want := []any{int64(101), int64(202), int64(1000), "%alice%"}
|
||||
want := []any{int64(1), int64(101), int64(202), int64(1000), "%alice%"}
|
||||
if !reflect.DeepEqual(args, want) {
|
||||
t.Fatalf("unexpected filter arguments: got %#v, want %#v", args, want)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user