Skip to content

Commit a346185

Browse files
JohnMcLearclaude
andcommitted
test: match the stubbed npm registry by origin, not substring
CodeQL flags `url.includes('npmjs.org')` in the catalog spec as incomplete URL sanitization (js/incomplete-url-substring-sanitization). It is test-only routing, but the prefix match is both stricter and clearer, so use it for the stub router and the call assertion. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013S4pYSjwUsiZtdtMMpW7bw
1 parent fa438b7 commit a346185

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/tests/backend/specs/pluginCatalog.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import settings from '../../../node/utils/Settings';
1818
*/
1919
describe(__filename, function () {
2020
const feedUrl = `${settings.updateServer}/plugins.json`;
21+
const npmRegistry = 'https://registry.npmjs.org';
2122

2223
// A miniature plugins.json, shaped exactly like the live feed: name,
2324
// description, time, version, official, downloads, compatibility.
@@ -73,7 +74,9 @@ describe(__filename, function () {
7374
.callsFake(async (input: any) => {
7475
const url = String(input);
7576
if (url === feedUrl) return jsonResponse(feed) as any;
76-
const m = /registry\.npmjs\.org\/([^/]+)\/([^/]+)$/.exec(url);
77+
const m = url.startsWith(`${npmRegistry}/`)
78+
? /\/([^/]+)\/([^/]+)$/.exec(url)
79+
: null;
7780
if (m) {
7881
const body = npm(decodeURIComponent(m[1]), decodeURIComponent(m[2]));
7982
if (body instanceof Error) throw body;
@@ -144,7 +147,8 @@ describe(__filename, function () {
144147
assert.deepEqual(Object.keys(a).sort(), Object.keys(b).sort());
145148
const feedCalls = fetchStub.getCalls().filter((c) => String(c.args[0]) === feedUrl);
146149
assert.equal(feedCalls.length, 1, 'the feed must be fetched once for both callers');
147-
const npmCalls = fetchStub.getCalls().filter((c) => String(c.args[0]).includes('npmjs.org'));
150+
const npmCalls = fetchStub.getCalls()
151+
.filter((c) => String(c.args[0]).startsWith(`${npmRegistry}/`));
148152
assert.equal(npmCalls.length, Object.keys(feed).length, 'one npm lookup per listed plugin');
149153
});
150154

0 commit comments

Comments
 (0)