mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-10-28 01:03:50 +08:00
feat(assets): 去掉企业资产范围 256 条规则上限
逐个 IP / 域名录范围的企业很容易撞上这个上限,撞上之后只能拆成多个企业, 而范围本身并不因为条数多就更慢。 - db:删掉 MaxCompanyScopeRules 常量、请求条数校验与 ensureCompanyScopeCapacityTx(每企业持久化总数的事务内校验) - 前端:去掉 MAX_COMPANY_SCOPE_RULES 与「剩余额度」计算,追加范围弹窗不再 按剩余条数报错;demo mock 的两处上限一并移除 - 单条规则仍限 1024 字符;请求正文 2 MiB(maxCompanyMutationBodyBytes)保留 作兜底,约合四五万条规则 测试:原先断言「超容量被拒」的两个用例翻转为「超过旧上限也能写入」—— db 侧批量写 300 条 + 追加 1 条,server 侧一次创建带 300 条范围的企业。 新用例先注册清理再断言,避免断言失败把企业留在共享开发库里。
This commit is contained in:
1 parent
48e14e8cf2
commit
acd1ac29d7
7 files changed
+41
-64
No files matched your search
@@ -151,21 +151,30 @@ func TestCompanyScopeHTTPErrorClassificationAndBounds(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("too many scope rules is 400", func(t *testing.T) {
|
||||
scope := make([]map[string]string, db.MaxCompanyScopeRules+1)
|
||||
t.Run("scope rule count is unbounded", func(t *testing.T) {
|
||||
scope := make([]map[string]string, 300)
|
||||
for i := range scope {
|
||||
scope[i] = map[string]string{"kind": "keyword", "value": fmt.Sprintf("keyword-%d", i)}
|
||||
scope[i] = map[string]string{"kind": "keyword", "value": fmt.Sprintf("unbounded-%d-%d", time.Now().UnixNano(), i)}
|
||||
}
|
||||
body, err := json.Marshal(map[string]any{"name": "Too Many Scope Rules", "scope": scope})
|
||||
body, err := json.Marshal(map[string]any{"name": fmt.Sprintf("Unbounded Scope %d", time.Now().UnixNano()), "scope": scope})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/companies", bytes.NewReader(body))
|
||||
rec := httptest.NewRecorder()
|
||||
s.createCompany(rec, req)
|
||||
if rec.Code != http.StatusBadRequest {
|
||||
var created struct {
|
||||
ID int64 `json:"id"`
|
||||
Added int `json:"scope_added"`
|
||||
}
|
||||
_ = json.Unmarshal(rec.Body.Bytes(), &created)
|
||||
defer func() { _ = m.pg.Companies().DeleteCompany(created.ID) }()
|
||||
if rec.Code != http.StatusCreated {
|
||||
t.Fatalf("status=%d body=%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
if created.Added != len(scope) {
|
||||
t.Fatalf("scope_added=%d want=%d", created.Added, len(scope))
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("oversized request body is 413", func(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user