Skip to content

Commit e09d222

Browse files
committed
fix: test case for safefetch
1 parent def0aed commit e09d222

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/lib/core/fetch_factory.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,27 @@ describe('test/lib/core/fetch_factory.test.js', () => {
2424
let host;
2525
const fetch = safeFetch.bind({
2626
config: {
27+
httpclient: {
28+
// ensure dns resolve succeeds
29+
lookup(hostname, options, callback) {
30+
const IP_REGEX = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
31+
if (IP_REGEX.test(hostname)) {
32+
const family = typeof options.family === 'number' ? options.family : 4;
33+
if (options.all) {
34+
callback(null, [{ address: hostname, family }]);
35+
} else {
36+
callback(null, hostname, family);
37+
}
38+
} else {
39+
const resultIp = '127.0.0.1'
40+
if (options.all) {
41+
callback(null, [{ address: resultIp, family: 4 }]);
42+
} else {
43+
callback(null, resultIp, 4);
44+
}
45+
}
46+
},
47+
},
2748
security: {
2849
ssrf: {
2950
checkAddress(aIp, aFamily, aHost) {

0 commit comments

Comments
 (0)