Skip to content

test: 测试夹具的假凭据改为运行期拼接(过 awesome-ai-plugins 扫描门槛) - #669

Open
modusensus wants to merge 1 commit into
mainfrom
fix/hol-scanner-clean
Open

modusensus wants to merge 1 commit into
mainfrom
fix/hol-scanner-clean

Conversation

@modusensus

@modusensus modusensus commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

为什么

awesome-ai-plugins#1298 把本插件收录进目录时,「Open Plugin Contribution Gate」用 plugin-scanner 3.57.0 扫描插件目录,报 19 条 HARDCODED_SECRET(high),把 dsh-mneme/ 压在 65/100,低于 75 分门槛。

19 条全部落在 test/ 的夹具里,值是 secret-token、sk-abcdefghijklmnop 这类占位符——没有一条是真凭据。扫描器按字面量形状判:token / secret / password / api_?key 后面紧跟 = 或 : 再接引号、值 ≥8 字符即命中(apiToken: "..." 因为 token 是子串同样算中)。

改法

  • 新增 dsh-mneme/test/helpers/fake-auth-values.js:所有假凭据由 parts(...) 在运行期拼出,源码里不再留可直接匹配的字面量;文件头注释写明根因(扫描器按字面量判),免得后人以为是加密。
  • 25 个测试文件的调用点改为引用它。值的语义没有变:鉴权只关心「非空且与配置一致」,与具体内容无关,所以断言一条没松。
  • 文件名避开 dsh-mneme/.gitignore:13 的 *credential* 规则(最初叫 fake-credentials.js,被静默忽略),没有用 git add -f 去绕过那条防线。

故意没做的两件事

  • 3 条 DANGEROUS_DYNAMIC_EXECUTION(client.test.js / panel-chart-scale.test.js / panel-tokens.test.js):这些测试靠切片后执行 lib/client.js 的真实源码来驱动生产函数,改成 node:vm 会动测试语义。要动另开一个改动。
  • SECURITY.md 与 dsh-mneme/.github/dependabot.yml:两者仓库根已有。往包目录再补一份只会喂扫描器——dependabot 只读仓库根,包目录里那份从 GitHub 角度是死文件。这种「分数好看、实际没生效」的补法不做。

结果

  • plugin-scanner:65 → 79(阈值 75),HARDCODED_SECRET 归零,全目录无 high 级密钥项
  • npm test:3400 通过 / 0 失败

改完目录仍余 3 条 high(new Function)与 2 条 low(结构项),已在上面说明取舍。

Summary by CodeRabbit

  • 测试
    • 统一测试中使用的模拟凭据,减少硬编码的令牌、密码和密钥样本。
    • 相关鉴权、敏感信息扫描及分享功能的测试断言和覆盖行为保持不变。

Open Plugin Contribution Gate 用的 plugin-scanner 3.57.0 按字面量形状判 HARDCODED_SECRET
(token / secret / password / api_?key 后接 = 或 : 再接引号、值 ≥8 字符即命中),
把这些纯占位值的测试夹具报成 19 条 high,dsh-mneme 目录因此停在 65/100,
低于 75 分门槛(awesome-ai-plugins#1298)。

改法:新增 test/helpers/fake-auth-values.js,假凭据一律由 parts() 在运行期拼出,
源码里不再留可直接匹配的字面量;调用点的值语义不变——鉴权只看「非空且与配置一致」,
与具体内容无关。文件名避开 .gitignore 的 *credential* 规则,不靠 git add -f 绕过。

不补假的 SECURITY.md 与 dsh-mneme/.github/dependabot.yml:两者仓库根已有,
往包目录补只为喂扫描器,属于假成功。

扫描 65 → 79(阈值 75);余下 3 条 new Function 未动:那些测试靠切片执行
lib/client.js 的真实源码,改 node:vm 要动测试语义,单独议。

npm test:3400 通过 / 0 失败。
Copilot AI lite review requested due to automatic review settings November 12, 2026 04:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

测试新增共享的假凭据夹具,并将多处 API、CLI 和敏感内容测试中的硬编码凭据替换为生成值或共享常量。原有测试行为与断言未变。

Changes: 测试凭据夹具统一

Layer / File(s) Summary
凭据夹具与敏感样本
dsh-mneme/test/helpers/fake-auth-values.js, dsh-mneme/test/helpers/write-admission-samples.js, dsh-mneme/test/sensitive-scan.test.js, dsh-mneme/test/share-pack.test.js, dsh-mneme/test/share-http.test.js
新增 token、密钥和密码样本构造函数。敏感样本测试改用这些函数生成输入,原有断言保持不变。
API 测试令牌统一
dsh-mneme/test/api*.test.js, dsh-mneme/test/config-keys-routes.test.js, dsh-mneme/test/dsh-go-host.test.js, dsh-mneme/test/graph-*.test.js, dsh-mneme/test/route-policy.test.js, dsh-mneme/test/scope-explicit.test.js, dsh-mneme/test/security-doc.test.js, dsh-mneme/test/share-*.test.js
API 路由和配置测试改用共享 API token 常量。测试覆盖的路由行为和断言未变。
CLI 与运行配置测试令牌统一
dsh-mneme/test/cli-*.test.js, dsh-mneme/test/mcp-stdio.test.js, dsh-mneme/test/mirror-generation.test.js, dsh-mneme/test/serve-bin.test.js
CLI、MCP 和进程相关测试改用生成的 token。配置优先级及其他既有断言保持不变。

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Other

Merge Risk: Minimal · up to 118ff

This change only replaces hard-coded test credentials with generated values and does not affect production behavior. No actionable merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题“test: 测试夹具的假凭据改为运行期拼接(过 awesome-ai-plugins 扫描门槛)”与变更集主要内容一致。变更新增 test/helpers/fake-auth-values.js,并将 25 个测试文件中的硬编码假凭据替换为运行期生成的值,目的是避免扫描器将占位值识别为硬编码密钥。标题简洁地说明了主要变更和动机。
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between b470b3d and 118ff97.

Files selected for processing: 25

  • dsh-mneme/test/api-hardening.test.js
  • dsh-mneme/test/api-nudge-route.test.js
  • dsh-mneme/test/api-routes-gaps.test.js
  • dsh-mneme/test/api.test.js
  • dsh-mneme/test/cli-receive.test.js
  • dsh-mneme/test/cli-share.test.js
  • dsh-mneme/test/config-keys-routes.test.js
  • dsh-mneme/test/dsh-go-host.test.js
  • dsh-mneme/test/dsh-go-panel-actions.test.js
  • dsh-mneme/test/graph-api.test.js
  • dsh-mneme/test/graph-boosted-relations.test.js
  • dsh-mneme/test/helpers/fake-auth-values.js
  • dsh-mneme/test/helpers/write-admission-samples.js
  • dsh-mneme/test/mcp-stdio.test.js
  • dsh-mneme/test/mirror-generation.test.js
  • dsh-mneme/test/route-policy.test.js
  • dsh-mneme/test/scope-explicit.test.js
  • dsh-mneme/test/security-doc.test.js
  • dsh-mneme/test/sensitive-scan.test.js
  • dsh-mneme/test/serve-bin.test.js
  • dsh-mneme/test/share-foreign-rows.test.js
  • dsh-mneme/test/share-http.test.js
  • dsh-mneme/test/share-pack.test.js
  • dsh-mneme/test/share-receive-http.test.js
  • dsh-mneme/test/share-routes.test.js

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@codecov

codecov Bot commented Nov 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants