fix(backend): allow accessing private IP when testing

This commit is contained in:
rectcoordsystem 2024-11-06 06:33:44 +09:00 committed by Julia Johannesen
parent f36f4b5398
commit 7ccccf5545
No known key found for this signature in database
GPG Key ID: 4A1377AF3E7FBC46
1 changed files with 2 additions and 2 deletions

View File

@ -42,7 +42,7 @@ class HttpRequestServiceAgent extends http.Agent {
const socket = super.createConnection(options, callback) const socket = super.createConnection(options, callback)
.on('connect', ()=>{ .on('connect', ()=>{
const address = socket.remoteAddress; const address = socket.remoteAddress;
if (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'test') { if (process.env.NODE_ENV === 'production') {
if (address && ipaddr.isValid(address)) { if (address && ipaddr.isValid(address)) {
if (this.isPrivateIp(address)) { if (this.isPrivateIp(address)) {
socket.destroy(new Error(`Blocked address: ${address}`)); socket.destroy(new Error(`Blocked address: ${address}`));
@ -84,7 +84,7 @@ class HttpsRequestServiceAgent extends https.Agent {
const socket = super.createConnection(options, callback) const socket = super.createConnection(options, callback)
.on('connect', ()=>{ .on('connect', ()=>{
const address = socket.remoteAddress; const address = socket.remoteAddress;
if (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'test') { if (process.env.NODE_ENV === 'production') {
if (address && ipaddr.isValid(address)) { if (address && ipaddr.isValid(address)) {
if (this.isPrivateIp(address)) { if (this.isPrivateIp(address)) {
socket.destroy(new Error(`Blocked address: ${address}`)); socket.destroy(new Error(`Blocked address: ${address}`));