Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict'
const co = require('co')
const test = require('blue-tape')
const s3 = require('../lib/s3')
let path = require('path')
const testBucket = 'web-assets.niketech.com'
var log = (...args) => console.log(...args.map(a => require('util').inspect(a, { colors: true, depth: 1 }))) // eslint-disable-line
// Load AWS secrets
let credentialsContents = require('fs').readFileSync(path.join(require('os').homedir(), '.aws', 'credentials')).toString()
let creds = credentialsContents.split('\n').slice(1, 3)
process.env.AWS_ACCESS_KEY = creds[0].split('= ')[1]
process.env.AWS_SECRET_KEY = creds[1].split('= ')[1]
// log('creds', process.env.AWS_ACCESS_KEY, process.env.AWS_SECRET_KEY)
let testFile = require('fs').readFileSync(path.join(__dirname, '../', 'package.json'))
let testLogger = {
log: log,
// debug: log,
error: log,
warn: log,
info: log
}
test('client should be able to upload, read, and delete a file', t => {
'use strict';
const assert = require('assert');
const os = require('os');
var pid = os.fork();
if (pid == 0) {
// child
os.exit(42);
} else {
// parent
var r = os.waitpid(pid);
assert.equal(r.pid, pid);
assert(os.WIFEXITED(r.status));
assert.equal(os.WEXITSTATUS(r.status), 42);
}
function canRunDockerTests() {
const isLinux = os.platform() === 'linux';
const isDarwin = os.platform() === 'darwin'
// dont even try on windows / osx for now
let hasDockerStarted = false;
if (isLinux || isDarwin) {
hasDockerStarted = proc.execSync('docker info 1>/dev/null 2>&1 ; echo $?').toString('utf-8') === '0\n';
}
return hasDockerStarted;
}
const testRoot = path.resolve(process.env.NODE_TEST_DIR ||
path.dirname(__filename));
exports.testDir = path.dirname(__filename);
exports.fixturesDir = path.join(exports.testDir, 'fixtures');
exports.libDir = path.join(exports.testDir, '../lib');
exports.tmpDirName = 'tmp';
exports.PORT = +process.env.NODE_COMMON_PORT || 12346;
exports.isWindows = process.platform === 'win32';
exports.isWOW64 = exports.isWindows &&
(process.env['PROCESSOR_ARCHITEW6432'] !== undefined);
exports.isAix = process.platform === 'aix';
exports.isLinuxPPCBE = (process.platform === 'linux') &&
(process.arch === 'ppc64') &&
(os.endianness() === 'BE');
exports.isSunOS = process.platform === 'sunos';
exports.isFreeBSD = process.platform === 'freebsd';
exports.enoughTestMem = os.totalmem() > 0x20000000; /* 512MB */
function rimrafSync(p) {
try {
var st = fs.lstatSync(p);
} catch (e) {
if (e.code === 'ENOENT')
return;
}
try {
if (st && st.isDirectory())
rmdirSync(p, null);
'use strict';
const common = require('../common');
const assert = require('assert');
const os = require('os');
const {
PRIORITY_LOW,
PRIORITY_BELOW_NORMAL,
PRIORITY_NORMAL,
PRIORITY_ABOVE_NORMAL,
PRIORITY_HIGH,
PRIORITY_HIGHEST
} = os.constants.priority;
// Validate priority constants.
assert.strictEqual(typeof PRIORITY_LOW, 'number');
assert.strictEqual(typeof PRIORITY_BELOW_NORMAL, 'number');
assert.strictEqual(typeof PRIORITY_NORMAL, 'number');
assert.strictEqual(typeof PRIORITY_ABOVE_NORMAL, 'number');
assert.strictEqual(typeof PRIORITY_HIGH, 'number');
assert.strictEqual(typeof PRIORITY_HIGHEST, 'number');
// Test pid type validation.
[null, true, false, 'foo', {}, [], /x/].forEach((pid) => {
const errObj = {
code: 'ERR_INVALID_ARG_TYPE',
message: /The "pid" argument must be of type number\./
};
'use strict';
const common = require('../common');
const assert = require('assert');
const spawnSync = require('child_process').spawnSync;
const signals = require('os').constants.signals;
const rootUser = common.isWindows ? false : process.getuid() === 0;
const invalidArgTypeError = common.expectsError(
{ code: 'ERR_INVALID_ARG_TYPE', type: TypeError },
common.isWindows || rootUser ? 42 : 62);
const invalidRangeError =
common.expectsError({ code: 'ERR_OUT_OF_RANGE', type: RangeError }, 20);
function pass(option, value) {
// Run the command with the specified option. Since it's not a real command,
// spawnSync() should run successfully but return an ENOENT error.
const child = spawnSync('not_a_real_command', { [option]: value });
assert.strictEqual(child.error.code, 'ENOENT');
}
.onFinalize(async (object, event) => {
const bucket = gcs.bucket(object.bucket);
const filePath = object.name;
const fileName = filePath.split('/').pop();
const bucketDir = dirname(filePath);
const workingDir = join(tmpdir(), 'c0mpre$$ed');
const tmpFilePath = join(workingDir, 'source.png');
// We only want to compress if the request included a desire quality so we gather that here
const imageQuality = object.metadata ? object.metadata.quality : null;
console.log('event', event);
// bail if there isn't a quality passed from req or if the file has already been created or it's not an image
if ( !imageQuality || fileName.includes('c0mpre$$ed@') || !object.contentType.includes('image')) {
console.log('exiting function');
return false;
}
object.metadata.location = 'some new location';
console.log('metadata', object.metadata);
// 1. Ensure c0mpre$$ed dir exists
await fs.ensureDir(workingDir);
var flags = kSignalFlag;
var options = (process.env.NODE_HEAPDUMP_OPTIONS || '').split(/\s*,\s*/);
for (var i = 0, n = options.length; i < n; i += 1) {
var option = options[i];
if (option === '') continue;
else if (option === 'signal') flags |= kSignalFlag;
else if (option === 'nosignal') flags &= ~kSignalFlag;
else console.error('node-heapdump: unrecognized option:', option);
}
addon.configure(flags);
var os = require('os');
var errno = [];
if (os.constants && os.constants.errno) {
Object.keys(os.constants.errno).forEach(function(key) {
var value = os.constants.errno[key];
errno[value] = key;
});
}
exports.writeSnapshot = function(filename, cb) {
if (typeof filename === 'function') cb = filename, filename = undefined;
var result = addon.writeSnapshot(filename);
var success = (typeof result === 'string'); // Filename or errno.
// Make the callback. Yes, this is synchronous; it wasn't back when heapdump
// forked before writing the snapshot, but it is now. index.js can postpone
// the callback with process.nextTick() or setImmediate() if synchronicity
// becomes an issue. Or just remove it, it's pretty pointless now.
if (cb) {
if (success) cb(null, result);
else cb(new Error('heapdump write error ' + (errno[result] || result)));
// restart it
startSonus();
}
})
}
// Initilize the keyword spotter
if (config && config.speech && !firstRun) {
startSonus();
}
if (config.remote && config.remote.enabled || firstRun) {
remote.start()
// Deturmine the local IP address
const interfaces = require("os").networkInterfaces()
let addresses = []
for (let k in interfaces) {
for (let k2 in interfaces[k]) {
let address = interfaces[k][k2]
if (address.family === "IPv4" && !address.internal) {
addresses.push(address.address)
}
}
}
console.log("Remote listening on http://%s:%d", addresses[0], config.remote.port)
remote.on("command", function (command) {
mainWindow.webContents.send("final-results", command)
})
remote.on("connected", function () {
var hasUnicode = module.exports = function () {
// Recent Win32 platforms (>XP) CAN support unicode in the console but
// don't have to, and in non-english locales often use traditional local
// code pages. There's no way, short of windows system calls or execing
// the chcp command line program to figure this out. As such, we default
// this to false and encourage your users to override it via config if
// appropriate.
if (os.type() == "Windows_NT") { return false }
var isUTF8 = /UTF-?8$/i
var ctype = process.env.LC_ALL || process.env.LC_CTYPE || process.env.LANG
return isUTF8.test(ctype)
}