-
Notifications
You must be signed in to change notification settings - Fork 92
Require secure transport for Zhihu upstream #517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,8 +53,8 @@ test('requires an Access Secret before any request is issued', async () => { | |
| (error) => error.code === grpcStatus.INVALID_ARGUMENT && /accessSecret is required/.test(error.message), | ||
| ); | ||
| assert.throws( | ||
| () => _test.resolveSettings({ config: { baseUrl: 'ftp://example' }, secret: { accessSecret: 'a' } }), | ||
| /baseUrl must use http or https/, | ||
| () => _test.resolveSettings({ config: { baseUrl: 'http://example' }, secret: { accessSecret: 'a' } }), | ||
| /baseUrl must use https/, | ||
| ); | ||
| assert.throws( | ||
| () => _test.normalizeBaseUrl('not a url'), | ||
|
|
@@ -492,31 +492,40 @@ test('parseResponse maps non-OK HTTP with and without a Message field', async () | |
| assert.deepEqual(ok, { data: { a: 1 } }); | ||
| }); | ||
|
|
||
| test('respects config timeouts, custom headers, TLS flags, and legacy aliases', async () => { | ||
| test('respects config timeouts, custom headers, and legacy aliases', async () => { | ||
| let captured; | ||
| globalThis.fetch = async (url, init) => { | ||
| captured = { url, init }; | ||
| return response(okData({})); | ||
| }; | ||
| const result = await handlers[METHODS.GET_HOT_LIST]({ | ||
| config: { | ||
| baseUrl: 'http://localhost:18082', | ||
| baseUrl: 'https://localhost:18082', | ||
| timeout_ms: 3100, | ||
| headers: { 'X-Custom': 'value' }, | ||
| skipTlsVerify: true, | ||
| }, | ||
| secret: { access_secret: 'legacy-secret' }, | ||
| meta: { instance_id: 'inst', request_id: 'req' }, | ||
| request: { limit: 2 }, | ||
| }); | ||
| assert.deepEqual(result.data, {}); | ||
| assert.equal(captured.url, 'http://localhost:18082/api/v1/content/hot_list?Limit=2'); | ||
| assert.equal(captured.url, 'https://localhost:18082/api/v1/content/hot_list?Limit=2'); | ||
| assert.equal(captured.init.headers['X-Custom'], 'value'); | ||
| assert.equal(captured.init.headers['x-engine-instance'], 'inst'); | ||
| assert.equal(captured.init.headers['x-request-id'], 'req'); | ||
| assert.equal(captured.init.headers.Authorization, 'Bearer legacy-secret'); | ||
| assert.equal(captured.init.dispatcher, _test.insecureTlsDispatcher); | ||
| assert.equal(captured.init.dispatcher, undefined); | ||
| assert.ok(captured.init.signal instanceof AbortSignal); | ||
| assert.throws( | ||
| () => _test.resolveSettings({ config: { baseUrl: 'https://example', skipTlsVerify: true }, secret: { accessSecret: 'a' } }), | ||
| /TLS certificate verification cannot be disabled/, | ||
| ); | ||
| for (const alias of ['tlsInsecureSkipVerify', 'insecureSkipVerify']) { | ||
| assert.throws( | ||
| () => _test.resolveSettings({ config: { baseUrl: 'https://example', [alias]: true }, secret: { accessSecret: 'a' } }), | ||
| /TLS certificate verification cannot be disabled/, | ||
| ); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 「前置 false + 后置 legacy true」组合缺少回归测试,新增用例在旧逻辑下同样通过本次将 TLS 守卫从 firstDefined(...) === true 改为数组的 .some(v => v === true),正是为了修复历史确认的问题:当靠前标志显式为 false 而靠后的 legacy 别名为 true 时(例如 config: { skipTlsVerify: false, tlsInsecureSkipVerify: true }),firstDefined 会直接返回 false,守卫被绕过,本应抛出的「TLS certificate verification cannot be disabled」被静默跳过。但新增的测试仅覆盖「单个标志为 true」的场景(skipTlsVerify: true、tlsInsecureSkipVerify: true、insecureSkipVerify: true 各自单独出现)。在旧的 firstDefined 实现下,这些场景中靠前的标志都是 undefined(未定义),firstDefined 会继续向后取到 true 并照常抛出,因此这些新用例在修复前后行为完全相同,无法区分 bug 与修复。真正需要保护的回归场景(前位 false、后位 true 的组合)没有任何断言覆盖,将来若有人改回 firstDefined 或等价逻辑,测试套件依然会全部通过。 Problem code: Recommendation: Suggested diff: diff --git a/services/zhihu__open-api/test/zhihu-open-api.test.js b/services/zhihu__open-api/test/zhihu-open-api.test.js
--- a/services/zhihu__open-api/test/zhihu-open-api.test.js
+++ b/services/zhihu__open-api/test/zhihu-open-api.test.js
@@ -520,6 +520,14 @@ test('respects config timeouts, custom headers, and legacy aliases', async () =>
for (const alias of ['tlsInsecureSkipVerify', 'insecureSkipVerify']) {
assert.throws(
() => _test.resolveSettings({ config: { baseUrl: 'https://example', [alias]: true }, secret: { accessSecret: 'a' } }),
/TLS certificate verification cannot be disabled/,
);
}
+ // 回归用例:前位显式 false + 后位 legacy true 在旧的 firstDefined 实现下会被绕过。
+ assert.throws(
+ () => _test.resolveSettings({ config: { baseUrl: 'https://example', skipTlsVerify: false, tlsInsecureSkipVerify: true }, secret: { accessSecret: 'a' } }),
+ /TLS certificate verification cannot be disabled/,
+ ); |
||
| const settings = _test.resolveSettings({ | ||
| config: { baseUrl: 'https://x', timeoutMs: 2000, headers: { a: 'b' } }, | ||
| secret: { accessSecret: 's' }, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.