diff --git a/box.js b/box.js index 224e433e7..0f68493a5 100755 --- a/box.js +++ b/box.js @@ -2,7 +2,8 @@ 'use strict'; -const fs = require('fs'), +const constants = require('./src/constants.js'), + fs = require('fs'), ldap = require('./src/ldap.js'), oidc = require('./src/oidc.js'), paths = require('./src/paths.js'), @@ -14,7 +15,7 @@ const fs = require('fs'), let logFd; async function setupLogging() { - if (process.env.BOX_ENV === 'test') return; + if (constants.TEST) return; logFd = fs.openSync(paths.BOX_LOG_FILE, 'a'); // we used to write using a stream before but it caches internally and there is no way to flush it when things crash diff --git a/src/dns/bunny.js b/src/dns/bunny.js index 603df6a8e..e2ec49862 100644 --- a/src/dns/bunny.js +++ b/src/dns/bunny.js @@ -231,7 +231,7 @@ async function verifyDomainConfig(domainObject) { accessKey: domainConfig.accessKey, }; - if (process.env.BOX_ENV === 'test') return credentials; // this shouldn't be here + if (constants.TEST) return credentials; // this shouldn't be here const [error, nameservers] = await safe(dig.resolve(zoneName, 'NS', { timeout: 5000 })); if (error && error.code === 'ENOTFOUND') throw new BoxError(BoxError.BAD_FIELD, 'Unable to resolve nameservers for this domain'); diff --git a/src/dns/cloudflare.js b/src/dns/cloudflare.js index 18b1edc9d..b1b95bc87 100644 --- a/src/dns/cloudflare.js +++ b/src/dns/cloudflare.js @@ -261,7 +261,7 @@ async function verifyDomainConfig(domainObject) { defaultProxyStatus: domainConfig.defaultProxyStatus }; - if (process.env.BOX_ENV === 'test') return sanitizedConfig; // this shouldn't be here + if (constants.TEST) return sanitizedConfig; // this shouldn't be here const [error, nameservers] = await safe(dig.resolve(zoneName, 'NS', { timeout: 5000 })); if (error && error.code === 'ENOTFOUND') throw new BoxError(BoxError.BAD_FIELD, 'Unable to resolve nameservers for this domain'); diff --git a/src/dns/digitalocean.js b/src/dns/digitalocean.js index 2324f870f..8a35e9fdf 100644 --- a/src/dns/digitalocean.js +++ b/src/dns/digitalocean.js @@ -226,7 +226,7 @@ async function verifyDomainConfig(domainObject) { token: domainConfig.token }; - if (process.env.BOX_ENV === 'test') return credentials; // this shouldn't be here + if (constants.TEST) return credentials; // this shouldn't be here const [error, nameservers] = await safe(dig.resolve(zoneName, 'NS', { timeout: 5000 })); if (error && error.code === 'ENOTFOUND') throw new BoxError(BoxError.BAD_FIELD, 'Unable to resolve nameservers for this domain'); diff --git a/src/dns/gandi.js b/src/dns/gandi.js index 196d8384c..db09d206a 100644 --- a/src/dns/gandi.js +++ b/src/dns/gandi.js @@ -138,7 +138,7 @@ async function verifyDomainConfig(domainObject) { const ip = '127.0.0.1'; - if (process.env.BOX_ENV === 'test') return credentials; // this shouldn't be here + if (constants.TEST) return credentials; // this shouldn't be here const [error, nameservers] = await safe(dig.resolve(zoneName, 'NS', { timeout: 5000 })); if (error && error.code === 'ENOTFOUND') throw new BoxError(BoxError.BAD_FIELD, 'Unable to resolve nameservers for this domain'); diff --git a/src/dns/gcdns.js b/src/dns/gcdns.js index 560cda3da..81768e011 100644 --- a/src/dns/gcdns.js +++ b/src/dns/gcdns.js @@ -168,7 +168,7 @@ async function verifyDomainConfig(domainObject) { const ip = '127.0.0.1'; - if (process.env.BOX_ENV === 'test') return credentials; // this shouldn't be here + if (constants.TEST) return credentials; // this shouldn't be here const [error, nameservers] = await safe(dig.resolve(zoneName, 'NS', { timeout: 5000 })); if (error && error.code === 'ENOTFOUND') throw new BoxError(BoxError.BAD_FIELD, 'Unable to resolve nameservers for this domain'); diff --git a/src/dns/godaddy.js b/src/dns/godaddy.js index 0fb39a835..bc27104a0 100644 --- a/src/dns/godaddy.js +++ b/src/dns/godaddy.js @@ -172,7 +172,7 @@ async function verifyDomainConfig(domainObject) { apiSecret: domainConfig.apiSecret }; - if (process.env.BOX_ENV === 'test') return credentials; // this shouldn't be here + if (constants.TEST) return credentials; // this shouldn't be here const [error, nameservers] = await safe(dig.resolve(zoneName, 'NS', { timeout: 5000 })); if (error && error.code === 'ENOTFOUND') throw new BoxError(BoxError.BAD_FIELD, 'Unable to resolve nameservers for this domain'); diff --git a/src/dns/hetzner.js b/src/dns/hetzner.js index 7fe03289b..206ec8f6f 100644 --- a/src/dns/hetzner.js +++ b/src/dns/hetzner.js @@ -235,7 +235,7 @@ async function verifyDomainConfig(domainObject) { token: domainConfig.token }; - if (process.env.BOX_ENV === 'test') return credentials; // this shouldn't be here + if (constants.TEST) return credentials; // this shouldn't be here const [error, nameservers] = await safe(dig.resolve(zoneName, 'NS', { timeout: 5000 })); if (error && error.code === 'ENOTFOUND') throw new BoxError(BoxError.BAD_FIELD, 'Unable to resolve nameservers for this domain'); diff --git a/src/dns/linode.js b/src/dns/linode.js index 79bc6ee1c..f1e501f15 100644 --- a/src/dns/linode.js +++ b/src/dns/linode.js @@ -244,7 +244,7 @@ async function verifyDomainConfig(domainObject) { token: domainConfig.token }; - if (process.env.BOX_ENV === 'test') return credentials; // this shouldn't be here + if (constants.TEST) return credentials; // this shouldn't be here const [error, nameservers] = await safe(dig.resolve(zoneName, 'NS', { timeout: 5000 })); if (error && error.code === 'ENOTFOUND') throw new BoxError(BoxError.BAD_FIELD, 'Unable to resolve nameservers for this domain'); diff --git a/src/dns/namecheap.js b/src/dns/namecheap.js index 7458cb997..fb3008f25 100644 --- a/src/dns/namecheap.js +++ b/src/dns/namecheap.js @@ -257,7 +257,7 @@ async function verifyDomainConfig(domainObject) { token: domainConfig.token }; - if (process.env.BOX_ENV === 'test') return credentials; // this shouldn't be here + if (constants.TEST) return credentials; // this shouldn't be here const [error, nameservers] = await safe(dig.resolve(zoneName, 'NS', { timeout: 5000 })); if (error && error.code === 'ENOTFOUND') throw new BoxError(BoxError.BAD_FIELD, 'Unable to resolve nameservers for this domain'); diff --git a/src/dns/namecom.js b/src/dns/namecom.js index a98ae556b..acada72fc 100644 --- a/src/dns/namecom.js +++ b/src/dns/namecom.js @@ -227,7 +227,7 @@ async function verifyDomainConfig(domainObject) { const ip = '127.0.0.1'; - if (process.env.BOX_ENV === 'test') return credentials; // this shouldn't be here + if (constants.TEST) return credentials; // this shouldn't be here const [error, nameservers] = await safe(dig.resolve(zoneName, 'NS', { timeout: 5000 })); if (error && error.code === 'ENOTFOUND') throw new BoxError(BoxError.BAD_FIELD, 'Unable to resolve nameservers for this domain'); diff --git a/src/dns/netcup.js b/src/dns/netcup.js index 196a0cfb8..bd6434a19 100644 --- a/src/dns/netcup.js +++ b/src/dns/netcup.js @@ -240,7 +240,7 @@ async function verifyDomainConfig(domainObject) { apiPassword: domainConfig.apiPassword, }; - if (process.env.BOX_ENV === 'test') return credentials; // this shouldn't be here + if (constants.TEST) return credentials; // this shouldn't be here const [error, nameservers] = await safe(dig.resolve(zoneName, 'NS', { timeout: 5000 })); if (error && error.code === 'ENOTFOUND') throw new BoxError(BoxError.BAD_FIELD, 'Unable to resolve nameservers for this domain'); diff --git a/src/dns/porkbun.js b/src/dns/porkbun.js index e94e8b24f..8853befcb 100644 --- a/src/dns/porkbun.js +++ b/src/dns/porkbun.js @@ -217,7 +217,7 @@ async function verifyDomainConfig(domainObject) { apikey: domainConfig.apikey }; - if (process.env.BOX_ENV === 'test') return credentials; // this shouldn't be here + if (constants.TEST) return credentials; // this shouldn't be here const [error, nameservers] = await safe(dig.resolve(zoneName, 'NS', { timeout: 5000 })); if (error && error.code === 'ENOTFOUND') throw new BoxError(BoxError.BAD_FIELD, 'Unable to resolve nameservers for this domain'); diff --git a/src/dns/route53.js b/src/dns/route53.js index f2a9df8aa..6b6fcd0c5 100644 --- a/src/dns/route53.js +++ b/src/dns/route53.js @@ -239,7 +239,7 @@ async function verifyDomainConfig(domainObject) { const ip = '127.0.0.1'; - if (process.env.BOX_ENV === 'test') return credentials; // this shouldn't be here + if (constants.TEST) return credentials; // this shouldn't be here const [error, nameservers] = await safe(dig.resolve(zoneName, 'NS', { timeout: 5000 })); if (error && error.code === 'ENOTFOUND') throw new BoxError(BoxError.BAD_FIELD, 'Unable to resolve nameservers for this domain'); diff --git a/src/dns/vultr.js b/src/dns/vultr.js index 47eede19c..1d1202cac 100644 --- a/src/dns/vultr.js +++ b/src/dns/vultr.js @@ -214,7 +214,7 @@ async function verifyDomainConfig(domainObject) { token: domainConfig.token }; - if (process.env.BOX_ENV === 'test') credentials; // this shouldn't be here + if (constants.TEST) credentials; // this shouldn't be here const [error, nameservers] = await safe(dig.resolve(zoneName, 'NS', { timeout: 5000 })); if (error && error.code === 'ENOTFOUND') throw new BoxError(BoxError.BAD_FIELD, 'Unable to resolve nameservers for this domain'); diff --git a/src/mail.js b/src/mail.js index 35b92b4f7..50800faeb 100644 --- a/src/mail.js +++ b/src/mail.js @@ -689,7 +689,7 @@ async function upsertDnsRecords(domain, mailFqdn) { const mailDomain = await getDomain(domain); if (!mailDomain) throw new BoxError(BoxError.NOT_FOUND, 'mail domain not found'); - if (process.env.BOX_ENV === 'test') return; + if (constants.TEST) return; const publicKey = mailDomain.dkimKey.publicKey.split('\n').slice(1, -2).join(''); // remove header, footer and new lines diff --git a/src/mailer.js b/src/mailer.js index 0b7595499..621dc64b1 100644 --- a/src/mailer.js +++ b/src/mailer.js @@ -18,6 +18,7 @@ exports = module.exports = { const assert = require('assert'), BoxError = require('./boxerror.js'), branding = require('./branding.js'), + constants = require('./constants.js'), dashboard = require('./dashboard.js'), debug = require('debug')('box:mailer'), ejs = require('ejs'), @@ -47,7 +48,7 @@ async function getMailConfig() { async function sendMail(mailOptions) { assert.strictEqual(typeof mailOptions, 'object'); - if (process.env.BOX_ENV === 'test') { + if (constants.TEST) { exports._mailQueue.push(mailOptions); return; } diff --git a/src/mailserver.js b/src/mailserver.js index cd29d6778..f126d0274 100644 --- a/src/mailserver.js +++ b/src/mailserver.js @@ -194,7 +194,7 @@ async function configureMail(mailFqdn, mailDomain, serviceConfig) { } async function restart() { - if (process.env.BOX_ENV === 'test' && !process.env.TEST_CREATE_INFRA) return; + if (constants.TEST && !process.env.TEST_CREATE_INFRA) return; const mailConfig = await services.getServiceConfig('mail'); const { domain, fqdn } = await getLocation(); diff --git a/src/network/generic.js b/src/network/generic.js index e423dc7d9..c4a6b7d5c 100644 --- a/src/network/generic.js +++ b/src/network/generic.js @@ -9,6 +9,7 @@ exports = module.exports = { const assert = require('assert'), BoxError = require('../boxerror.js'), + constants = require('../constants.js'), debug = require('debug')('box:network/generic'), safe = require('safetydance'), superagent = require('superagent'); @@ -18,7 +19,7 @@ const gCache = { ipv4: {}, ipv6: {} }; // each has { timestamp, value, request } async function getIPv4(config) { assert.strictEqual(typeof config, 'object'); - if (process.env.BOX_ENV === 'test') return '127.0.0.1'; + if (constants.TEST) return '127.0.0.1'; if (gCache.ipv4.value && (Date.now() - gCache.ipv4.timestamp <= 5 * 60 * 1000)) return gCache.ipv4.value; @@ -52,7 +53,7 @@ async function getIPv4(config) { async function getIPv6(config) { assert.strictEqual(typeof config, 'object'); - if (process.env.BOX_ENV === 'test') return '::1'; + if (constants.TEST) return '::1'; if (gCache.ipv6.value && (Date.now() - gCache.ipv6.timestamp <= 5 * 60 * 1000)) return gCache.ipv6.value; diff --git a/src/platform.js b/src/platform.js index a915e549e..808ca65fd 100644 --- a/src/platform.js +++ b/src/platform.js @@ -130,7 +130,7 @@ async function onInfraReady(infraChanged) { async function startInfra(restoreOptions) { assert.strictEqual(typeof restoreOptions, 'object'); - if (process.env.BOX_ENV === 'test' && !process.env.TEST_CREATE_INFRA) return; + if (constants.TEST && !process.env.TEST_CREATE_INFRA) return; debug('startInfra: checking infrastructure'); @@ -228,7 +228,7 @@ async function onActivated(restoreOptions) { // disable responding to api calls via IP to not leak domain info. this is carefully placed as the last item, so it buys // the UI some time to query the dashboard domain in the restore code path - await timers.setTimeout(30000); + if (!constants.TEST) await timers.setTimeout(30000); await reverseProxy.writeDefaultConfig({ activated :true }); }