const utils = {
cleanForExit,
- generateRandomString
+ generateRandomString,
+ isTestInstance
}
function generateRandomString (size, callback) {
process.kill(-webtorrentProcess.pid)
}
+function isTestInstance () {
+ return (process.env.NODE_ENV === 'test')
+}
+
// ---------------------------------------------------------------------------
module.exports = utils
const REMOTE_SCHEME = {
HTTP: 'https',
- WS: 'WS'
+ WS: 'wss'
}
// Password encryption
// ---------------------------------------------------------------------------
+// This method exists in utils module but we want to let the constants module independent
function isTestInstance () {
return (process.env.NODE_ENV === 'test')
}
'use strict'
const checkErrors = require('./utils').checkErrors
+const constants = require('../../initializers/constants')
const friends = require('../../lib/friends')
const logger = require('../../helpers/logger')
+const utils = require('../../helpers/utils')
const validatorsPod = {
makeFriends,
}
function makeFriends (req, res, next) {
+ // Force https if the administrator wants to make friends
+ if (utils.isTestInstance() === false && constants.CONFIG.WEBSERVER.SCHEME === 'http') {
+ return res.status(400).send('Cannot make friends with a non HTTPS webserver.')
+ }
+
req.checkBody('hosts', 'Should have an array of unique hosts').isEachUniqueHostValid()
logger.debug('Checking makeFriends parameters', { parameters: req.body })