From 90e3977714a08e25ccd4506e317fa9c062c9c372 Mon Sep 17 00:00:00 2001 From: po-et <42566883+po-et@users.noreply.github.com> Date: Tue, 15 Sep 2026 13:59:36 +0800 Subject: [PATCH] test(datasource): keep yuque and ima config tests off live DNS parseYuqueConfig and parseIMAConfig validate DefaultBaseURL through ValidateConnectorBaseURL, which resolves the host with net.LookupIP. Their TestMain only whitelists loopback, so the config tests fail on any machine where www.yuque.com or ima.qq.com resolves to a restricted address (a local DNS sinkhole, for example), and the result depends on the network the tests happen to run on. Whitelist the default host as well, which is what the feishu tests already do for open.feishu.cn. --- internal/datasource/connector/ima/fake_ima_test.go | 6 ++++-- internal/datasource/connector/yuque/connector_test.go | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/datasource/connector/ima/fake_ima_test.go b/internal/datasource/connector/ima/fake_ima_test.go index f0026c62..1b503ab6 100644 --- a/internal/datasource/connector/ima/fake_ima_test.go +++ b/internal/datasource/connector/ima/fake_ima_test.go @@ -15,9 +15,11 @@ import ( ) // TestMain whitelists loopback for SSRF so the httptest servers (127.0.0.1) -// are reachable. Production keeps the default strict SSRF policy. +// are reachable, and the default base host so parseIMAConfig does not resolve +// ima.qq.com over live DNS during a unit test. Production keeps the default +// strict SSRF policy. func TestMain(m *testing.M) { - _ = os.Setenv("SSRF_WHITELIST", "127.0.0.1,localhost") + _ = os.Setenv("SSRF_WHITELIST", "127.0.0.1,localhost,ima.qq.com") secutils.ResetSSRFWhitelistForTest() os.Exit(m.Run()) } diff --git a/internal/datasource/connector/yuque/connector_test.go b/internal/datasource/connector/yuque/connector_test.go index 35118e97..44f3ca04 100644 --- a/internal/datasource/connector/yuque/connector_test.go +++ b/internal/datasource/connector/yuque/connector_test.go @@ -11,8 +11,11 @@ import ( secutils "github.com/Tencent/WeKnora/internal/utils" ) +// TestMain whitelists loopback for the httptest servers and the default base +// host so parseYuqueConfig does not resolve www.yuque.com over live DNS during +// a unit test. Production keeps the default strict SSRF policy. func TestMain(m *testing.M) { - os.Setenv("SSRF_WHITELIST", "127.0.0.1,localhost") + _ = os.Setenv("SSRF_WHITELIST", "127.0.0.1,localhost,www.yuque.com") secutils.ResetSSRFWhitelistForTest() os.Exit(m.Run()) }