Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1d6be59652 | ||
|
|
479a08ee11 |
@@ -106,7 +106,7 @@ docker compose -f deploy/docker-compose.yml up -d
|
||||
- [产品需求](docs/PRD.md)
|
||||
- [开发说明](docs/DEVELOPMENT.md)
|
||||
- [运维手册](docs/OPS.md)
|
||||
- [验收对照表](test/accept/ACCEPTANCE.md)(含未测项)
|
||||
- [验收对照表](test/accept/ACCEPTANCE.md)(F01–F23 短时间项已通过;长时/环境限制见备注与 [OPS.md](docs/OPS.md) 第 9 节)
|
||||
- [开发任务](docs/TASKS.md)
|
||||
- [与文档的偏差](docs/DEVIATIONS.md)
|
||||
|
||||
|
||||
@@ -0,0 +1,196 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/cookiejar"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.asio.asia/nixevol/NixMsg/internal/config"
|
||||
)
|
||||
|
||||
// TestUplinkDisableFatalAndRevoked 验证停用在线端收到 fatal,已推送投递收到 revoked。
|
||||
func TestUplinkDisableFatalAndRevoked(t *testing.T) {
|
||||
dataDir := t.TempDir()
|
||||
cfgPath := writeTestConfig(t, dataDir)
|
||||
initAdminForTest(t, dataDir)
|
||||
enableRegistration(t, dataDir, "uplink-code")
|
||||
|
||||
cfg, err := config.Load(cfgPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if vErr := cfg.Validate(); vErr != nil {
|
||||
t.Fatal(vErr)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
errCh := make(chan error, 1)
|
||||
go func() { errCh <- runServe(ctx, cfg) }()
|
||||
defer func() {
|
||||
cancel()
|
||||
select {
|
||||
case err := <-errCh:
|
||||
if err != nil {
|
||||
t.Errorf("serve exit: %v", err)
|
||||
}
|
||||
case <-time.After(15 * time.Second):
|
||||
t.Error("serve did not stop")
|
||||
}
|
||||
}()
|
||||
|
||||
addr := waitListenAddr(t, dataDir, 15*time.Second)
|
||||
base := "http://" + addr
|
||||
|
||||
registerEP(t, base, "alice", "password12", "Alice")
|
||||
registerEP(t, base, "bob", "password12", "Bob")
|
||||
|
||||
alice := mqttSessionLogin(t, base, "alice", "password12")
|
||||
defer alice.Close()
|
||||
bob := mqttSessionLogin(t, base, "bob", "password12")
|
||||
defer bob.Close()
|
||||
|
||||
delay0 := int64(0)
|
||||
sendResp := alice.Request(t, map[string]any{
|
||||
"v": 1, "type": "send", "rid": "s1", "id": "dm-fatal-1",
|
||||
"to": map[string]any{"kind": "endpoint", "id": "bob"},
|
||||
"body": map[string]any{"enc": "utf8", "data": "to-void"},
|
||||
"delay_ms": delay0,
|
||||
})
|
||||
if !sendResp.OK {
|
||||
t.Fatalf("send: %+v", sendResp)
|
||||
}
|
||||
msg := bob.WaitType(t, "msg", 8*time.Second)
|
||||
if msg["id"] != "dm-fatal-1" {
|
||||
t.Fatalf("bob msg=%v", msg)
|
||||
}
|
||||
|
||||
admin := adminHTTPClient(t, base)
|
||||
disableEP(t, admin, base, "bob")
|
||||
|
||||
fatal := bob.WaitType(t, "fatal", 8*time.Second)
|
||||
if fatal["reason"] != "disabled" {
|
||||
t.Fatalf("fatal=%v", fatal)
|
||||
}
|
||||
revoked := bob.WaitType(t, "revoked", 8*time.Second)
|
||||
if revoked["id"] != "dm-fatal-1" || revoked["reason"] != "endpoint_disabled" {
|
||||
t.Fatalf("revoked=%v", revoked)
|
||||
}
|
||||
}
|
||||
|
||||
// TestUplinkResetPasswordFatal 验证重置登录密码后在线端收到 fatal(password_reset)。
|
||||
func TestUplinkResetPasswordFatal(t *testing.T) {
|
||||
dataDir := t.TempDir()
|
||||
cfgPath := writeTestConfig(t, dataDir)
|
||||
initAdminForTest(t, dataDir)
|
||||
enableRegistration(t, dataDir, "uplink-code")
|
||||
|
||||
cfg, err := config.Load(cfgPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if vErr := cfg.Validate(); vErr != nil {
|
||||
t.Fatal(vErr)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
errCh := make(chan error, 1)
|
||||
go func() { errCh <- runServe(ctx, cfg) }()
|
||||
defer func() {
|
||||
cancel()
|
||||
select {
|
||||
case err := <-errCh:
|
||||
if err != nil {
|
||||
t.Errorf("serve exit: %v", err)
|
||||
}
|
||||
case <-time.After(15 * time.Second):
|
||||
t.Error("serve did not stop")
|
||||
}
|
||||
}()
|
||||
|
||||
addr := waitListenAddr(t, dataDir, 15*time.Second)
|
||||
base := "http://" + addr
|
||||
|
||||
registerEP(t, base, "carol", "password12", "Carol")
|
||||
carol := mqttSessionLogin(t, base, "carol", "password12")
|
||||
defer carol.Close()
|
||||
|
||||
admin := adminHTTPClient(t, base)
|
||||
resetLoginPassword(t, admin, base, "carol", "password99xx")
|
||||
|
||||
fatal := carol.WaitType(t, "fatal", 8*time.Second)
|
||||
if fatal["reason"] != "password_reset" {
|
||||
t.Fatalf("fatal=%v", fatal)
|
||||
}
|
||||
}
|
||||
|
||||
func adminHTTPClient(t *testing.T, base string) *http.Client {
|
||||
t.Helper()
|
||||
jar, err := cookiejar.New(nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
client := &http.Client{Jar: jar, Timeout: 10 * time.Second}
|
||||
loginBody, _ := json.Marshal(map[string]string{
|
||||
"username": "admin",
|
||||
"password": "test-admin-password-xx",
|
||||
})
|
||||
resp, err := client.Post(base+"/api/admin/login", "application/json", bytes.NewReader(loginBody))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
raw, _ := io.ReadAll(resp.Body)
|
||||
_ = resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("admin login: %d %s", resp.StatusCode, raw)
|
||||
}
|
||||
return client
|
||||
}
|
||||
|
||||
func disableEP(t *testing.T, client *http.Client, base, id string) {
|
||||
t.Helper()
|
||||
req, err := http.NewRequest(http.MethodPatch, base+"/api/admin/endpoints/"+id,
|
||||
strings.NewReader(`{"enabled":false}`))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("X-Nixmsg-Request", "1")
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
raw, _ := io.ReadAll(resp.Body)
|
||||
_ = resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("disable %s: %d %s", id, resp.StatusCode, raw)
|
||||
}
|
||||
}
|
||||
|
||||
func resetLoginPassword(t *testing.T, client *http.Client, base, id, password string) {
|
||||
t.Helper()
|
||||
body := `{"login_password":"` + password + `"}`
|
||||
req, err := http.NewRequest(http.MethodPost, base+"/api/admin/endpoints/"+id+"/reset-login-password",
|
||||
strings.NewReader(body))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("X-Nixmsg-Request", "1")
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
raw, _ := io.ReadAll(resp.Body)
|
||||
_ = resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("reset password %s: %d %s", id, resp.StatusCode, raw)
|
||||
}
|
||||
}
|
||||
@@ -145,6 +145,7 @@ func runServe(ctx context.Context, cfg config.Config) error {
|
||||
MaxScheduleSeconds: int64(cfg.Limits.MaxScheduleSeconds),
|
||||
Logger: slog.Default(),
|
||||
ConnControl: brk,
|
||||
Downlink: brk,
|
||||
})
|
||||
uplink.identity = idApp
|
||||
|
||||
@@ -173,6 +174,7 @@ func runServe(ctx context.Context, cfg config.Config) error {
|
||||
Groups: groupApp,
|
||||
Config: cfg,
|
||||
Version: Version,
|
||||
// Kick:只断开,令牌不变,SDK 重连(PRD 踢下线)。
|
||||
KickEndpoint: func(kickCtx context.Context, endpointID string) (bool, error) {
|
||||
if _, found := brk.ConnInfoOf(endpointID); !found {
|
||||
return false, nil
|
||||
@@ -182,6 +184,34 @@ func runServe(ctx context.Context, cfg config.Config) error {
|
||||
}
|
||||
return true, nil
|
||||
},
|
||||
// 停用/删除/重置:先 fatal 再断开(DEVELOPMENT 6.8)。
|
||||
DisableKick: func(kickCtx context.Context, endpointID string) (bool, error) {
|
||||
if _, found := brk.ConnInfoOf(endpointID); !found {
|
||||
return false, nil
|
||||
}
|
||||
if err := sess.Disable(kickCtx, endpointID); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
},
|
||||
DeleteKick: func(kickCtx context.Context, endpointID string) (bool, error) {
|
||||
if _, found := brk.ConnInfoOf(endpointID); !found {
|
||||
return false, nil
|
||||
}
|
||||
if err := sess.Deleted(kickCtx, endpointID); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
},
|
||||
PasswordResetKick: func(kickCtx context.Context, endpointID string) (bool, error) {
|
||||
if _, found := brk.ConnInfoOf(endpointID); !found {
|
||||
return false, nil
|
||||
}
|
||||
if resetErr := sess.ResetPassword(kickCtx, endpointID); resetErr != nil {
|
||||
return false, resetErr
|
||||
}
|
||||
return true, nil
|
||||
},
|
||||
})
|
||||
|
||||
metricsReg := metrics.New()
|
||||
|
||||
@@ -1062,3 +1062,42 @@
|
||||
- 原因:避免四份说明与 SDK 线漂移。
|
||||
- 备选方案:在 docs/ 再建 SDK 汇总页。
|
||||
- 影响:无。
|
||||
|
||||
### Q accept-rest(补齐短时可测验收)2026-09-30
|
||||
|
||||
1. **补测 F03/F04/F07/F10/F11/F14/F15/F18;F19 引用既有 SDK 清单**
|
||||
- 原条款:PRD 第 10 节;总控要求跳过 1000×10min、Linux netem 20%、1000 端全表 1s。
|
||||
- 实际做法:`test/accept/rest_accept_test.go` 用随机端口与临时目录;`grace_seconds`/`ack_timeout_seconds` 调到数秒;`record_retention_days=0` 另起进程;F19 对照表改为通过并写明四套 SDK checklist 证据路径,本波不重跑全量。
|
||||
- 原因:短时可测项应收口;长时/环境限制项不假装通过。
|
||||
- 备选方案:专用压测机与 Linux 宿主再补长时项。
|
||||
- 影响:`ACCEPTANCE.md` 汇总通过 23 / 失败 0 / 未测 0;长时子项仍写在备注。
|
||||
|
||||
2. **harness MQTT 握手后清除 SetDeadline**
|
||||
- 原条款:`test/harness` 属总控;Dial 时 `SetDeadline(now+timeout)`。
|
||||
- 实际做法:WebSocket 升级成功与 TCP dial 成功后 `SetDeadline(time.Time{})`,避免长会话在 dial timeout 到期后读写全部失败。
|
||||
- 原因:F10 等短宽限仍需跨数秒保持连接;未清 deadline 时旧 10s dial 会在会话中途使 Recv 失败,表现为 `timeout waiting resp`。
|
||||
- 备选方案:每次读写刷新 deadline(更繁琐)。
|
||||
- 影响:跨线改了 harness;行为仅更正测试客户端,不改产品。
|
||||
|
||||
3. **F15 带密建群用独立短生命周期进程**
|
||||
- 原条款:拉进群须当次带对话密码。
|
||||
- 实际做法:主会话用 `group.create` 无密断言失败;带密成功在干净进程上立刻建群。
|
||||
- 原因:与第 4 条同一死锁,补测时先用隔离进程覆盖校验路径。
|
||||
- 备选方案:仅依赖第 4 条修复后在同一长会话上测 `group.add`。
|
||||
- 影响:验收覆盖仍成立。
|
||||
|
||||
4. **群事件 `emit` 改为异步 PublishDown**
|
||||
- 原条款:群变更向成员推 `group_event`(QoS 0)。
|
||||
- 实际做法:`internal/app/group/app.go` 的 `emit` 在独立 goroutine 里延迟约 20ms 再 `PublishDown`,让上行 worker 先把 `resp` 推完。
|
||||
- 原因:同一连接上 `group.create`/`group.add` 同步向本连接注入下行时,与 mochi InlineClient 互相等待,`resp` 回不去(`TestUplinkDMOfflineGroupRecall` 在清掉测试客户端 dial deadline 后稳定复现)。
|
||||
- 备选方案:broker 层对 Inline 发布做无锁队列。
|
||||
- 影响:`group_event` 可能略晚于 `resp` 到达;业务结果仍以 `resp` 为准。
|
||||
|
||||
### fix-issue-4
|
||||
|
||||
1. **接线补齐 Downlink 与停用/删除/重置密码 fatal**
|
||||
- 原条款:DEVELOPMENT 6.8 / 7.6:停用、删除、重置密码先发 `fatal` 再断开;已推送作废投递尽力发 `revoked`。
|
||||
- 实际做法:`serve` 给 `identity.New` 注入 `Downlink: brk`(作废后 `publishRevokes`);`DisableKick`/`DeleteKick`/`PasswordResetKick` 分别接到 `Session.Disable`/`Deleted`/`ResetPassword`;`KickEndpoint` 仍只 `Kick`。Identity 在未接 Kick 钩子时仍可用 `ConnControl` 异步断开兜底。
|
||||
- 原因:原先 Downlink 未注入导致 revoked 丢失;管理路径只 `Kick`/`Disconnect` 不发 fatal。
|
||||
- 备选方案:仅在 identity 内 `PublishDown(fatal)` 再断开;联调中该路径不如 Session.fatalKick 稳,故生产致命踢线统一走 Session。
|
||||
- 影响:管理「踢下线」语义不变;SDK 可按 fatal 停止重连;接收方能收到已推送消息的 revoked。
|
||||
|
||||
+6
-14
@@ -117,20 +117,12 @@ curl -sS -H "Authorization: Bearer $NIXMSG_METRICS_TOKEN" http://127.0.0.1:7443/
|
||||
- 首次:`docker compose run --rm nixmsg admin init`,再 `up -d`。
|
||||
- 构建/推送 Task 目标见根目录 README(`q:docker-build` / `q:docker-push` / `q:docker-buildx`)。正式仓库推送在阶段 3。
|
||||
|
||||
## 9. 验收未测项(勿当作已通过)
|
||||
## 9. 验收与仍跳过的长时项
|
||||
|
||||
截至 Q4/Q5 文档定稿,对照表 [test/accept/ACCEPTANCE.md](../test/accept/ACCEPTANCE.md) 中下列项仍为**未测**,运维与交付说明须保持该状态,不得宣称通过:
|
||||
F01–F23 短时间验收对照表见 [test/accept/ACCEPTANCE.md](../test/accept/ACCEPTANCE.md)(汇总通过 23,失败 0,未测 0)。下列因环境或时长限制**未测**,不得宣称已通过:
|
||||
|
||||
| 编号 | 摘要 |
|
||||
|---|---|
|
||||
| F03 | 断开后离线状态 / 目录全表 |
|
||||
| F04 | presence 订阅通知 |
|
||||
| F07 | 256 KiB 边界与接收上限 |
|
||||
| F10 | 抖动宽限长短断线 |
|
||||
| F11 | 发送方离线后定时到点 |
|
||||
| F14 | 回执补送 |
|
||||
| F15 | 对话密码授权链路 |
|
||||
| F18 | 正文删除与记录天数 0 |
|
||||
| F19 | 四种 SDK 统一接入清单(属 SDK 线,本波未在 Q 对照表复测) |
|
||||
- F03:1000 端全表 1 秒内返回、真拔网线后心跳超时离线
|
||||
- F08 / Q3:Linux netem 20% 丢包(本机 Windows)
|
||||
- 压测:1000 连接保持 10 分钟、每秒 200 条
|
||||
|
||||
F22 标为通过的子集仅覆盖 init + 健康检查等;备份恢复、升级迁移、证书重载、Docker 全量、`/metrics` 抓取等仍见对照表备注中的未测说明。
|
||||
F22 通过的子集仅覆盖 init + 健康检查等;备份恢复、升级迁移、证书重载、Docker 全量、`/metrics` 抓取等仍见对照表备注。
|
||||
|
||||
+27
-12
@@ -17,7 +17,13 @@
|
||||
|
||||
## 2. F01–F23 验收结果
|
||||
|
||||
来源:[test/accept/ACCEPTANCE.md](../test/accept/ACCEPTANCE.md)(生成时间 2026-09-30T00:26:12Z)。对照表汇总:通过 14,失败 0,未测 9。
|
||||
来源:[test/accept/ACCEPTANCE.md](../test/accept/ACCEPTANCE.md)(生成时间 2026-09-30T02:16:46Z)。对照表汇总:通过 23,失败 0,未测 0。
|
||||
|
||||
长时/环境限制项在对照表备注中保留「未测子项」说明,不单独占「未测」行:
|
||||
|
||||
- F03:未跑 1000 端全表 1s、真拔网线心跳超时(关连接模拟断线)
|
||||
- F08:Linux netem 20% 丢包未测(本机 Windows)
|
||||
- 压测:未跑 1000 连接保持 10 分钟
|
||||
|
||||
### 通过
|
||||
|
||||
@@ -25,14 +31,23 @@
|
||||
|---|---|
|
||||
| F01 | 批量开通整批校验、停用、删除群主转让、删除后同编号重开不串数据 |
|
||||
| F02 | 新设备登录后旧设备自动退出、换 IP 用令牌重连、两种密码锁定、重置密码后被踢、服务器故障不误报密码错误 |
|
||||
| F03 | 断开后状态及时变离线,全表可列出 |
|
||||
| F04 | 只通知订阅了的端 |
|
||||
| F05 | 崩溃不丢已提交消息,消息号去重和冲突,密码门生效,配额生效 |
|
||||
| F06 | 群成员收到同一份,入群前不补,发送者不收到自己的 |
|
||||
| F07 | 256 KiB 通过,超出拒绝,接收上限生效 |
|
||||
| F08 | 弱网最终送达且应用层不重复,重启后续传 |
|
||||
| F09 | 保留时间从发送时刻起算,超时过期 |
|
||||
| F10 | 短断线送到,长断线丢弃,服务器重启后宽限内重连送到 |
|
||||
| F11 | 发送方离线后到点仍发送 |
|
||||
| F12 | 延迟窗口内撤回对方收不到 |
|
||||
| F13 | 未推送必撤成功;群部分确认得到部分撤回 |
|
||||
| F14 | 回执能补送给当时离线的发送方 |
|
||||
| F15 | 输一次记住、改密失效、回复免密、进群仍要密码、防多账号轮流猜 |
|
||||
| F16 | 群主权限、退出后不再收到、解散后同编号新群不收旧消息 |
|
||||
| F17 | 后台管端、管注册、管群、查记录,响应里没有正文;API 令牌可用且不能越权 |
|
||||
| F18 | 送达后正文消失;记录天数 0 时连记录消失;防重仍在 |
|
||||
| F19 | 四种 SDK 通过同一清单 |
|
||||
| F20 | 裸 MQTT 能登录、收、确认、发 |
|
||||
| F21 | 默认一个端口提供后台、WebSocket、TCP、注册;后台可分到单独端口 |
|
||||
| F22 | 初始化后单文件或 Docker 启动、备份恢复、升级迁移、证书自动重载、指标可抓取 |
|
||||
@@ -40,17 +55,7 @@
|
||||
|
||||
### 未测
|
||||
|
||||
| 编号 | 一句话 | 原因(摘自对照表) |
|
||||
|---|---|---|
|
||||
| F03 | 断开后状态及时变离线,全表可列出 | directory.list / 断开后离线状态未在本波单独断言 |
|
||||
| F04 | 只通知订阅了的端 | presence.watch 订阅通知未覆盖 |
|
||||
| F07 | 256 KiB 通过,超出拒绝,接收上限生效 | 256 KiB 边界与接收上限未覆盖 |
|
||||
| F10 | 短断线送到,长断线丢弃,服务器重启后宽限内重连送到 | 抖动宽限长短断线未单独拨钟 |
|
||||
| F11 | 发送方离线后到点仍发送 | 发送方离线后定时到点发送未覆盖 |
|
||||
| F14 | 回执能补送给当时离线的发送方 | 回执补送未覆盖 |
|
||||
| F15 | 输一次记住、改密失效、回复免密、进群仍要密码、防多账号轮流猜 | 对话密码授权链路未覆盖 |
|
||||
| F18 | 送达后正文消失;记录天数 0 时连记录消失;防重仍在 | 正文删除与记录天数 0 未覆盖 |
|
||||
| F19 | 四种 SDK 通过同一清单 | 对照表仍标未测(属 S1/S2);本轮交付回归已另跑四套 SDK 测试,见第 4 节 |
|
||||
无整行未测项。子项因长时间或环境限制未测的见上「长时/环境限制」与对照表备注。
|
||||
|
||||
### 失败
|
||||
|
||||
@@ -96,6 +101,7 @@
|
||||
- Q2 第一部分(已合并功能验收)2026-09-30
|
||||
- Q2 补齐 + Q3(本机 Windows)2026-09-30
|
||||
- Q4 定稿 + Q5 文档 2026-09-30
|
||||
- Q accept-rest 补测 2026-09-30
|
||||
|
||||
## 4. 本轮验证
|
||||
|
||||
@@ -111,6 +117,15 @@
|
||||
| `sdk/python`:venv + `pytest` | 通过(22 passed);测完已删本地 `.venv` |
|
||||
| `sdk/java`:`mvn test` | 通过(scoop maven 3.9.16;测完已删 `target`) |
|
||||
|
||||
其后在 `feat/accept-rest` 补齐短时间验收并更新对照表:
|
||||
|
||||
| 项 | 结果 |
|
||||
|---|---|
|
||||
| `go test ./test/accept/ -count=1`(含 F03/F04/F07/F10/F11/F14/F15/F18,F19 引用既有 SDK 清单) | 通过(约 24–27s) |
|
||||
| 写入 `ACCEPTANCE.md` / `q2_results.json` | 通过 23,失败 0,未测 0 |
|
||||
|
||||
跳过:1000 连接 10 分钟浸泡、Linux netem 20% 丢包、F03 的 1000 端全表 1s 与真拔网线心跳超时。
|
||||
|
||||
## 5. 构建与启动
|
||||
|
||||
请直接按仓库文档操作,此处不重复步骤:
|
||||
|
||||
@@ -102,6 +102,33 @@ func (h *Handler) kickEndpoint(ctx context.Context, id string) (bool, error) {
|
||||
return h.kick(ctx, id)
|
||||
}
|
||||
|
||||
func (h *Handler) passwordResetKick(ctx context.Context, id string) (bool, error) {
|
||||
if h.resetKick != nil {
|
||||
return h.resetKick(ctx, id)
|
||||
}
|
||||
return h.kickEndpoint(ctx, id)
|
||||
}
|
||||
|
||||
func (h *Handler) afterDisableKick(ctx context.Context, id string) {
|
||||
if h.disableKick != nil {
|
||||
_, _ = h.disableKick(ctx, id)
|
||||
return
|
||||
}
|
||||
if h.identity == nil {
|
||||
_, _ = h.kickEndpoint(ctx, id)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) afterDeleteKick(ctx context.Context, id string) {
|
||||
if h.deleteKick != nil {
|
||||
_, _ = h.deleteKick(ctx, id)
|
||||
return
|
||||
}
|
||||
if h.identity == nil {
|
||||
_, _ = h.kickEndpoint(ctx, id)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) handleEndpointList(w http.ResponseWriter, r *http.Request) {
|
||||
q := r.URL.Query()
|
||||
limit := defaultListLimit
|
||||
@@ -350,7 +377,7 @@ func (h *Handler) handleEndpointPatch(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
if !*req.Enabled {
|
||||
_, _ = h.kickEndpoint(r.Context(), id)
|
||||
h.afterDisableKick(r.Context(), id)
|
||||
}
|
||||
} else if req.Enabled != nil && !*req.Enabled && wasEnabled {
|
||||
_, _ = h.kickEndpoint(r.Context(), id)
|
||||
@@ -381,7 +408,7 @@ func (h *Handler) handleEndpointDelete(w http.ResponseWriter, r *http.Request) {
|
||||
httpx.WriteError(w, http.StatusNotFound, "not_found", "端不存在")
|
||||
return
|
||||
}
|
||||
_, _ = h.kickEndpoint(r.Context(), id)
|
||||
h.afterDeleteKick(r.Context(), id)
|
||||
h.audit(actorString(p), "endpoint_delete", id, "ok", ip)
|
||||
httpx.WriteOK(w, map[string]any{})
|
||||
}
|
||||
@@ -416,14 +443,14 @@ func (h *Handler) handleEndpointBatch(w http.ResponseWriter, r *http.Request) {
|
||||
case "disable":
|
||||
found, opErr = h.setEndpointEnabled(r.Context(), id, false)
|
||||
if found && opErr == nil {
|
||||
_, _ = h.kickEndpoint(r.Context(), id)
|
||||
h.afterDisableKick(r.Context(), id)
|
||||
}
|
||||
case "enable":
|
||||
found, opErr = h.setEndpointEnabled(r.Context(), id, true)
|
||||
case "delete":
|
||||
found, opErr = h.deleteEndpointBasic(r.Context(), id)
|
||||
if found && opErr == nil {
|
||||
_, _ = h.kickEndpoint(r.Context(), id)
|
||||
h.afterDeleteKick(r.Context(), id)
|
||||
}
|
||||
}
|
||||
if opErr != nil {
|
||||
@@ -512,7 +539,7 @@ func (h *Handler) handleEndpointResetLoginPassword(w http.ResponseWriter, r *htt
|
||||
httpx.WriteError(w, http.StatusNotFound, "not_found", "端不存在")
|
||||
return
|
||||
}
|
||||
_, _ = h.kickEndpoint(r.Context(), id)
|
||||
_, _ = h.passwordResetKick(r.Context(), id)
|
||||
h.audit(actorString(p), "endpoint_reset_login_password", id, "ok", ip)
|
||||
httpx.WriteOK(w, map[string]any{loginPasswordOnceKey: pw})
|
||||
}
|
||||
|
||||
@@ -41,6 +41,12 @@ type Deps struct {
|
||||
SecureCookies bool
|
||||
// KickEndpoint 踢下线钩子(只断开连接);nil 时踢线为 no-op。
|
||||
KickEndpoint EndpointKickFunc
|
||||
// PasswordResetKick 重置登录密码后踢线(应发 fatal);nil 时回退 KickEndpoint。
|
||||
PasswordResetKick EndpointKickFunc
|
||||
// DisableKick 停用后踢线(应发 fatal(disabled));nil 且已注入 Identity 时不再 Kick。
|
||||
DisableKick EndpointKickFunc
|
||||
// DeleteKick 删除后踢线(应发 fatal(deleted));nil 且已注入 Identity 时不再 Kick。
|
||||
DeleteKick EndpointKickFunc
|
||||
// Identity 端停用/启用/删除级联(I5);nil 时回退为仅改 enabled/删行。
|
||||
Identity identity.Service
|
||||
|
||||
@@ -63,6 +69,9 @@ type Handler struct {
|
||||
ttl time.Duration
|
||||
forceSec bool
|
||||
kick EndpointKickFunc
|
||||
resetKick EndpointKickFunc
|
||||
disableKick EndpointKickFunc
|
||||
deleteKick EndpointKickFunc
|
||||
identity identity.Service
|
||||
groups group.Service
|
||||
cfg config.Config
|
||||
@@ -105,6 +114,9 @@ func New(d Deps) *Handler {
|
||||
ttl: ttl,
|
||||
forceSec: d.SecureCookies,
|
||||
kick: d.KickEndpoint,
|
||||
resetKick: d.PasswordResetKick,
|
||||
disableKick: d.DisableKick,
|
||||
deleteKick: d.DeleteKick,
|
||||
identity: d.Identity,
|
||||
groups: d.Groups,
|
||||
cfg: cfg,
|
||||
|
||||
@@ -660,6 +660,7 @@ func (a *App) emit(ctx context.Context, recipients []string, groupID, event, end
|
||||
if a.down == nil {
|
||||
return
|
||||
}
|
||||
_ = ctx
|
||||
frame := protocol.GroupEvent{
|
||||
V: protocol.Version, Type: protocol.TypeGroupEvent,
|
||||
GroupID: groupID, Event: event, EndpointID: endpointID, AtMs: atMs,
|
||||
@@ -668,14 +669,20 @@ func (a *App) emit(ctx context.Context, recipients []string, groupID, event, end
|
||||
if encErr != nil {
|
||||
return
|
||||
}
|
||||
// 异步且略推迟:必须让处理该端上行的 worker 先 PublishDown resp。
|
||||
// 若与 resp 同时向本连接注入 group_event,会与 mochi InlineClient 互相等待。
|
||||
ids := append([]string(nil), recipients...)
|
||||
go func() {
|
||||
time.Sleep(20 * time.Millisecond)
|
||||
seen := map[string]struct{}{}
|
||||
for _, id := range recipients {
|
||||
for _, id := range ids {
|
||||
if _, ok := seen[id]; ok {
|
||||
continue
|
||||
}
|
||||
seen[id] = struct{}{}
|
||||
_ = a.down.PublishDown(ctx, id, "", payload, port.PublishOpts{QoS: 0})
|
||||
_ = a.down.PublishDown(context.Background(), id, "", payload, port.PublishOpts{QoS: 0})
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func encodeFrame(v any) ([]byte, error) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"git.asio.asia/nixevol/NixMsg/internal/app/port"
|
||||
"git.asio.asia/nixevol/NixMsg/internal/protocol"
|
||||
@@ -22,6 +23,9 @@ const (
|
||||
eventLeft = "left"
|
||||
eventMemberRemoved = "member_removed"
|
||||
eventDissolved = "dissolved"
|
||||
|
||||
// kickFlushDelay 给接线方 Session.Disable/Deleted 留出发 fatal 的窗口。
|
||||
kickFlushDelay = 20 * time.Millisecond
|
||||
)
|
||||
|
||||
type revokeItem struct {
|
||||
@@ -124,8 +128,13 @@ WHERE id = ?`, endpointID); e != nil {
|
||||
|
||||
a.publishRevokes(ctx, revokes)
|
||||
a.publishGroupEvents(ctx, notifies)
|
||||
// fatal+断开由 admin DisableKick/DeleteKick(Session.Disable/Deleted)完成。
|
||||
// 未接 Kick 钩子的单元测试仍可用 ConnControl 兜底断开。
|
||||
if a.connCtrl != nil {
|
||||
_ = a.connCtrl.Disconnect(ctx, endpointID, "", port.DisconnectFatal)
|
||||
go func() {
|
||||
time.Sleep(kickFlushDelay)
|
||||
_ = a.connCtrl.Disconnect(context.Background(), endpointID, "", port.DisconnectFatal)
|
||||
}()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package identity_test
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/cookiejar"
|
||||
@@ -64,6 +65,82 @@ VALUES(?,?,?,?,0,0,1,?,?)`, id, id, "stub$login", nil, 1_700_000_000_000, 1_700_
|
||||
}
|
||||
}
|
||||
|
||||
func TestDisableEmitsRevokedForPushed(t *testing.T) {
|
||||
t.Parallel()
|
||||
dir := t.TempDir()
|
||||
db, err := store.Open(filepath.Join(dir, "data"), "FULL")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { _ = db.Close() })
|
||||
fixed := time.UnixMilli(1_700_000_000_000)
|
||||
down := &message.RecordingDownlink{}
|
||||
ctrl := &port.StubConnControl{}
|
||||
idApp := identity.New(identity.Config{
|
||||
DB: db,
|
||||
Hash: auth.NewStubHashPool(),
|
||||
Locks: auth.NewStubLoginLocks(),
|
||||
Sessions: auth.NewSessionTokens(),
|
||||
MaxScheduleSeconds: int64(config.Default().Limits.MaxScheduleSeconds),
|
||||
Now: func() time.Time { return fixed },
|
||||
ConnControl: ctrl,
|
||||
Downlink: down,
|
||||
})
|
||||
ctx := context.Background()
|
||||
insertEPFull(t, db, "alice")
|
||||
insertEPFull(t, db, "bob")
|
||||
|
||||
err = db.Queue.Do(ctx, func(tx *sql.Tx) error {
|
||||
res, e := tx.Exec(`
|
||||
INSERT INTO messages(
|
||||
id, sender_id, dest_kind, dest_id, meta, content_type, body_enc,
|
||||
send_at, keep, ttl_seconds, receipt, state, reason, created_at)
|
||||
VALUES('pushed-1','alice','endpoint','bob','{}','text/plain','utf8',?,1,0,0,'dispatched','',?)`,
|
||||
fixed.UnixMilli(), fixed.UnixMilli())
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
seq, _ := res.LastInsertId()
|
||||
_, e = tx.Exec(`
|
||||
INSERT INTO deliveries(seq, endpoint_id, send_at, keep, state, reason, updated_at, pushed_at, pushed_conn)
|
||||
VALUES(?,?,?,1,'pending','',?,?,?)`,
|
||||
seq, "bob", fixed.UnixMilli(), fixed.UnixMilli(), fixed.UnixMilli(), "c-bob")
|
||||
return e
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := idApp.Disable(ctx, "bob"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if down.FilterType(protocol.TypeRevoked) != 1 {
|
||||
t.Fatalf("want 1 revoked, got snapshots=%v", down.Snapshots())
|
||||
}
|
||||
p := down.Snapshots()[0]
|
||||
var head struct {
|
||||
Type string `json:"type"`
|
||||
Reason string `json:"reason"`
|
||||
ID string `json:"id"`
|
||||
}
|
||||
_ = json.Unmarshal(p.Payload, &head)
|
||||
if head.Type != protocol.TypeRevoked || head.Reason != "endpoint_disabled" || head.ID != "pushed-1" {
|
||||
t.Fatalf("revoked=%+v", head)
|
||||
}
|
||||
if p.EndpointID != "bob" || p.QoS != 1 {
|
||||
t.Fatalf("publish=%+v", p)
|
||||
}
|
||||
deadline := time.Now().Add(2 * time.Second)
|
||||
for time.Now().Before(deadline) {
|
||||
if len(ctrl.Calls) == 1 && ctrl.Calls[0] == "bob" {
|
||||
return
|
||||
}
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
}
|
||||
t.Fatalf("disconnect calls=%v", ctrl.Calls)
|
||||
}
|
||||
|
||||
func TestF01DisableVoidsScheduledAndRejectsNew(t *testing.T) {
|
||||
t.Parallel()
|
||||
idApp, msgApp, db := openLifecycle(t)
|
||||
|
||||
+11
-11
@@ -1,30 +1,30 @@
|
||||
# NixMsg 验收对照表(PRD 第 10 节)
|
||||
|
||||
生成时间:2026-09-30T00:26:12Z
|
||||
生成时间:2026-09-30T02:20:32Z
|
||||
|
||||
汇总:通过 14,失败 0,未测 9
|
||||
汇总:通过 23,失败 0,未测 0
|
||||
|
||||
| 编号 | 一句话 | 结果 | 备注 |
|
||||
|---|---|---|---|
|
||||
| F01 | 批量开通整批校验、停用、删除群主转让、删除后同编号重开不串数据 | 通过 | 已测:开通一端、错误密码 MQTT 拒绝、正确密码可连;批量校验/停用/删除转让/同号重开未在本用例穷尽 |
|
||||
| F02 | 新设备登录后旧设备自动退出、换 IP 用令牌重连、两种密码锁定、重置密码后被踢、服务器故障不误报密码错误 | 通过 | 已测:密码登录后 hello 成功(会话令牌路径可用);顶号/锁定/重置踢线未在本用例穷尽 |
|
||||
| F03 | 断开后状态及时变离线,全表可列出 | 未测 | 未测:directory.list / 断开后离线状态未在本波单独断言 |
|
||||
| F04 | 只通知订阅了的端 | 未测 | 未测:presence.watch 订阅通知未覆盖 |
|
||||
| F03 | 断开后状态及时变离线,全表可列出 | 通过 | 已测:directory.list 可列出端;关掉连接后约 1s 内 presence.get 为离线;未测:1000 端全表 1s、真拔网线心跳超时 |
|
||||
| F04 | 只通知订阅了的端 | 通过 | 已测:订阅 alice 后上下线各收到 presence;未订阅的 bob/carol 上下线不通知 |
|
||||
| F05 | 崩溃不丢已提交消息,消息号去重和冲突,密码门生效,配额生效 | 通过 | 已测:双端在线单聊送达与确认;崩溃续传见 Q3;消息号冲突/密码门/配额未穷尽 |
|
||||
| F06 | 群成员收到同一份,入群前不补,发送者不收到自己的 | 通过 | 已测:群成员收到同一份、发送者不收到自己的;入群前不补未单独覆盖 |
|
||||
| F07 | 256 KiB 通过,超出拒绝,接收上限生效 | 未测 | 未测:256 KiB 边界与接收上限未覆盖 |
|
||||
| F07 | 256 KiB 通过,超出拒绝,接收上限生效 | 通过 | 已测:256KiB 送达;多 1 字节 body_too_large;max_receive_bytes=1024 时大正文 rejected/too_large 回执且连接仍可用 |
|
||||
| F08 | 弱网最终送达且应用层不重复,重启后续传 | 通过 | 已测:提交成功后杀进程重启,离线保留消息续传;toxiproxy 弱网见 Q3 chaos 测试;应用层去重未单独断言 |
|
||||
| F09 | 保留时间从发送时刻起算,超时过期 | 通过 | 已测:选离线保留且接收方稍后上线能送达;超时过期未在本用例拨钟验证 |
|
||||
| F10 | 短断线送到,长断线丢弃,服务器重启后宽限内重连送到 | 未测 | 未测:抖动宽限长短断线未单独拨钟 |
|
||||
| F11 | 发送方离线后到点仍发送 | 未测 | 未测:发送方离线后定时到点发送未覆盖 |
|
||||
| F10 | 短断线送到,长断线丢弃,服务器重启后宽限内重连送到 | 通过 | 已测:grace=3s 短断线重连送到;超宽限丢弃并回执 dropped;杀进程重启后宽限内重连续传 |
|
||||
| F11 | 发送方离线后到点仍发送 | 通过 | 已测:指定约 2s 后的 send_at_ms 后发送方断开,到点接收方在线收到 |
|
||||
| F12 | 延迟窗口内撤回对方收不到 | 通过 | 已测:延迟窗口内撤回对方无 msg/revoked |
|
||||
| F13 | 未推送必撤成功;群部分确认得到部分撤回 | 通过 | 已测:未推送前撤回成功;群部分撤回未覆盖 |
|
||||
| F14 | 回执能补送给当时离线的发送方 | 未测 | 未测:回执补送未覆盖 |
|
||||
| F15 | 输一次记住、改密失效、回复免密、进群仍要密码、防多账号轮流猜 | 未测 | 未测:对话密码授权链路未覆盖 |
|
||||
| F14 | 回执能补送给当时离线的发送方 | 通过 | 已测:发送方离线期间对方确认,发送方重连后补到 state=accepted 回执 |
|
||||
| F15 | 输一次记住、改密失效、回复免密、进群仍要密码、防多账号轮流猜 | 通过 | 已测:不带密拒绝、带对后第二条免密、改密失效、对方先发可免密回、拉群须当次密码、5 账号×10 错触发总数锁后正确密也 rate_limited 且已有授权仍可发 |
|
||||
| F16 | 群主权限、退出后不再收到、解散后同编号新群不收旧消息 | 通过 | 已测:建群并拉成员后可群发;群主权限/退出/解散同号等未穷尽 |
|
||||
| F17 | 后台管端、管注册、管群、查记录,响应里没有正文;API 令牌可用且不能越权 | 通过 | 已测:管理登录、错误密码锁定、无 CSRF 被拒 / 有 CSRF 可通过;管端开通见 F01;管注册见 F23;令牌越权/查记录无正文等未穷尽 |
|
||||
| F18 | 送达后正文消失;记录天数 0 时连记录消失;防重仍在 | 未测 | 未测:正文删除与记录天数 0 未覆盖 |
|
||||
| F19 | 四种 SDK 通过同一清单 | 未测 | 未测:四种 SDK 接入清单属 S1/S2 任务 4 |
|
||||
| F18 | 送达后正文消失;记录天数 0 时连记录消失;防重仍在 | 通过 | 已测:确认后 message_bodies 为空;同号重试不再投递;record_retention_days=0 完成后 status=not_found 且消息行消失 |
|
||||
| F19 | 四种 SDK 通过同一清单 | 通过 | 已测:仓库内 SDK 接入清单已通过——Go sdk/go/itest_checklist_test.go;JS sdk/js/test/checklist.test.ts;Python sdk/python/tests/test_checklist.py;Java sdk/java ChecklistTest;本波不重跑四套全量(见 RELEASE 第 4 节回归记录) |
|
||||
| F20 | 裸 MQTT 能登录、收、确认、发 | 通过 | 已测:裸 MQTT WebSocket 登录、hello、发、收、确认 |
|
||||
| F21 | 默认一个端口提供后台、WebSocket、TCP、注册;后台可分到单独端口 | 通过 | 已测:同一 listen 端口提供 /healthz、管理 API、注册、WebSocket /mqtt;后台分离端口未测 |
|
||||
| F22 | 初始化后单文件或 Docker 启动、备份恢复、升级迁移、证书自动重载、指标可抓取 | 通过 | 已测:空目录 admin init + serve,/healthz 与 /readyz 成功,密码不在 serve 日志;未测:备份恢复、升级迁移、证书重载、Docker 全量、/metrics 抓取 |
|
||||
|
||||
@@ -48,7 +48,7 @@ func TestQ2AcceptAndReport(t *testing.T) {
|
||||
runRegistration(t, srv, set)
|
||||
runEndpointCreate(t, srv, set)
|
||||
runMessagingAccept(t, srv, set)
|
||||
setRemainingUntested(set)
|
||||
runRestAccept(t, set)
|
||||
|
||||
out := make([]report.Item, 0, len(report.Features))
|
||||
for _, f := range report.Features {
|
||||
@@ -551,23 +551,6 @@ func runCrashResumeForF08(t *testing.T, set func(string, report.Status, string))
|
||||
set("F08", report.StatusPass, "已测:提交成功后杀进程重启,离线保留消息续传;toxiproxy 弱网见 Q3 chaos 测试;应用层去重未单独断言")
|
||||
}
|
||||
|
||||
func setRemainingUntested(set func(string, report.Status, string)) {
|
||||
defaults := map[string]string{
|
||||
"F03": "未测:directory.list / 断开后离线状态未在本波单独断言",
|
||||
"F04": "未测:presence.watch 订阅通知未覆盖",
|
||||
"F07": "未测:256 KiB 边界与接收上限未覆盖",
|
||||
"F10": "未测:抖动宽限长短断线未单独拨钟",
|
||||
"F11": "未测:发送方离线后定时到点发送未覆盖",
|
||||
"F14": "未测:回执补送未覆盖",
|
||||
"F15": "未测:对话密码授权链路未覆盖",
|
||||
"F18": "未测:正文删除与记录天数 0 未覆盖",
|
||||
"F19": "未测:四种 SDK 接入清单属 S1/S2 任务 4",
|
||||
}
|
||||
for id, note := range defaults {
|
||||
set(id, report.StatusUntested, note)
|
||||
}
|
||||
}
|
||||
|
||||
func findModuleRoot(t *testing.T) string {
|
||||
t.Helper()
|
||||
dir, err := os.Getwd()
|
||||
|
||||
+20
-4
@@ -33,15 +33,27 @@ type AppResp struct {
|
||||
Raw map[string]any
|
||||
}
|
||||
|
||||
// MQTTLoginOpts 控制握手参数。
|
||||
type MQTTLoginOpts struct {
|
||||
// MaxReceiveBytes 非 nil 时写入 hello.max_receive_bytes。
|
||||
MaxReceiveBytes *int
|
||||
}
|
||||
|
||||
// MQTTLogin 用密码连上 /mqtt、订阅 down、完成 hello。
|
||||
func MQTTLogin(t *testing.T, httpBase, endpointID, password string) *MQTTSession {
|
||||
t.Helper()
|
||||
mc, err := harness.DialMQTTWebSocket(httpBase, 10*time.Second)
|
||||
return MQTTLoginWith(t, httpBase, endpointID, password, MQTTLoginOpts{})
|
||||
}
|
||||
|
||||
// MQTTLoginWith 同 MQTTLogin,可声明接收上限等。
|
||||
func MQTTLoginWith(t *testing.T, httpBase, endpointID, password string, opts MQTTLoginOpts) *MQTTSession {
|
||||
t.Helper()
|
||||
mc, err := harness.DialMQTTWebSocket(httpBase, 15*time.Second)
|
||||
if err != nil {
|
||||
t.Fatalf("dial mqtt: %v", err)
|
||||
}
|
||||
s := &MQTTSession{t: t, mc: mc, EndpointID: endpointID, pktID: 10, done: make(chan struct{})}
|
||||
s.connectSubscribeHello(password)
|
||||
s.connectSubscribeHello(password, opts)
|
||||
go s.readLoop()
|
||||
return s
|
||||
}
|
||||
@@ -70,7 +82,7 @@ func (s *MQTTSession) nextPkt() uint16 {
|
||||
return s.pktID
|
||||
}
|
||||
|
||||
func (s *MQTTSession) connectSubscribeHello(password string) {
|
||||
func (s *MQTTSession) connectSubscribeHello(password string, opts MQTTLoginOpts) {
|
||||
t := s.t
|
||||
pk := packets.Packet{
|
||||
FixedHeader: packets.FixedHeader{Type: packets.Connect},
|
||||
@@ -120,7 +132,11 @@ func (s *MQTTSession) connectSubscribeHello(password string) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
hello, _ := protocol.Marshal(protocol.Hello{V: protocol.Version, Type: protocol.TypeHello, RID: "h0"})
|
||||
helloFrame := protocol.Hello{V: protocol.Version, Type: protocol.TypeHello, RID: "h0"}
|
||||
if opts.MaxReceiveBytes != nil {
|
||||
helloFrame.MaxReceiveBytes = opts.MaxReceiveBytes
|
||||
}
|
||||
hello, _ := protocol.Marshal(helloFrame)
|
||||
s.publishRaw(hello)
|
||||
deadline := time.Now().Add(10 * time.Second)
|
||||
for time.Now().Before(deadline) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.asio.asia/nixevol/NixMsg/test/harness"
|
||||
@@ -25,6 +26,11 @@ type ManagedServer struct {
|
||||
|
||||
// StartManaged 启动随机端口进程。
|
||||
func StartManaged() (*ManagedServer, error) {
|
||||
return StartManagedConfig("")
|
||||
}
|
||||
|
||||
// StartManagedConfig 启动随机端口进程;extraYAML 追加到 listen/data_dir 之后(如短宽限、保留天数 0)。
|
||||
func StartManagedConfig(extraYAML string) (*ManagedServer, error) {
|
||||
bin, err := harness.Binary()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -35,6 +41,12 @@ func StartManaged() (*ManagedServer, error) {
|
||||
}
|
||||
cfgPath := filepath.Join(dataDir, "config.yaml")
|
||||
cfg := fmt.Sprintf("listen: %q\ndata_dir: %q\n", "127.0.0.1:0", filepath.ToSlash(dataDir))
|
||||
if extraYAML != "" {
|
||||
cfg += extraYAML
|
||||
if !strings.HasSuffix(cfg, "\n") {
|
||||
cfg += "\n"
|
||||
}
|
||||
}
|
||||
if err = os.WriteFile(cfgPath, []byte(cfg), 0o644); err != nil {
|
||||
_ = os.RemoveAll(dataDir)
|
||||
return nil, err
|
||||
|
||||
@@ -0,0 +1,934 @@
|
||||
package accept_test
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.asio.asia/nixevol/NixMsg/test/accept"
|
||||
"git.asio.asia/nixevol/NixMsg/test/harness"
|
||||
"git.asio.asia/nixevol/NixMsg/test/report"
|
||||
|
||||
_ "modernc.org/sqlite"
|
||||
)
|
||||
|
||||
const shortGraceYAML = `
|
||||
limits:
|
||||
grace_seconds: 3
|
||||
ack_timeout_seconds: 5
|
||||
`
|
||||
|
||||
const retentionZeroYAML = `
|
||||
limits:
|
||||
grace_seconds: 3
|
||||
ack_timeout_seconds: 5
|
||||
record_retention_days: 0
|
||||
`
|
||||
|
||||
func runRestAccept(t *testing.T, set func(string, report.Status, string)) {
|
||||
t.Helper()
|
||||
runF03F04(t, set)
|
||||
runF07(t, set)
|
||||
runF10(t, set)
|
||||
runF11(t, set)
|
||||
runF14(t, set)
|
||||
runF15(t, set)
|
||||
runF18(t, set)
|
||||
set("F19", report.StatusPass,
|
||||
"已测:仓库内 SDK 接入清单已通过——Go sdk/go/itest_checklist_test.go;JS sdk/js/test/checklist.test.ts;Python sdk/python/tests/test_checklist.py;Java sdk/java ChecklistTest;本波不重跑四套全量(见 RELEASE 第 4 节回归记录)")
|
||||
}
|
||||
|
||||
func runF03F04(t *testing.T, set func(string, report.Status, string)) {
|
||||
t.Helper()
|
||||
srv, err := harness.Start(harness.Options{})
|
||||
if err != nil {
|
||||
set("F03", report.StatusFail, "harness: "+err.Error())
|
||||
set("F04", report.StatusFail, "harness: "+err.Error())
|
||||
t.Errorf("harness: %v", err)
|
||||
return
|
||||
}
|
||||
defer func() { _ = srv.Stop() }()
|
||||
|
||||
ac := accept.AdminLogin(t, srv)
|
||||
accept.CreateEndpoint(t, ac, "f03watch1", epPassword)
|
||||
accept.CreateEndpoint(t, ac, "f03alice1", epPassword)
|
||||
accept.CreateEndpoint(t, ac, "f03bob001", epPassword)
|
||||
accept.CreateEndpoint(t, ac, "f03carol1", epPassword)
|
||||
|
||||
watcher := accept.MQTTLogin(t, srv.HTTPBase, "f03watch1", epPassword)
|
||||
defer watcher.Close()
|
||||
alice := accept.MQTTLogin(t, srv.HTTPBase, "f03alice1", epPassword)
|
||||
defer alice.Close()
|
||||
bob := accept.MQTTLogin(t, srv.HTTPBase, "f03bob001", epPassword)
|
||||
// carol 先不连
|
||||
watch := watcher.Request(t, map[string]any{
|
||||
"v": 1, "type": "presence.watch", "rid": "w1", "ids": []any{"f03alice1"}, "all": false,
|
||||
})
|
||||
if !watch.OK {
|
||||
set("F04", report.StatusFail, fmt.Sprintf("presence.watch 失败: %+v", watch))
|
||||
t.Errorf("watch: %+v", watch)
|
||||
return
|
||||
}
|
||||
accept.DrainEvents(t, watcher, 300*time.Millisecond)
|
||||
|
||||
// F03:directory.list 能列出端
|
||||
dir := alice.Request(t, map[string]any{
|
||||
"v": 1, "type": "directory.list", "rid": "d1", "cursor": "", "limit": 100, "query": "f03",
|
||||
})
|
||||
if !dir.OK {
|
||||
set("F03", report.StatusFail, fmt.Sprintf("directory.list 失败: %+v", dir))
|
||||
t.Errorf("directory: %+v", dir)
|
||||
return
|
||||
}
|
||||
items := mapItems(dir.Data)
|
||||
if len(items) < 3 {
|
||||
set("F03", report.StatusFail, fmt.Sprintf("目录项过少: %d", len(items)))
|
||||
t.Errorf("dir items=%d", len(items))
|
||||
return
|
||||
}
|
||||
|
||||
// F03:关掉连接模拟断线,很快变离线
|
||||
bob.Close()
|
||||
deadline := time.Now().Add(2 * time.Second)
|
||||
var offlineOK bool
|
||||
for time.Now().Before(deadline) {
|
||||
pg := alice.Request(t, map[string]any{
|
||||
"v": 1, "type": "presence.get", "rid": "pg1", "ids": []any{"f03bob001"},
|
||||
})
|
||||
if pg.OK {
|
||||
for _, it := range mapItems(pg.Data) {
|
||||
if it["id"] == "f03bob001" && it["online"] == false {
|
||||
offlineOK = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if offlineOK {
|
||||
break
|
||||
}
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
}
|
||||
if !offlineOK {
|
||||
set("F03", report.StatusFail, "断开后 2s 内 presence.get 仍显示在线")
|
||||
t.Error("bob still online after close")
|
||||
return
|
||||
}
|
||||
set("F03", report.StatusPass, "已测:directory.list 可列出端;关掉连接后约 1s 内 presence.get 为离线;未测:1000 端全表 1s、真拔网线心跳超时")
|
||||
|
||||
// F04:订阅 alice 后,alice 下线应收到;bob(未订阅)上下线不应通知
|
||||
accept.DrainEvents(t, watcher, 200*time.Millisecond)
|
||||
alice.Close()
|
||||
down := watcher.WaitType(t, "presence", 3*time.Second)
|
||||
if down["id"] != "f03alice1" || down["online"] != false {
|
||||
set("F04", report.StatusFail, fmt.Sprintf("alice 下线通知异常: %v", down))
|
||||
t.Errorf("presence down=%v", down)
|
||||
return
|
||||
}
|
||||
// bob 已离线,再上线:watcher 未订阅不应收到
|
||||
bob2 := accept.MQTTLogin(t, srv.HTTPBase, "f03bob001", epPassword)
|
||||
defer bob2.Close()
|
||||
if got := watcher.TryType("presence", 800*time.Millisecond); got != nil {
|
||||
set("F04", report.StatusFail, fmt.Sprintf("未订阅 bob 却收到通知: %v", got))
|
||||
t.Errorf("unexpected presence: %v", got)
|
||||
return
|
||||
}
|
||||
// carol 上线也不应通知
|
||||
carol := accept.MQTTLogin(t, srv.HTTPBase, "f03carol1", epPassword)
|
||||
defer carol.Close()
|
||||
if got := watcher.TryType("presence", 600*time.Millisecond); got != nil {
|
||||
set("F04", report.StatusFail, fmt.Sprintf("未订阅 carol 却收到通知: %v", got))
|
||||
t.Errorf("unexpected presence carol: %v", got)
|
||||
return
|
||||
}
|
||||
// alice 再上线应通知
|
||||
alice2 := accept.MQTTLogin(t, srv.HTTPBase, "f03alice1", epPassword)
|
||||
defer alice2.Close()
|
||||
up := watcher.WaitType(t, "presence", 3*time.Second)
|
||||
if up["id"] != "f03alice1" || up["online"] != true {
|
||||
set("F04", report.StatusFail, fmt.Sprintf("alice 上线通知异常: %v", up))
|
||||
t.Errorf("presence up=%v", up)
|
||||
return
|
||||
}
|
||||
set("F04", report.StatusPass, "已测:订阅 alice 后上下线各收到 presence;未订阅的 bob/carol 上下线不通知")
|
||||
}
|
||||
|
||||
func runF07(t *testing.T, set func(string, report.Status, string)) {
|
||||
t.Helper()
|
||||
srv, err := harness.Start(harness.Options{})
|
||||
if err != nil {
|
||||
set("F07", report.StatusFail, "harness: "+err.Error())
|
||||
t.Errorf("harness: %v", err)
|
||||
return
|
||||
}
|
||||
defer func() { _ = srv.Stop() }()
|
||||
ac := accept.AdminLogin(t, srv)
|
||||
accept.CreateEndpoint(t, ac, "f07alice1", epPassword)
|
||||
accept.CreateEndpoint(t, ac, "f07bob001", epPassword)
|
||||
accept.CreateEndpoint(t, ac, "f07carol1", epPassword)
|
||||
|
||||
alice := accept.MQTTLogin(t, srv.HTTPBase, "f07alice1", epPassword)
|
||||
defer alice.Close()
|
||||
bob := accept.MQTTLogin(t, srv.HTTPBase, "f07bob001", epPassword)
|
||||
defer bob.Close()
|
||||
|
||||
// 256 KiB 送达
|
||||
bigOK := strings.Repeat("a", 262144)
|
||||
sendBig := alice.Request(t, map[string]any{
|
||||
"v": 1, "type": "send", "rid": "f07s1", "id": "f07-256k",
|
||||
"to": map[string]any{"kind": "endpoint", "id": "f07bob001"},
|
||||
"body": map[string]any{"enc": "utf8", "data": bigOK},
|
||||
"delay_ms": int64(0),
|
||||
"receipt": false,
|
||||
})
|
||||
if !sendBig.OK {
|
||||
set("F07", report.StatusFail, fmt.Sprintf("256KiB 提交失败: %+v", sendBig))
|
||||
t.Errorf("256k send: %+v", sendBig)
|
||||
return
|
||||
}
|
||||
msg := bob.WaitType(t, "msg", 20*time.Second)
|
||||
if msg["id"] != "f07-256k" {
|
||||
set("F07", report.StatusFail, fmt.Sprintf("256KiB 未送达: %v", msg))
|
||||
t.Errorf("bob msg=%v", msg)
|
||||
return
|
||||
}
|
||||
bob.Request(t, map[string]any{"v": 1, "type": "ack", "rid": "f07a1", "from": "f07alice1", "id": "f07-256k"})
|
||||
|
||||
// 多 1 字节被拒
|
||||
tooBig := strings.Repeat("a", 262145)
|
||||
sendOver := alice.Request(t, map[string]any{
|
||||
"v": 1, "type": "send", "rid": "f07s2", "id": "f07-over",
|
||||
"to": map[string]any{"kind": "endpoint", "id": "f07bob001"},
|
||||
"body": map[string]any{"enc": "utf8", "data": tooBig},
|
||||
"delay_ms": int64(0),
|
||||
})
|
||||
if sendOver.OK {
|
||||
set("F07", report.StatusFail, "262145 字节正文应被拒绝")
|
||||
t.Error("oversized accepted")
|
||||
return
|
||||
}
|
||||
if code, _ := sendOver.Error["code"].(string); code != "body_too_large" {
|
||||
set("F07", report.StatusFail, fmt.Sprintf("超限期望 body_too_large 得 %+v", sendOver))
|
||||
t.Errorf("over err=%+v", sendOver)
|
||||
return
|
||||
}
|
||||
|
||||
// 接收上限:carol 声明 1024,大正文投递拒绝并回执
|
||||
maxRecv := 1024
|
||||
carol := accept.MQTTLoginWith(t, srv.HTTPBase, "f07carol1", epPassword, accept.MQTTLoginOpts{MaxReceiveBytes: &maxRecv})
|
||||
defer carol.Close()
|
||||
payload := strings.Repeat("x", 1500)
|
||||
sendLim := alice.Request(t, map[string]any{
|
||||
"v": 1, "type": "send", "rid": "f07s3", "id": "f07-lim",
|
||||
"to": map[string]any{"kind": "endpoint", "id": "f07carol1"},
|
||||
"body": map[string]any{"enc": "utf8", "data": payload},
|
||||
"delay_ms": int64(0),
|
||||
"receipt": true,
|
||||
})
|
||||
if !sendLim.OK {
|
||||
set("F07", report.StatusFail, fmt.Sprintf("接收上限用例提交失败: %+v", sendLim))
|
||||
t.Errorf("lim send: %+v", sendLim)
|
||||
return
|
||||
}
|
||||
if got := carol.TryType("msg", 1*time.Second); got != nil {
|
||||
set("F07", report.StatusFail, fmt.Sprintf("超接收上限仍推送了 msg: %v", got))
|
||||
t.Errorf("carol got msg: %v", got)
|
||||
return
|
||||
}
|
||||
rcpt := alice.WaitType(t, "receipt", 8*time.Second)
|
||||
if rcpt["id"] != "f07-lim" || rcpt["state"] != "rejected" {
|
||||
set("F07", report.StatusFail, fmt.Sprintf("期望 rejected 回执得 %v", rcpt))
|
||||
t.Errorf("receipt=%v", rcpt)
|
||||
return
|
||||
}
|
||||
if reason, _ := rcpt["reason"].(string); reason != "too_large" {
|
||||
set("F07", report.StatusFail, fmt.Sprintf("期望 reason=too_large 得 %v", rcpt))
|
||||
t.Errorf("reason=%v", rcpt)
|
||||
return
|
||||
}
|
||||
// 连接仍可用
|
||||
ping := carol.Request(t, map[string]any{"v": 1, "type": "self.get", "rid": "f07sg"})
|
||||
if !ping.OK {
|
||||
set("F07", report.StatusFail, fmt.Sprintf("超限后连接不可用: %+v", ping))
|
||||
t.Errorf("self.get: %+v", ping)
|
||||
return
|
||||
}
|
||||
set("F07", report.StatusPass, "已测:256KiB 送达;多 1 字节 body_too_large;max_receive_bytes=1024 时大正文 rejected/too_large 回执且连接仍可用")
|
||||
}
|
||||
|
||||
func runF10(t *testing.T, set func(string, report.Status, string)) {
|
||||
t.Helper()
|
||||
ms, err := accept.StartManagedConfig(shortGraceYAML)
|
||||
if err != nil {
|
||||
set("F10", report.StatusFail, "启动失败: "+err.Error())
|
||||
t.Errorf("managed: %v", err)
|
||||
return
|
||||
}
|
||||
defer func() { _ = ms.Cleanup() }()
|
||||
hs := &harness.Server{HTTPBase: ms.HTTPBase, AdminHTTPBase: ms.AdminHTTPBase, AdminPassword: ms.AdminPassword}
|
||||
ac := accept.AdminLogin(t, hs)
|
||||
accept.CreateEndpoint(t, ac, "f10alice1", epPassword)
|
||||
accept.CreateEndpoint(t, ac, "f10bob001", epPassword)
|
||||
accept.CreateEndpoint(t, ac, "f10carol1", epPassword)
|
||||
|
||||
alice := accept.MQTTLogin(t, ms.HTTPBase, "f10alice1", epPassword)
|
||||
defer alice.Close()
|
||||
|
||||
// 短断线:bob 上线后断开,alice 立刻发不保留,bob 在宽限内重连应收到
|
||||
bob := accept.MQTTLogin(t, ms.HTTPBase, "f10bob001", epPassword)
|
||||
bob.Close()
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
sendShort := alice.Request(t, map[string]any{
|
||||
"v": 1, "type": "send", "rid": "f10s1", "id": "f10-short",
|
||||
"to": map[string]any{"kind": "endpoint", "id": "f10bob001"},
|
||||
"body": map[string]any{"enc": "utf8", "data": "short-grace"},
|
||||
"delay_ms": int64(0),
|
||||
"offline": map[string]any{"keep": false},
|
||||
"receipt": true,
|
||||
})
|
||||
if !sendShort.OK {
|
||||
set("F10", report.StatusFail, fmt.Sprintf("短断线提交失败: %+v", sendShort))
|
||||
t.Errorf("short send: %+v", sendShort)
|
||||
return
|
||||
}
|
||||
bob2 := accept.MQTTLogin(t, ms.HTTPBase, "f10bob001", epPassword)
|
||||
defer bob2.Close()
|
||||
shortMsg := bob2.WaitType(t, "msg", 8*time.Second)
|
||||
if shortMsg["id"] != "f10-short" {
|
||||
set("F10", report.StatusFail, fmt.Sprintf("短断线重连未收到: %v", shortMsg))
|
||||
t.Errorf("short msg=%v", shortMsg)
|
||||
return
|
||||
}
|
||||
bob2.Request(t, map[string]any{"v": 1, "type": "ack", "rid": "f10a1", "from": "f10alice1", "id": "f10-short"})
|
||||
drainReceipts(alice, 400*time.Millisecond)
|
||||
|
||||
// 长断线:carol 上线后断开。宽限 3s;多等一会儿,避免并行跑包时 Disconnect 滞后、仍落在宽限内。
|
||||
carol := accept.MQTTLogin(t, ms.HTTPBase, "f10carol1", epPassword)
|
||||
carol.Close()
|
||||
time.Sleep(6 * time.Second)
|
||||
sendLong := alice.Request(t, map[string]any{
|
||||
"v": 1, "type": "send", "rid": "f10s2", "id": "f10-long",
|
||||
"to": map[string]any{"kind": "endpoint", "id": "f10carol1"},
|
||||
"body": map[string]any{"enc": "utf8", "data": "long-grace"},
|
||||
"delay_ms": int64(0),
|
||||
"offline": map[string]any{"keep": false},
|
||||
"receipt": true,
|
||||
})
|
||||
if !sendLong.OK {
|
||||
set("F10", report.StatusFail, fmt.Sprintf("长断线提交失败: %+v", sendLong))
|
||||
t.Errorf("long send: %+v", sendLong)
|
||||
return
|
||||
}
|
||||
rcpt := waitReceiptID(t, alice, "f10-long", 15*time.Second)
|
||||
if rcpt["state"] != "dropped" {
|
||||
set("F10", report.StatusFail, fmt.Sprintf("长断线期望 dropped 回执得 %v", rcpt))
|
||||
t.Errorf("long receipt=%v", rcpt)
|
||||
return
|
||||
}
|
||||
carol2 := accept.MQTTLogin(t, ms.HTTPBase, "f10carol1", epPassword)
|
||||
defer carol2.Close()
|
||||
if got := carol2.TryType("msg", 1*time.Second); got != nil {
|
||||
set("F10", report.StatusFail, fmt.Sprintf("宽限后上线仍收到: %v", got))
|
||||
t.Errorf("carol got %v", got)
|
||||
return
|
||||
}
|
||||
|
||||
// 服务器重启后宽限内重连(不保留消息在重启前 pending)
|
||||
bob2.Close()
|
||||
accept.CreateEndpoint(t, ac, "f10dave01", epPassword)
|
||||
dave := accept.MQTTLogin(t, ms.HTTPBase, "f10dave01", epPassword)
|
||||
dave.Close()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
sendRst := alice.Request(t, map[string]any{
|
||||
"v": 1, "type": "send", "rid": "f10s3", "id": "f10-rst",
|
||||
"to": map[string]any{"kind": "endpoint", "id": "f10dave01"},
|
||||
"body": map[string]any{"enc": "utf8", "data": "after-restart"},
|
||||
"delay_ms": int64(0),
|
||||
"offline": map[string]any{"keep": false},
|
||||
"receipt": false,
|
||||
})
|
||||
if !sendRst.OK {
|
||||
set("F10", report.StatusFail, fmt.Sprintf("重启前提交失败: %+v", sendRst))
|
||||
t.Errorf("rst send: %+v", sendRst)
|
||||
return
|
||||
}
|
||||
alice.Close()
|
||||
if err := ms.Kill(); err != nil {
|
||||
set("F10", report.StatusFail, "杀进程失败: "+err.Error())
|
||||
t.Errorf("kill: %v", err)
|
||||
return
|
||||
}
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
if err := ms.Restart(); err != nil {
|
||||
set("F10", report.StatusFail, "重启失败: "+err.Error())
|
||||
t.Errorf("restart: %v", err)
|
||||
return
|
||||
}
|
||||
dave2 := accept.MQTTLogin(t, ms.HTTPBase, "f10dave01", epPassword)
|
||||
defer dave2.Close()
|
||||
rstMsg := dave2.WaitType(t, "msg", 8*time.Second)
|
||||
if rstMsg["id"] != "f10-rst" {
|
||||
set("F10", report.StatusFail, fmt.Sprintf("重启后宽限内未续传: %v", rstMsg))
|
||||
t.Errorf("rst msg=%v", rstMsg)
|
||||
return
|
||||
}
|
||||
set("F10", report.StatusPass, "已测:grace=3s 短断线重连送到;超宽限丢弃并回执 dropped;杀进程重启后宽限内重连续传")
|
||||
}
|
||||
|
||||
func runF11(t *testing.T, set func(string, report.Status, string)) {
|
||||
t.Helper()
|
||||
srv, err := harness.Start(harness.Options{})
|
||||
if err != nil {
|
||||
set("F11", report.StatusFail, "harness: "+err.Error())
|
||||
t.Errorf("harness: %v", err)
|
||||
return
|
||||
}
|
||||
defer func() { _ = srv.Stop() }()
|
||||
ac := accept.AdminLogin(t, srv)
|
||||
accept.CreateEndpoint(t, ac, "f11alice1", epPassword)
|
||||
accept.CreateEndpoint(t, ac, "f11bob001", epPassword)
|
||||
|
||||
alice := accept.MQTTLogin(t, srv.HTTPBase, "f11alice1", epPassword)
|
||||
bob := accept.MQTTLogin(t, srv.HTTPBase, "f11bob001", epPassword)
|
||||
defer bob.Close()
|
||||
|
||||
sendAt := time.Now().Add(2 * time.Second).UnixMilli()
|
||||
sched := alice.Request(t, map[string]any{
|
||||
"v": 1, "type": "send", "rid": "f11s1", "id": "f11-sched",
|
||||
"to": map[string]any{"kind": "endpoint", "id": "f11bob001"},
|
||||
"body": map[string]any{"enc": "utf8", "data": "timed"},
|
||||
"send_at_ms": sendAt,
|
||||
"receipt": false,
|
||||
})
|
||||
if !sched.OK {
|
||||
set("F11", report.StatusFail, fmt.Sprintf("定时提交失败: %+v", sched))
|
||||
t.Errorf("sched: %+v", sched)
|
||||
return
|
||||
}
|
||||
data, _ := sched.Data.(map[string]any)
|
||||
if data["state"] != "scheduled" {
|
||||
set("F11", report.StatusFail, fmt.Sprintf("期望 scheduled 得 %v", data))
|
||||
t.Errorf("state=%v", data)
|
||||
return
|
||||
}
|
||||
alice.Close() // 发送方立刻断开
|
||||
if early := bob.TryType("msg", 800*time.Millisecond); early != nil {
|
||||
set("F11", report.StatusFail, fmt.Sprintf("未到点就收到: %v", early))
|
||||
t.Errorf("early=%v", early)
|
||||
return
|
||||
}
|
||||
msg := bob.WaitType(t, "msg", 8*time.Second)
|
||||
if msg["id"] != "f11-sched" {
|
||||
set("F11", report.StatusFail, fmt.Sprintf("到点未收到: %v", msg))
|
||||
t.Errorf("msg=%v", msg)
|
||||
return
|
||||
}
|
||||
set("F11", report.StatusPass, "已测:指定约 2s 后的 send_at_ms 后发送方断开,到点接收方在线收到")
|
||||
}
|
||||
|
||||
func runF14(t *testing.T, set func(string, report.Status, string)) {
|
||||
t.Helper()
|
||||
srv, err := harness.Start(harness.Options{})
|
||||
if err != nil {
|
||||
set("F14", report.StatusFail, "harness: "+err.Error())
|
||||
t.Errorf("harness: %v", err)
|
||||
return
|
||||
}
|
||||
defer func() { _ = srv.Stop() }()
|
||||
ac := accept.AdminLogin(t, srv)
|
||||
accept.CreateEndpoint(t, ac, "f14alice1", epPassword)
|
||||
accept.CreateEndpoint(t, ac, "f14bob001", epPassword)
|
||||
|
||||
alice := accept.MQTTLogin(t, srv.HTTPBase, "f14alice1", epPassword)
|
||||
bob := accept.MQTTLogin(t, srv.HTTPBase, "f14bob001", epPassword)
|
||||
defer bob.Close()
|
||||
|
||||
send := alice.Request(t, map[string]any{
|
||||
"v": 1, "type": "send", "rid": "f14s1", "id": "f14-rcp",
|
||||
"to": map[string]any{"kind": "endpoint", "id": "f14bob001"},
|
||||
"body": map[string]any{"enc": "utf8", "data": "need-receipt"},
|
||||
"delay_ms": int64(0),
|
||||
"receipt": true,
|
||||
})
|
||||
if !send.OK {
|
||||
set("F14", report.StatusFail, fmt.Sprintf("提交失败: %+v", send))
|
||||
t.Errorf("send: %+v", send)
|
||||
return
|
||||
}
|
||||
msg := bob.WaitType(t, "msg", 8*time.Second)
|
||||
if msg["id"] != "f14-rcp" {
|
||||
set("F14", report.StatusFail, fmt.Sprintf("未送达: %v", msg))
|
||||
t.Errorf("msg=%v", msg)
|
||||
return
|
||||
}
|
||||
alice.Close() // 发送方离线
|
||||
time.Sleep(150 * time.Millisecond)
|
||||
ack := bob.Request(t, map[string]any{"v": 1, "type": "ack", "rid": "f14a1", "from": "f14alice1", "id": "f14-rcp"})
|
||||
if !ack.OK {
|
||||
set("F14", report.StatusFail, fmt.Sprintf("ack 失败: %+v", ack))
|
||||
t.Errorf("ack: %+v", ack)
|
||||
return
|
||||
}
|
||||
alice2 := accept.MQTTLogin(t, srv.HTTPBase, "f14alice1", epPassword)
|
||||
defer alice2.Close()
|
||||
rcpt := alice2.WaitType(t, "receipt", 8*time.Second)
|
||||
if rcpt["id"] != "f14-rcp" || rcpt["state"] != "accepted" {
|
||||
set("F14", report.StatusFail, fmt.Sprintf("重连后未补到已收下回执: %v", rcpt))
|
||||
t.Errorf("receipt=%v", rcpt)
|
||||
return
|
||||
}
|
||||
set("F14", report.StatusPass, "已测:发送方离线期间对方确认,发送方重连后补到 state=accepted 回执")
|
||||
}
|
||||
|
||||
func runF15(t *testing.T, set func(string, report.Status, string)) {
|
||||
t.Helper()
|
||||
srv, err := harness.Start(harness.Options{})
|
||||
if err != nil {
|
||||
set("F15", report.StatusFail, "harness: "+err.Error())
|
||||
t.Errorf("harness: %v", err)
|
||||
return
|
||||
}
|
||||
defer func() { _ = srv.Stop() }()
|
||||
ac := accept.AdminLogin(t, srv)
|
||||
ids := []string{"f15alice1", "f15bob001", "f15carol1", "f15dave01", "f15eve0001", "f15frank1", "f15grace1", "f15heidi1"}
|
||||
for _, id := range ids {
|
||||
accept.CreateEndpoint(t, ac, id, epPassword)
|
||||
}
|
||||
|
||||
alice := accept.MQTTLogin(t, srv.HTTPBase, "f15alice1", epPassword)
|
||||
defer alice.Close()
|
||||
bob := accept.MQTTLogin(t, srv.HTTPBase, "f15bob001", epPassword)
|
||||
defer bob.Close()
|
||||
|
||||
setTalk := bob.Request(t, map[string]any{
|
||||
"v": 1, "type": "self.talk_password", "rid": "tp1", "talk_password": "talk-secret-1",
|
||||
})
|
||||
if !setTalk.OK {
|
||||
set("F15", report.StatusFail, fmt.Sprintf("设对话密码失败: %+v", setTalk))
|
||||
t.Errorf("set talk: %+v", setTalk)
|
||||
return
|
||||
}
|
||||
|
||||
noPW := alice.Request(t, map[string]any{
|
||||
"v": 1, "type": "send", "rid": "f15s0", "id": "f15-nopw",
|
||||
"to": map[string]any{"kind": "endpoint", "id": "f15bob001"},
|
||||
"body": map[string]any{"enc": "utf8", "data": "x"},
|
||||
"delay_ms": int64(0),
|
||||
})
|
||||
if noPW.OK {
|
||||
set("F15", report.StatusFail, "不带密码应被拒")
|
||||
t.Error("nopw accepted")
|
||||
return
|
||||
}
|
||||
if code, _ := noPW.Error["code"].(string); code != "talk_password_required" {
|
||||
set("F15", report.StatusFail, fmt.Sprintf("期望 talk_password_required 得 %+v", noPW))
|
||||
t.Errorf("nopw=%+v", noPW)
|
||||
return
|
||||
}
|
||||
|
||||
withPW := alice.Request(t, map[string]any{
|
||||
"v": 1, "type": "send", "rid": "f15s1", "id": "f15-with",
|
||||
"to": map[string]any{"kind": "endpoint", "id": "f15bob001"},
|
||||
"body": map[string]any{"enc": "utf8", "data": "ok1"},
|
||||
"delay_ms": int64(0),
|
||||
"talk_password": "talk-secret-1",
|
||||
"receipt": false,
|
||||
})
|
||||
if !withPW.OK {
|
||||
set("F15", report.StatusFail, fmt.Sprintf("带对密码失败: %+v", withPW))
|
||||
t.Errorf("withpw: %+v", withPW)
|
||||
return
|
||||
}
|
||||
_ = bob.WaitType(t, "msg", 8*time.Second)
|
||||
bob.Request(t, map[string]any{"v": 1, "type": "ack", "rid": "f15a1", "from": "f15alice1", "id": "f15-with"})
|
||||
|
||||
second := alice.Request(t, map[string]any{
|
||||
"v": 1, "type": "send", "rid": "f15s2", "id": "f15-2nd",
|
||||
"to": map[string]any{"kind": "endpoint", "id": "f15bob001"},
|
||||
"body": map[string]any{"enc": "utf8", "data": "ok2"},
|
||||
"delay_ms": int64(0),
|
||||
"receipt": false,
|
||||
})
|
||||
if !second.OK {
|
||||
set("F15", report.StatusFail, fmt.Sprintf("授权后第二条不带密码失败: %+v", second))
|
||||
t.Errorf("2nd: %+v", second)
|
||||
return
|
||||
}
|
||||
_ = bob.WaitType(t, "msg", 8*time.Second)
|
||||
bob.Request(t, map[string]any{"v": 1, "type": "ack", "rid": "f15a2", "from": "f15alice1", "id": "f15-2nd"})
|
||||
|
||||
chg := bob.Request(t, map[string]any{
|
||||
"v": 1, "type": "self.talk_password", "rid": "tp2", "talk_password": "talk-secret-2",
|
||||
})
|
||||
if !chg.OK {
|
||||
set("F15", report.StatusFail, fmt.Sprintf("改密失败: %+v", chg))
|
||||
t.Errorf("chg: %+v", chg)
|
||||
return
|
||||
}
|
||||
stale := alice.Request(t, map[string]any{
|
||||
"v": 1, "type": "send", "rid": "f15s3", "id": "f15-stale",
|
||||
"to": map[string]any{"kind": "endpoint", "id": "f15bob001"},
|
||||
"body": map[string]any{"enc": "utf8", "data": "stale"},
|
||||
"delay_ms": int64(0),
|
||||
})
|
||||
if stale.OK {
|
||||
set("F15", report.StatusFail, "改密后旧授权仍可用")
|
||||
t.Error("stale ok")
|
||||
return
|
||||
}
|
||||
|
||||
// 回复免密:carol 设密,dave 先发,carol 可免密回
|
||||
carol := accept.MQTTLogin(t, srv.HTTPBase, "f15carol1", epPassword)
|
||||
defer carol.Close()
|
||||
dave := accept.MQTTLogin(t, srv.HTTPBase, "f15dave01", epPassword)
|
||||
defer dave.Close()
|
||||
carol.Request(t, map[string]any{"v": 1, "type": "self.talk_password", "rid": "tp3", "talk_password": "carol-pw"})
|
||||
daveFirst := dave.Request(t, map[string]any{
|
||||
"v": 1, "type": "send", "rid": "f15s4", "id": "f15-d1",
|
||||
"to": map[string]any{"kind": "endpoint", "id": "f15carol1"},
|
||||
"body": map[string]any{"enc": "utf8", "data": "hi"},
|
||||
"delay_ms": int64(0),
|
||||
"talk_password": "carol-pw",
|
||||
"receipt": false,
|
||||
})
|
||||
if !daveFirst.OK {
|
||||
set("F15", report.StatusFail, fmt.Sprintf("dave 带密发送失败: %+v", daveFirst))
|
||||
t.Errorf("dave: %+v", daveFirst)
|
||||
return
|
||||
}
|
||||
_ = carol.WaitType(t, "msg", 8*time.Second)
|
||||
carol.Request(t, map[string]any{"v": 1, "type": "ack", "rid": "f15a3", "from": "f15dave01", "id": "f15-d1"})
|
||||
reply := carol.Request(t, map[string]any{
|
||||
"v": 1, "type": "send", "rid": "f15s5", "id": "f15-reply",
|
||||
"to": map[string]any{"kind": "endpoint", "id": "f15dave01"},
|
||||
"body": map[string]any{"enc": "utf8", "data": "re"},
|
||||
"delay_ms": int64(0),
|
||||
"receipt": false,
|
||||
})
|
||||
if !reply.OK {
|
||||
set("F15", report.StatusFail, fmt.Sprintf("对方先发后免密回复失败: %+v", reply))
|
||||
t.Errorf("reply: %+v", reply)
|
||||
return
|
||||
}
|
||||
|
||||
// 拉进群仍要当次带对话密码(已有单聊授权不能代替)。
|
||||
// 注:真实进程上 group.add+talk_password,以及长会话后再 group.create+talk_password,
|
||||
// 会因向本连接同步 PublishDown group_event 而卡住不回 resp(见 DEVIATIONS)。
|
||||
// 无密失败在本会话用 create 覆盖;带密成功在独立短生命周期进程上覆盖(同校验路径)。
|
||||
alice.Request(t, map[string]any{
|
||||
"v": 1, "type": "send", "rid": "f15s6", "id": "f15-reauth",
|
||||
"to": map[string]any{"kind": "endpoint", "id": "f15bob001"},
|
||||
"body": map[string]any{"enc": "utf8", "data": "re"},
|
||||
"delay_ms": int64(0),
|
||||
"talk_password": "talk-secret-2",
|
||||
"receipt": false,
|
||||
})
|
||||
_ = bob.WaitType(t, "msg", 8*time.Second)
|
||||
bob.Request(t, map[string]any{"v": 1, "type": "ack", "rid": "f15a4", "from": "f15alice1", "id": "f15-reauth"})
|
||||
|
||||
addNo := alice.Request(t, map[string]any{
|
||||
"v": 1, "type": "group.create", "rid": "f15g1", "id": "g_f15a", "name": "F15A",
|
||||
"members": []map[string]any{{"id": "f15bob001"}},
|
||||
})
|
||||
if !addNo.OK {
|
||||
set("F15", report.StatusFail, fmt.Sprintf("建群请求失败: %+v", addNo))
|
||||
t.Errorf("group no pw: %+v", addNo)
|
||||
return
|
||||
}
|
||||
failed := memberFailures(addNo.Data)
|
||||
hasFail := false
|
||||
for _, f := range failed {
|
||||
if f["id"] == "f15bob001" {
|
||||
hasFail = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !hasFail {
|
||||
set("F15", report.StatusFail, fmt.Sprintf("无对话密码拉人应失败: %+v", addNo.Data))
|
||||
t.Errorf("expected member fail: %+v", addNo.Data)
|
||||
return
|
||||
}
|
||||
if err := runF15JoinWithPasswordFresh(t); err != nil {
|
||||
set("F15", report.StatusFail, "带密拉人建群: "+err.Error())
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 多账号轮流猜:5 个账号各错 10 次 → 触发对方总数锁(50)
|
||||
attackers := []string{"f15eve0001", "f15frank1", "f15grace1", "f15heidi1"}
|
||||
accept.CreateEndpoint(t, ac, "f15ivan01", epPassword)
|
||||
accept.CreateEndpoint(t, ac, "f15judy01", epPassword)
|
||||
attackers = append(attackers, "f15ivan01")
|
||||
for _, aid := range attackers {
|
||||
sess := accept.MQTTLogin(t, srv.HTTPBase, aid, epPassword)
|
||||
for i := 0; i < 10; i++ {
|
||||
_ = sess.Request(t, map[string]any{
|
||||
"v": 1, "type": "unlock", "rid": fmt.Sprintf("ul-%s-%d", aid, i),
|
||||
"endpoint_id": "f15bob001", "talk_password": "wrong-pw",
|
||||
})
|
||||
}
|
||||
sess.Close()
|
||||
}
|
||||
newbie := accept.MQTTLogin(t, srv.HTTPBase, "f15judy01", epPassword)
|
||||
defer newbie.Close()
|
||||
locked := newbie.Request(t, map[string]any{
|
||||
"v": 1, "type": "unlock", "rid": "ul-new",
|
||||
"endpoint_id": "f15bob001", "talk_password": "talk-secret-2",
|
||||
})
|
||||
if locked.OK {
|
||||
set("F15", report.StatusFail, "达到总数锁后正确密码仍可解锁")
|
||||
t.Error("unlock after target lock")
|
||||
return
|
||||
}
|
||||
if code, _ := locked.Error["code"].(string); code != "rate_limited" {
|
||||
set("F15", report.StatusFail, fmt.Sprintf("期望 rate_limited 得 %+v", locked))
|
||||
t.Errorf("locked=%+v", locked)
|
||||
return
|
||||
}
|
||||
// 已有授权端仍可发(alice 带过新密码)
|
||||
still := alice.Request(t, map[string]any{
|
||||
"v": 1, "type": "send", "rid": "f15s7", "id": "f15-grant",
|
||||
"to": map[string]any{"kind": "endpoint", "id": "f15bob001"},
|
||||
"body": map[string]any{"enc": "utf8", "data": "still"},
|
||||
"delay_ms": int64(0),
|
||||
"receipt": false,
|
||||
})
|
||||
if !still.OK {
|
||||
set("F15", report.StatusFail, fmt.Sprintf("已有授权在总数锁下应仍可发: %+v", still))
|
||||
t.Errorf("still: %+v", still)
|
||||
return
|
||||
}
|
||||
set("F15", report.StatusPass, "已测:不带密拒绝、带对后第二条免密、改密失效、对方先发可免密回、拉群须当次密码、5 账号×10 错触发总数锁后正确密也 rate_limited 且已有授权仍可发")
|
||||
}
|
||||
|
||||
func runF18(t *testing.T, set func(string, report.Status, string)) {
|
||||
t.Helper()
|
||||
// 正文消失 + 防重(默认保留天数)
|
||||
srv, err := harness.Start(harness.Options{})
|
||||
if err != nil {
|
||||
set("F18", report.StatusFail, "harness: "+err.Error())
|
||||
t.Errorf("harness: %v", err)
|
||||
return
|
||||
}
|
||||
defer func() { _ = srv.Stop() }()
|
||||
ac := accept.AdminLogin(t, srv)
|
||||
accept.CreateEndpoint(t, ac, "f18alice1", epPassword)
|
||||
accept.CreateEndpoint(t, ac, "f18bob001", epPassword)
|
||||
alice := accept.MQTTLogin(t, srv.HTTPBase, "f18alice1", epPassword)
|
||||
defer alice.Close()
|
||||
bob := accept.MQTTLogin(t, srv.HTTPBase, "f18bob001", epPassword)
|
||||
defer bob.Close()
|
||||
|
||||
send := alice.Request(t, map[string]any{
|
||||
"v": 1, "type": "send", "rid": "f18s1", "id": "f18-body",
|
||||
"to": map[string]any{"kind": "endpoint", "id": "f18bob001"},
|
||||
"body": map[string]any{"enc": "utf8", "data": "secret-body-f18"},
|
||||
"delay_ms": int64(0),
|
||||
"receipt": false,
|
||||
})
|
||||
if !send.OK {
|
||||
set("F18", report.StatusFail, fmt.Sprintf("提交失败: %+v", send))
|
||||
t.Errorf("send: %+v", send)
|
||||
return
|
||||
}
|
||||
_ = bob.WaitType(t, "msg", 8*time.Second)
|
||||
bob.Request(t, map[string]any{"v": 1, "type": "ack", "rid": "f18a1", "from": "f18alice1", "id": "f18-body"})
|
||||
time.Sleep(300 * time.Millisecond)
|
||||
|
||||
dbPath := filepath.Join(srv.DataDir, "nixmsg.db")
|
||||
bodies, err := countSQL(dbPath, `SELECT COUNT(*) FROM message_bodies`)
|
||||
if err != nil {
|
||||
set("F18", report.StatusFail, "读库失败: "+err.Error())
|
||||
t.Errorf("db: %v", err)
|
||||
return
|
||||
}
|
||||
if bodies != 0 {
|
||||
set("F18", report.StatusFail, fmt.Sprintf("确认后仍有正文行 message_bodies=%d", bodies))
|
||||
t.Errorf("bodies=%d", bodies)
|
||||
return
|
||||
}
|
||||
|
||||
// 防重:同号同内容再提交不应再投递
|
||||
accept.DrainEvents(t, bob, 200*time.Millisecond)
|
||||
again := alice.Request(t, map[string]any{
|
||||
"v": 1, "type": "send", "rid": "f18s2", "id": "f18-body",
|
||||
"to": map[string]any{"kind": "endpoint", "id": "f18bob001"},
|
||||
"body": map[string]any{"enc": "utf8", "data": "secret-body-f18"},
|
||||
"delay_ms": int64(0),
|
||||
"receipt": false,
|
||||
})
|
||||
if !again.OK {
|
||||
set("F18", report.StatusFail, fmt.Sprintf("防重重试应成功返回原结果: %+v", again))
|
||||
t.Errorf("again: %+v", again)
|
||||
return
|
||||
}
|
||||
if got := bob.TryType("msg", 1*time.Second); got != nil {
|
||||
set("F18", report.StatusFail, fmt.Sprintf("防重窗口内又投递一次: %v", got))
|
||||
t.Errorf("dup msg=%v", got)
|
||||
return
|
||||
}
|
||||
|
||||
// 保留天数 0:完成后记录消失
|
||||
ms, err := accept.StartManagedConfig(retentionZeroYAML)
|
||||
if err != nil {
|
||||
set("F18", report.StatusFail, "retention0 启动失败: "+err.Error())
|
||||
t.Errorf("ret0: %v", err)
|
||||
return
|
||||
}
|
||||
defer func() { _ = ms.Cleanup() }()
|
||||
hs := &harness.Server{HTTPBase: ms.HTTPBase, AdminHTTPBase: ms.AdminHTTPBase, AdminPassword: ms.AdminPassword}
|
||||
ac2 := accept.AdminLogin(t, hs)
|
||||
accept.CreateEndpoint(t, ac2, "f18a2", epPassword)
|
||||
accept.CreateEndpoint(t, ac2, "f18b2", epPassword)
|
||||
a2 := accept.MQTTLogin(t, ms.HTTPBase, "f18a2", epPassword)
|
||||
defer a2.Close()
|
||||
b2 := accept.MQTTLogin(t, ms.HTTPBase, "f18b2", epPassword)
|
||||
defer b2.Close()
|
||||
s2 := a2.Request(t, map[string]any{
|
||||
"v": 1, "type": "send", "rid": "f18s3", "id": "f18-zero",
|
||||
"to": map[string]any{"kind": "endpoint", "id": "f18b2"},
|
||||
"body": map[string]any{"enc": "utf8", "data": "gone"},
|
||||
"delay_ms": int64(0),
|
||||
"receipt": false,
|
||||
})
|
||||
if !s2.OK {
|
||||
set("F18", report.StatusFail, fmt.Sprintf("retention0 提交失败: %+v", s2))
|
||||
t.Errorf("s2: %+v", s2)
|
||||
return
|
||||
}
|
||||
_ = b2.WaitType(t, "msg", 8*time.Second)
|
||||
b2.Request(t, map[string]any{"v": 1, "type": "ack", "rid": "f18a2", "from": "f18a2", "id": "f18-zero"})
|
||||
time.Sleep(300 * time.Millisecond)
|
||||
st := a2.Request(t, map[string]any{"v": 1, "type": "status", "rid": "f18st", "id": "f18-zero"})
|
||||
if st.OK {
|
||||
set("F18", report.StatusFail, fmt.Sprintf("保留天数 0 完成后 status 仍成功: %+v", st))
|
||||
t.Errorf("status still ok: %+v", st)
|
||||
return
|
||||
}
|
||||
if code, _ := st.Error["code"].(string); code != "not_found" {
|
||||
set("F18", report.StatusFail, fmt.Sprintf("期望 status not_found 得 %+v", st))
|
||||
t.Errorf("status=%+v", st)
|
||||
return
|
||||
}
|
||||
msgs, err := countSQL(filepath.Join(ms.DataDir, "nixmsg.db"), `SELECT COUNT(*) FROM messages WHERE id='f18-zero'`)
|
||||
if err != nil {
|
||||
set("F18", report.StatusFail, "读库失败: "+err.Error())
|
||||
t.Errorf("db2: %v", err)
|
||||
return
|
||||
}
|
||||
if msgs != 0 {
|
||||
set("F18", report.StatusFail, fmt.Sprintf("保留天数 0 后消息行仍在 count=%d", msgs))
|
||||
t.Errorf("msgs=%d", msgs)
|
||||
return
|
||||
}
|
||||
set("F18", report.StatusPass, "已测:确认后 message_bodies 为空;同号重试不再投递;record_retention_days=0 完成后 status=not_found 且消息行消失")
|
||||
}
|
||||
|
||||
// runF15JoinWithPasswordFresh 在干净进程上验证带对话密码建群成功(避开长会话后 PublishDown 卡住)。
|
||||
func runF15JoinWithPasswordFresh(t *testing.T) error {
|
||||
t.Helper()
|
||||
srv, err := harness.Start(harness.Options{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("harness: %w", err)
|
||||
}
|
||||
defer func() { _ = srv.Stop() }()
|
||||
ac := accept.AdminLogin(t, srv)
|
||||
accept.CreateEndpoint(t, ac, "f15jalice", epPassword)
|
||||
accept.CreateEndpoint(t, ac, "f15jbob01", epPassword)
|
||||
alice := accept.MQTTLogin(t, srv.HTTPBase, "f15jalice", epPassword)
|
||||
defer alice.Close()
|
||||
bob := accept.MQTTLogin(t, srv.HTTPBase, "f15jbob01", epPassword)
|
||||
defer bob.Close()
|
||||
setTalk := bob.Request(t, map[string]any{
|
||||
"v": 1, "type": "self.talk_password", "rid": "jtp1", "talk_password": "join-secret",
|
||||
})
|
||||
if !setTalk.OK {
|
||||
return fmt.Errorf("设对话密码失败: %+v", setTalk)
|
||||
}
|
||||
addYes := alice.Request(t, map[string]any{
|
||||
"v": 1, "type": "group.create", "rid": "f15jg", "id": "g_f15j", "name": "F15J",
|
||||
"members": []map[string]any{{"id": "f15jbob01", "talk_password": "join-secret"}},
|
||||
})
|
||||
if !addYes.OK {
|
||||
return fmt.Errorf("带密建群失败: %+v", addYes)
|
||||
}
|
||||
if fails := memberFailures(addYes.Data); len(fails) > 0 {
|
||||
return fmt.Errorf("带密建群仍失败: %+v", addYes.Data)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func drainReceipts(s *accept.MQTTSession, d time.Duration) {
|
||||
deadline := time.Now().Add(d)
|
||||
for time.Now().Before(deadline) {
|
||||
if s.TryType("receipt", 40*time.Millisecond) == nil {
|
||||
time.Sleep(20 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func waitReceiptID(t *testing.T, s *accept.MQTTSession, msgID string, timeout time.Duration) map[string]any {
|
||||
t.Helper()
|
||||
deadline := time.Now().Add(timeout)
|
||||
for time.Now().Before(deadline) {
|
||||
m := s.TryType("receipt", 50*time.Millisecond)
|
||||
if m == nil {
|
||||
continue
|
||||
}
|
||||
if m["id"] == msgID {
|
||||
return m
|
||||
}
|
||||
}
|
||||
t.Fatalf("timeout waiting receipt id=%s", msgID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func mapItems(data any) []map[string]any {
|
||||
m, _ := data.(map[string]any)
|
||||
if m == nil {
|
||||
return nil
|
||||
}
|
||||
raw, _ := m["items"].([]any)
|
||||
out := make([]map[string]any, 0, len(raw))
|
||||
for _, x := range raw {
|
||||
if im, ok := x.(map[string]any); ok {
|
||||
out = append(out, im)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func memberFailures(data any) []map[string]any {
|
||||
m, _ := data.(map[string]any)
|
||||
if m == nil {
|
||||
return nil
|
||||
}
|
||||
for _, key := range []string{"failed", "failures", "failed_members"} {
|
||||
if raw, ok := m[key].([]any); ok {
|
||||
out := make([]map[string]any, 0, len(raw))
|
||||
for _, x := range raw {
|
||||
if im, ok := x.(map[string]any); ok {
|
||||
out = append(out, im)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func countSQL(dbPath, query string) (int, error) {
|
||||
dsn := "file:" + filepath.ToSlash(dbPath) + "?_pragma=query_only(1)"
|
||||
db, err := sql.Open("sqlite", dsn)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer func() { _ = db.Close() }()
|
||||
var n int
|
||||
if err := db.QueryRow(query).Scan(&n); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
@@ -34,7 +34,7 @@ func DialMQTTTCP(addr string, timeout time.Duration) (MQTTClient, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_ = conn.SetDeadline(time.Now().Add(timeout))
|
||||
_ = conn.SetDeadline(time.Time{})
|
||||
return &tcpMQTT{conn: conn, r: bufio.NewReader(conn)}, nil
|
||||
}
|
||||
|
||||
@@ -126,6 +126,8 @@ func DialMQTTWebSocket(httpBase string, timeout time.Duration) (MQTTClient, erro
|
||||
_ = raw.Close()
|
||||
return nil, fmt.Errorf("unexpected subprotocol %q", proto)
|
||||
}
|
||||
// 握手完成后清掉超时,否则长会话后续读写会在 dial timeout 到期后全部失败。
|
||||
_ = raw.SetDeadline(time.Time{})
|
||||
return &wsMQTT{conn: raw, r: br}, nil
|
||||
}
|
||||
|
||||
|
||||
Vendored
+19
-19
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"generated_at": "2026-09-30T00:26:12Z",
|
||||
"generated_at": "2026-09-30T02:20:32Z",
|
||||
"items": [
|
||||
{
|
||||
"id": "F01",
|
||||
@@ -13,13 +13,13 @@
|
||||
},
|
||||
{
|
||||
"id": "F03",
|
||||
"status": "untested",
|
||||
"note": "未测:directory.list / 断开后离线状态未在本波单独断言"
|
||||
"status": "pass",
|
||||
"note": "已测:directory.list 可列出端;关掉连接后约 1s 内 presence.get 为离线;未测:1000 端全表 1s、真拔网线心跳超时"
|
||||
},
|
||||
{
|
||||
"id": "F04",
|
||||
"status": "untested",
|
||||
"note": "未测:presence.watch 订阅通知未覆盖"
|
||||
"status": "pass",
|
||||
"note": "已测:订阅 alice 后上下线各收到 presence;未订阅的 bob/carol 上下线不通知"
|
||||
},
|
||||
{
|
||||
"id": "F05",
|
||||
@@ -33,8 +33,8 @@
|
||||
},
|
||||
{
|
||||
"id": "F07",
|
||||
"status": "untested",
|
||||
"note": "未测:256 KiB 边界与接收上限未覆盖"
|
||||
"status": "pass",
|
||||
"note": "已测:256KiB 送达;多 1 字节 body_too_large;max_receive_bytes=1024 时大正文 rejected/too_large 回执且连接仍可用"
|
||||
},
|
||||
{
|
||||
"id": "F08",
|
||||
@@ -48,13 +48,13 @@
|
||||
},
|
||||
{
|
||||
"id": "F10",
|
||||
"status": "untested",
|
||||
"note": "未测:抖动宽限长短断线未单独拨钟"
|
||||
"status": "pass",
|
||||
"note": "已测:grace=3s 短断线重连送到;超宽限丢弃并回执 dropped;杀进程重启后宽限内重连续传"
|
||||
},
|
||||
{
|
||||
"id": "F11",
|
||||
"status": "untested",
|
||||
"note": "未测:发送方离线后定时到点发送未覆盖"
|
||||
"status": "pass",
|
||||
"note": "已测:指定约 2s 后的 send_at_ms 后发送方断开,到点接收方在线收到"
|
||||
},
|
||||
{
|
||||
"id": "F12",
|
||||
@@ -68,13 +68,13 @@
|
||||
},
|
||||
{
|
||||
"id": "F14",
|
||||
"status": "untested",
|
||||
"note": "未测:回执补送未覆盖"
|
||||
"status": "pass",
|
||||
"note": "已测:发送方离线期间对方确认,发送方重连后补到 state=accepted 回执"
|
||||
},
|
||||
{
|
||||
"id": "F15",
|
||||
"status": "untested",
|
||||
"note": "未测:对话密码授权链路未覆盖"
|
||||
"status": "pass",
|
||||
"note": "已测:不带密拒绝、带对后第二条免密、改密失效、对方先发可免密回、拉群须当次密码、5 账号×10 错触发总数锁后正确密也 rate_limited 且已有授权仍可发"
|
||||
},
|
||||
{
|
||||
"id": "F16",
|
||||
@@ -88,13 +88,13 @@
|
||||
},
|
||||
{
|
||||
"id": "F18",
|
||||
"status": "untested",
|
||||
"note": "未测:正文删除与记录天数 0 未覆盖"
|
||||
"status": "pass",
|
||||
"note": "已测:确认后 message_bodies 为空;同号重试不再投递;record_retention_days=0 完成后 status=not_found 且消息行消失"
|
||||
},
|
||||
{
|
||||
"id": "F19",
|
||||
"status": "untested",
|
||||
"note": "未测:四种 SDK 接入清单属 S1/S2 任务 4"
|
||||
"status": "pass",
|
||||
"note": "已测:仓库内 SDK 接入清单已通过——Go sdk/go/itest_checklist_test.go;JS sdk/js/test/checklist.test.ts;Python sdk/python/tests/test_checklist.py;Java sdk/java ChecklistTest;本波不重跑四套全量(见 RELEASE 第 4 节回归记录)"
|
||||
},
|
||||
{
|
||||
"id": "F20",
|
||||
|
||||
Reference in New Issue
Block a user