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.
main
po-et 2026-09-15 13:59:36 +08:00 committed by lyingbug
parent 86d245d892
commit 90e3977714
2 changed files with 8 additions and 3 deletions

View File

@ -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())
}

View File

@ -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())
}