chore: 初始开源发布
iotlcm-onelink-mock:OneLink 挡板服务(本地测试替身)。 - Go module 迁移至 git.5iot.com/iotlcm-public/iotlcm-onelink-mock - 修复同毫秒内多次生成卡导致 ICCID/IMSI 唯一约束冲突 - 补 Apache-2.0 LICENSE,README 重写并新增 docs/deploy.md - 移除内部部署资产(CI 触发器 / 镜像推送脚本 / 指定环境部署文档) - 测试凭据改为 demo_appid / demo_password,真实手机号与内网 IP 脱敏 - 统一 LF 行尾并加 .gitattributes
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestOperationLogCapturesAdminMutationAndRedactsSecrets(t *testing.T) {
|
||||
service, err := NewService(t.TempDir() + "/onelink_mock.db")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/appids", strings.NewReader(`{"appid":"demo","password":"plain-secret","name":"演示"}`))
|
||||
req.RemoteAddr = "192.0.2.10:1234"
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
res := httptest.NewRecorder()
|
||||
service.Router().ServeHTTP(res, req)
|
||||
if res.Code != http.StatusOK {
|
||||
t.Fatalf("status = %d body = %s", res.Code, res.Body.String())
|
||||
}
|
||||
page := service.operationLogs.Query("", "管理台", "success", 1, 20)
|
||||
if page.Total != 1 || page.Items[0].Action != "新增 AppID" {
|
||||
t.Fatalf("logs = %#v", page.Items)
|
||||
}
|
||||
if strings.Contains(page.Items[0].Params, "plain-secret") || !strings.Contains(page.Items[0].Params, "***") {
|
||||
t.Fatalf("secret was not redacted: %s", page.Items[0].Params)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOperationLogQueryReturnsNewestFirst(t *testing.T) {
|
||||
store := newOperationLogStore(func() time.Time { return time.Date(2026, 8, 13, 10, 0, 0, 0, time.Local) })
|
||||
store.Add(OperationLog{Category: "管理台", Action: "第一条", Result: "success"})
|
||||
store.Add(OperationLog{Category: "管理台", Action: "第二条", Result: "success"})
|
||||
page := store.Query("", "", "", 1, 1)
|
||||
if page.Total != 2 || len(page.Items) != 1 || page.Items[0].Action != "第二条" {
|
||||
t.Fatalf("page = %#v", page)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user