Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

regedit

Package Overview
Dependencies
Maintainers
3
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

regedit - npm Package Compare versions

Comparing version 3.0.0 to 3.0.2

434

index.js

@@ -40,117 +40,114 @@ var fs = require('fs')

*/
var externalVBSFolderLocation = undefined;
var externalVBSFolderLocation
module.exports.setExternalVBSLocation = function (newLocation) {
if (fs.existsSync(newLocation)) {
externalVBSFolderLocation = newLocation;
return 'Folder found and set';
}
else{
return 'Folder not found';
}
module.exports.setExternalVBSLocation = function(newLocation) {
if (fs.existsSync(newLocation)) {
externalVBSFolderLocation = newLocation
return 'Folder found and set'
}
return 'Folder not found'
}
module.exports.list = function (keys, architecture, callback) {
module.exports.list = function(keys, architecture, callback) {
//console.log('list with callback will be deprecated in future versions, use list streaming interface')
if (architecture === undefined) {
callback = undefined
architecture = OS_ARCH_AGNOSTIC
}
else if (typeof architecture === 'function') {
callback = architecture
architecture = OS_ARCH_AGNOSTIC
}
if (architecture === undefined) {
callback = undefined
architecture = OS_ARCH_AGNOSTIC
} else if (typeof architecture === 'function') {
callback = architecture
architecture = OS_ARCH_AGNOSTIC
}
if (typeof keys === 'string') {
keys = [keys]
}
if (typeof keys === 'string') {
keys = [keys]
}
if (typeof callback === 'function') {
execute(toCommandArgs('regList.wsf', architecture, keys), callback)
}
else {
var outputStream = through2.obj(helper.vbsOutputTransform)
if (typeof callback === 'function') {
execute(toCommandArgs('regList.wsf', architecture, keys), callback)
} else {
var outputStream = through2.obj(helper.vbsOutputTransform)
cscript.init(function (err) {
if (err) {
return outputStream.emit('error', err)
}
cscript.init(function(err) {
if (err) {
return outputStream.emit('error', err)
}
var args = baseCommand('regListStream.wsf', architecture)
var child = execFile(cscript.path(), args, {encoding: 'utf8'}, function(err) {
if (err) {
outputStream.emit('error', err)
}
})
child.stderr.pipe(process.stderr)
var args = baseCommand('regListStream.wsf', architecture)
var slicer = new StreamSlicer({sliceBy: helper.WIN_EOL})
child.stdout.pipe(slicer).pipe(outputStream)
helper.writeArrayToStream(keys, child.stdin)
})
var child = execFile(cscript.path(), args, { encoding: 'utf8' }, function(err) {
if (err) {
outputStream.emit('error', err)
}
})
return outputStream
}
child.stderr.pipe(process.stderr)
var slicer = new StreamSlicer({ sliceBy: helper.WIN_EOL })
child.stdout.pipe(slicer).pipe(outputStream)
helper.writeArrayToStream(keys, child.stdin)
})
return outputStream
}
}
module.exports.createKey = function (keys, architecture, callback) {
if (typeof architecture === 'function') {
callback = architecture
architecture = OS_ARCH_AGNOSTIC
}
module.exports.createKey = function(keys, architecture, callback) {
if (typeof architecture === 'function') {
callback = architecture
architecture = OS_ARCH_AGNOSTIC
}
if (typeof keys === 'string') {
keys = [keys]
}
if (typeof keys === 'string') {
keys = [keys]
}
var args = baseCommand('regCreateKey.wsf', architecture)
var args = baseCommand('regCreateKey.wsf', architecture)
spawnEx(args, keys, callback)
spawnEx(args, keys, callback)
}
module.exports.deleteKey = function (keys, architecture, callback) {
if (typeof architecture === 'function') {
callback = architecture
architecture = OS_ARCH_AGNOSTIC
}
module.exports.deleteKey = function(keys, architecture, callback) {
if (typeof architecture === 'function') {
callback = architecture
architecture = OS_ARCH_AGNOSTIC
}
if (typeof keys === 'string') {
keys = [keys]
}
if (typeof keys === 'string') {
keys = [keys]
}
var args = baseCommand('regDeleteKey.wsf', architecture)
var args = baseCommand('regDeleteKey.wsf', architecture)
spawnEx(args, keys, callback)
spawnEx(args, keys, callback)
}
module.exports.putValue = function(map, architecture, callback) {
if (typeof architecture === 'function') {
callback = architecture
architecture = OS_ARCH_AGNOSTIC
}
if (typeof architecture === 'function') {
callback = architecture
architecture = OS_ARCH_AGNOSTIC
}
var args = baseCommand('regPutValue.wsf', architecture)
var args = baseCommand('regPutValue.wsf', architecture)
var values = []
var values = []
for (var key in map) {
var keyValues = map[key]
for (var key in map) {
var keyValues = map[key]
for (var valueName in keyValues) {
var entry = keyValues[valueName]
for (var valueName in keyValues) {
var entry = keyValues[valueName]
// helper writes the array to the stream in reversed order
values.push(entry.type)
values.push(renderValueByType(entry.value, entry.type))
values.push(valueName)
values.push(key)
}
}
values.push(entry.type)
values.push(renderValueByType(entry.value, entry.type))
values.push(valueName)
values.push(key)
}
}
spawnEx(args, values, callback)
spawnEx(args, values, callback)
}

@@ -161,47 +158,47 @@

module.exports.arch.list = function(keys, callback) {
return module.exports.list(keys, OS_ARCH_SPECIFIC, callback)
return module.exports.list(keys, OS_ARCH_SPECIFIC, callback)
}
module.exports.arch.list32 = function (keys, callback) {
return module.exports.list(keys, OS_ARCH_32BIT, callback)
module.exports.arch.list32 = function(keys, callback) {
return module.exports.list(keys, OS_ARCH_32BIT, callback)
}
module.exports.arch.list64 = function (keys, callback) {
return module.exports.list(keys, OS_ARCH_64BIT, callback)
module.exports.arch.list64 = function(keys, callback) {
return module.exports.list(keys, OS_ARCH_64BIT, callback)
}
module.exports.arch.createKey = function (keys, callback) {
return module.exports.createKey(keys, OS_ARCH_SPECIFIC, callback)
module.exports.arch.createKey = function(keys, callback) {
return module.exports.createKey(keys, OS_ARCH_SPECIFIC, callback)
}
module.exports.arch.createKey32 = function (keys, callback) {
return module.exports.createKey(keys, OS_ARCH_32BIT, callback)
module.exports.arch.createKey32 = function(keys, callback) {
return module.exports.createKey(keys, OS_ARCH_32BIT, callback)
}
module.exports.arch.createKey64 = function (keys, callback) {
return module.exports.createKey(keys, OS_ARCH_64BIT, callback)
module.exports.arch.createKey64 = function(keys, callback) {
return module.exports.createKey(keys, OS_ARCH_64BIT, callback)
}
module.exports.arch.deleteKey = function (keys, callback) {
return module.exports.deleteKey(keys, OS_ARCH_SPECIFIC, callback)
module.exports.arch.deleteKey = function(keys, callback) {
return module.exports.deleteKey(keys, OS_ARCH_SPECIFIC, callback)
}
module.exports.arch.deleteKey32 = function (keys, callback) {
return module.exports.deleteKey(keys, OS_ARCH_32BIT, callback)
module.exports.arch.deleteKey32 = function(keys, callback) {
return module.exports.deleteKey(keys, OS_ARCH_32BIT, callback)
}
module.exports.arch.deleteKey64 = function (keys, callback) {
return module.exports.deleteKey(keys, OS_ARCH_64BIT, callback)
module.exports.arch.deleteKey64 = function(keys, callback) {
return module.exports.deleteKey(keys, OS_ARCH_64BIT, callback)
}
module.exports.arch.putValue = function (keys, callback) {
return module.exports.putValue(keys, OS_ARCH_SPECIFIC, callback)
module.exports.arch.putValue = function(keys, callback) {
return module.exports.putValue(keys, OS_ARCH_SPECIFIC, callback)
}
module.exports.arch.putValue32 = function (keys, callback) {
return module.exports.putValue(keys, OS_ARCH_32BIT, callback)
module.exports.arch.putValue32 = function(keys, callback) {
return module.exports.putValue(keys, OS_ARCH_32BIT, callback)
}
module.exports.arch.putValue64 = function (keys, callback) {
return module.exports.putValue(keys, OS_ARCH_64BIT, callback)
module.exports.arch.putValue64 = function(keys, callback) {
return module.exports.putValue(keys, OS_ARCH_64BIT, callback)
}

@@ -211,101 +208,100 @@

if (typeof callback !== 'function') {
throw new Error('missing callback')
}
if (typeof callback !== 'function') {
throw new Error('missing callback')
}
debug(args)
debug(args)
cscript.init(function (err) {
if (err) {
return callback(err)
}
cscript.init(function(err) {
if (err) {
return callback(err)
}
childProcess.execFile(cscript.path(), args, function (err, stdout, stderr) {
childProcess.execFile(cscript.path(), args, function(err, stdout, stderr) {
if (err) {
if (stdout) {
console.log(stdout)
}
if (err) {
if (stdout) {
console.log(stdout)
}
if (stderr) {
console.error(stderr)
}
if (stderr) {
console.error(stderr)
}
if (err.code in errors) {
return callback(errors[err.code])
}
return callback(err)
}
if (err.code in errors) {
return callback(errors[err.code])
}
return callback(err)
}
// in case we have stuff in stderr but no real error
if (stderr) {
return callback(new Error(stderr))
}
if (!stdout) {
return callback()
}
debug(stdout)
if (stderr) {
return callback(new Error(stderr))
}
if (!stdout) {
return callback()
}
var result
err = null
debug(stdout)
try {
result = JSON.parse(stdout)
}
catch (e) {
e.stdout = stdout
err = e
}
var result
err = null
callback(err, result)
})
})
try {
result = JSON.parse(stdout)
} catch (e) {
e.stdout = stdout
err = e
}
callback(err, result)
})
})
}
function spawnEx(args, keys, callback) {
cscript.init(function (err) {
if (err) {
return callback(err)
}
cscript.init(function(err) {
if (err) {
return callback(err)
}
debug(args)
debug(args)
var child = execFile(cscript.path(), args, {encoding: 'utf8'})
handleErrorsAndClose(child, callback)
var child = execFile(cscript.path(), args, { encoding: 'utf8' })
helper.writeArrayToStream(keys, child.stdin)
})
handleErrorsAndClose(child, callback)
helper.writeArrayToStream(keys, child.stdin)
})
}
function handleErrorsAndClose (child, callback) {
var error
child.once('error', function(e) {
debug('process error %s', e)
error = e
})
function handleErrorsAndClose(child, callback) {
var error
child.once('error', function(e) {
debug('process error %s', e)
error = e
})
child.once('close', function (code) {
debug('process exit with code %d', code)
child.once('close', function(code) {
debug('process exit with code %d', code)
if (error) {
if (error.code in errors) {
return callback(errors[error.code])
}
return callback(error)
}
if (error) {
if (error.code in errors) {
return callback(errors[error.code])
}
return callback(error)
if (code !== 0) {
if (code in errors) {
return callback(errors[code])
}
return callback(new Error('vbscript process reported unknown error code ' + code))
}
}
callback()
})
if (code !== 0) {
if (code in errors) {
return callback(errors[code])
}
return callback(new Error('vbscript process reported unknown error code ' + code))
}
callback()
})
}

@@ -315,26 +311,26 @@

function renderValueByType(value, type) {
type = type.toUpperCase()
type = type.toUpperCase()
switch (type) {
case 'REG_BINARY':
if (!util.isArray(value)) {
throw new Error('invalid value type ' + typeof (value) + ' for registry type REG_BINARY, please use an array of numbers')
}
return value.join(',')
switch (type) {
case 'REG_BINARY':
if (!util.isArray(value)) {
throw new Error('invalid value type ' + typeof(value) + ' for registry type REG_BINARY, please use an array of numbers')
}
return value.join(',')
case 'REG_MULTI_SZ':
if (!util.isArray(value)) {
throw new Error('invalid value type ' + typeof (value) + ' for registry type REG_BINARY, please use an array of strings')
}
return value.join(',')
case 'REG_MULTI_SZ':
if (!util.isArray(value)) {
throw new Error('invalid value type ' + typeof(value) + ' for registry type REG_BINARY, please use an array of strings')
}
return value.join(',')
case 'REG_SZ':
if (value === '') {
return '\0'
}
return value
case 'REG_SZ':
if (value === '') {
return '\0'
}
return value
default:
return value
}
default:
return value
}
}

@@ -344,14 +340,12 @@

function toCommandArgs(cmd, arch, keys) {
var result = baseCommand(cmd, arch)
if (typeof keys === 'string') {
result.push(keys)
}
else if (util.isArray(keys)) {
result = result.concat(keys)
}
else {
debug('creating command without using keys %s', keys ? keys : '')
}
var result = baseCommand(cmd, arch)
if (typeof keys === 'string') {
result.push(keys)
} else if (util.isArray(keys)) {
result = result.concat(keys)
} else {
debug('creating command without using keys %s', keys ? keys : '')
}
return result
return result
}

@@ -361,13 +355,13 @@

function baseCommand(cmd, arch) {
var scriptPath
// test undefined, null and empty string
if (externalVBSFolderLocation && typeof(externalVBSFolderLocation) === 'string') {
scriptPath = externalVBSFolderLocation
if (externalVBSFolderLocation && typeof(externalVBSFolderLocation) === 'string') {
scriptPath = externalVBSFolderLocation
} else {
scriptPath = path.join(__dirname, 'vbs')
scriptPath = path.join(__dirname, 'vbs')
}
return ['//Nologo', path.join(scriptPath, cmd), arch]
}

@@ -10,10 +10,10 @@ /* eslint-disable global-require */

/*
* when we mock stuff we need a way to reset
* when we mock stuff we need a way to reset
*/
function resetDependencies() {
init = false
ifAsync = require('if-async')
fs = require('fs')
execFile = require('../lib/execFile.js')({bufferStdout: true, bufferStderr: true})
debug = require('debug')('regedit:cscript')
init = false
ifAsync = require('if-async')
fs = require('fs')
execFile = require('../lib/execFile.js')({ bufferStdout: true, bufferStderr: true })
debug = require('debug')('regedit:cscript')
}

@@ -24,3 +24,3 @@

/*
* expected output for failed where.exe execution, exported for testing purposes
* expected output for failed where.exe execution, exported for testing purposes
*/

@@ -30,3 +30,3 @@ var CSCRIPT_NOT_FOUND = module.exports.CSCRIPT_NOT_FOUND = 'INFO: Could not find files for the given pattern(s).'

/*
* expected output for cscript.exe, exported for testing purposes
* expected output for cscript.exe, exported for testing purposes
*/

@@ -37,41 +37,41 @@ var CSCRIPT_EXPECTED_OUTPUT = module.exports.CSCRIPT_EXPECTED_OUTPUT = 'Microsoft (R) Windows Script Host Version'

module.exports.path = function () {
module.exports.path = function() {
// this sucks...
if (init === false) {
throw new Error('must initialize first')
}
debug(cscript)
return cscript
if (init === false) {
throw new Error('must initialize first')
}
debug(cscript)
return cscript
}
module.exports.init = function (callback) {
debug('init()')
module.exports.init = function(callback) {
debug('init()')
if (init) {
debug('already initialized')
return setImmediate(callback)
}
if (init) {
debug('already initialized')
return setImmediate(callback)
}
var functor =
var functor =
ifAsync(spawnCScriptSucceeded)
.or(whereCScriptSucceeded)
.or(fsStatCScriptSucceeded)
.then(function (cb) {
init = true
cb()
})
.then(function(cb) {
init = true
cb()
})
.else(callbackWithError)
functor(function (err) {
if (err) {
return callback(err)
}
callback()
})
functor(function(err) {
if (err) {
return callback(err)
}
callback()
})
}
module.exports._mock = function(_fs, _execFile, _init) {
fs = _fs
execFile = _execFile
init = _init
fs = _fs
execFile = _execFile
init = _init
}

@@ -81,78 +81,78 @@

function spawnCScriptSucceeded (callback) {
debug('spawnCScriptSucceeded()')
function spawnCScriptSucceeded(callback) {
debug('spawnCScriptSucceeded()')
execFile('cscript.exe', function (err, stdout, stderr) {
if (err) {
execFile('cscript.exe', function(err, stdout, stderr) {
if (err) {
// where command not found on this system
if (err.code === 'ENOENT') {
return callback(null, false)
}
return callback(err)
}
if (err.code === 'ENOENT') {
return callback(null, false)
}
return callback(err)
cscript = 'cscript.exe'
callback(null, stdout.indexOf(CSCRIPT_EXPECTED_OUTPUT) > -1)
})
}
cscript = 'cscript.exe'
callback(null, stdout.indexOf(CSCRIPT_EXPECTED_OUTPUT) > -1)
})
}
function whereCScriptSucceeded (callback) {
debug('whereCScriptSucceeded()')
function whereCScriptSucceeded(callback) {
debug('whereCScriptSucceeded()')
execFile('where cscript.exe', function (err, stdout, stderr) {
if (err) {
execFile('where cscript.exe', function(err, stdout, stderr) {
if (err) {
// where command not found on this system
if (err.code === 'ENOENT') {
return callback(null, false)
}
return callback(err)
}
if (err.code === 'ENOENT') {
return callback(null, false)
}
return callback(err)
if (typeof stdout !== 'string') {
return callback(null, false)
}
if (stdout.indexOf(CSCRIPT_NOT_FOUND) > -1) {
return callback(null, false)
}
}
cscript = stdout.trim()
callback(null, true)
})
if (typeof stdout !== 'string') {
return callback(null, false)
}
if (stdout.indexOf(CSCRIPT_NOT_FOUND) > -1) {
return callback(null, false)
}
cscript = stdout.trim()
callback(null, true)
})
}
function fsStatCScriptSucceeded(callback) {
debug('fsStatCScriptSucceeded()')
debug('fsStatCScriptSucceeded()')
fs.stat('c:\\windows\\system32\\cscript.exe', function(err, stat) {
if (err) {
if (err.code === 'ENOENT') {
return callback(null, false)
}
return callback(err)
}
fs.stat('c:\\windows\\system32\\cscript.exe', function(err, stat) {
if (err) {
if (err.code === 'ENOENT') {
return callback(null, false)
}
return callback(err)
cscript = 'c:\\windows\\system32\\cscript.exe'
callback(null, true)
})
}
cscript = 'c:\\windows\\system32\\cscript.exe'
callback(null, true)
})
}
function callbackWithError(cb) {
cb(new Error('cscript not found'))
cb(new Error('cscript not found'))
}
function once (cb) {
var fired = false
return function () {
if (fired) {
return cb()
}
fired = true
function once(cb) {
var fired = false
return function() {
if (fired) {
return cb()
}
fired = true
cb.apply(null, arguments)
}
cb.apply(null, arguments)
}
}
var childProcess = require('child_process')
module.exports = function(options) {
options = options || {}
options = options || {}
return function execFile () {
return function execFile() {
var child = childProcess.execFile.apply(childProcess, arguments)
var child = childProcess.execFile.apply(childProcess, arguments)
if (!options.bufferStdout) {
child.stdout.removeAllListeners('data')
}
if (!options.bufferStdout) {
child.stdout.removeAllListeners('data')
}
if (!options.bufferStderr) {
child.stderr.removeAllListeners('data')
}
if (!options.bufferStderr) {
child.stderr.removeAllListeners('data')
}
return child
}
return child
}
}

@@ -8,3 +8,3 @@ var debug = require('debug')('regedit')

module.exports.encode = function(str) {
return escape(str) + WIN_EOL
return escape(str) + WIN_EOL
}

@@ -15,47 +15,45 @@

*/
module.exports.writeArrayToStream = function (arr, stream, optionalCallback) {
module.exports.writeArrayToStream = function(arr, stream, optionalCallback) {
var encoding = 'utf8'
var member = arr.pop()
var encoding = 'utf8'
var member = arr.pop()
function write(m) {
if (m !== undefined) {
var b = module.exports.encode(m)
debug(b)
return stream.write(b)
}
function write(m) {
if (m !== undefined) {
var b = module.exports.encode(m)
debug(b)
return stream.write(b)
}
return false
}
return false
}
while (write(member)) {
member = arr.pop()
}
while (write(member)) {
member = arr.pop()
}
if (arr.length === 0) {
stream.write(WIN_EOL, optionalCallback)
return
}
if (arr.length === 0) {
stream.write(WIN_EOL, optionalCallback)
return
}
stream.once('drain', function () {
module.exports.writeArrayToStream(arr, stream, optionalCallback)
})
stream.once('drain', function() {
module.exports.writeArrayToStream(arr, stream, optionalCallback)
})
}
module.exports.vbsOutputTransform = function (chunk, enc, callback) {
try {
if (enc === 'buffer') {
chunk = chunk.toString()
}
else {
chunk = chunk.toString(enc)
}
module.exports.vbsOutputTransform = function(chunk, enc, callback) {
try {
if (enc === 'buffer') {
chunk = chunk.toString()
} else {
chunk = chunk.toString(enc)
}
this.push(JSON.parse(chunk))
}
catch (e) {
return callback(e)
}
this.push(JSON.parse(chunk))
} catch (e) {
return callback(e)
}
return callback()
return callback()
}
{
"name": "regedit",
"version": "3.0.0",
"version": "3.0.2",
"description": "Read, Write, List and do all sorts of funky stuff to the windows registry using node.js and windows script host",

@@ -18,3 +18,3 @@ "keywords": [

"dependencies": {
"debug": "^2.1.1",
"debug": "^4.1.0",
"if-async": "^3.7.4",

@@ -28,5 +28,2 @@ "stream-slicer": "0.0.6",

},
"os": [
"win32"
],
"repository": {

@@ -39,7 +36,7 @@ "type": "git",

"devDependencies": {
"mocha": "^5.2.0",
"eslint": "^3.19.0",
"husky": "^0.13.4",
"mocha": "^2.3.4",
"should": "^4.4.2"
}
}

@@ -40,2 +40,11 @@ # regedit

#### A note about Electron
This software uses Windows Script Host to read and write to the registry. For that purpose, it will execute [`.wsf`](https://github.com/ironSource/node-regedit/tree/master/vbs) files. When packaging the app's dependencies with ASAR, `node-regedit` will not be able to access the windows script files, because they are bundled in a single ASAR file. Therefore it is necessary to store the `.wsf` files elsewhere, outside of the packaged asar file. You can set your custom location for the files with `setExternalVBSLocation(location)`:
```
// Assuming the files lie in <app>/resources/my-location
const vbsDirectory = path.join(path.dirname(electron.remote.app.getPath('exe')), './resources/my-location');
regedit.setExternalVBSLocation(vbsDirectory);
```
# API

@@ -42,0 +51,0 @@ Every command executes a sub process that runs vbscript code. To boost efficiency, every command supports batching.

var should = require('should')
var index = require('../index')
describe.skip('benchmark test', function (done) {
this.timeout(40000)
describe.skip('benchmark test', function(done) {
this.timeout(40000)
var testSize = 10000
var staticBaseKey = 'HKCU\\software\\ironSource\\test\\bench\\'
var testSize = 10000
var staticBaseKey = 'HKCU\\software\\ironSource\\test\\bench\\'
var baseKey, keys
var baseKey, keys
it('create', function (done) {
console.time('start create')
index.createKey(keys, function(err, result) {
if (err) {
return done(err)
}
console.timeEnd('start create')
done()
})
})
it('create', function(done) {
it('test', function (done) {
index.createKey(keys, function(err, result) {
if (err) {
return done(err)
}
console.timeEnd('start create')
index.list(baseKey, function (err, result) {
if (err) {
return done(err)
}
console.time('start create')
done()
})
})
})
console.time('start create')
index.createKey(keys, function(err, result) {
if (err) {
return done(err)
}
console.timeEnd('start create')
done()
})
})
beforeEach(function (done) {
baseKey = staticBaseKey + Date.now()
it('test', function(done) {
index.createKey(keys, function(err, result) {
if (err) {
return done(err)
}
console.timeEnd('start create')
index.list(baseKey, function(err, result) {
if (err) {
return done(err)
}
console.time('start create')
done()
})
})
})
beforeEach(function(done) {
baseKey = staticBaseKey + Date.now()
// clear remains of previous tests
index.deleteKey(staticBaseKey, function (err) {
if (err) {
console.log(err)
console.log('this is of no consequence, probably.')
}
index.deleteKey(staticBaseKey, function(err) {
if (err) {
console.log(err)
console.log('this is of no consequence, probably.')
}
// create N keys for the test
keys = []
keys = []
for (var i = 0; i < testSize; i++) {
keys.push(baseKey + '\\' + i)
}
})
})
for (var i = 0; i < testSize; i++) {
keys.push(baseKey + '\\' + i)
}
})
})
})

@@ -6,122 +6,122 @@ /* eslint-disable consistent-this */

describe('cscript', function () {
var mockFs, mockExecFile
describe('cscript', function() {
var mockFs, mockExecFile
it('must be initialized', function () {
(function () {
cscript.path()
}).should.throw('must initialize first')
})
it('must be initialized', function() {
(function() {
cscript.path()
}).should.throw('must initialize first')
})
it('if cscript.exe is successfully spawned then no more checks are conducted', function (done) {
mockExecFile['cscript.exe'].calls.should.eql(0)
mockExecFile['cscript.exe'].stdout = cscript.CSCRIPT_EXPECTED_OUTPUT
it('if cscript.exe is successfully spawned then no more checks are conducted', function(done) {
mockExecFile['cscript.exe'].calls.should.eql(0)
mockExecFile['cscript.exe'].stdout = cscript.CSCRIPT_EXPECTED_OUTPUT
cscript.init(function (err) {
if (err) {
return done(err)
}
cscript.init(function(err) {
if (err) {
return done(err)
}
mockExecFile['cscript.exe'].calls.should.eql(1)
mockExecFile['cscript.exe'].args[0].should.eql('cscript.exe')
done()
})
})
mockExecFile['cscript.exe'].calls.should.eql(1)
mockExecFile['cscript.exe'].args[0].should.eql('cscript.exe')
done()
})
})
it('initializes only once', function (done) {
it('initializes only once', function(done) {
mockExecFile['cscript.exe'].calls.should.eql(0)
mockExecFile['cscript.exe'].stdout = cscript.CSCRIPT_EXPECTED_OUTPUT
mockExecFile['cscript.exe'].calls.should.eql(0)
mockExecFile['cscript.exe'].stdout = cscript.CSCRIPT_EXPECTED_OUTPUT
cscript.init(function (err) {
if (err) {
return done(err)
}
cscript.init(function(err) {
if (err) {
return done(err)
}
mockExecFile['cscript.exe'].calls.should.eql(1)
cscript.init(function (err) {
if (err) {
return done(err)
}
mockExecFile['cscript.exe'].calls.should.eql(1)
mockExecFile['where cscript.exe'].calls.should.eql(0)
done()
})
})
})
mockExecFile['cscript.exe'].calls.should.eql(1)
it('if cscript.exe fails to execute, try to run "where cscript.exe"', function (done) {
mockExecFile['cscript.exe'].calls.should.eql(0)
mockExecFile['where cscript.exe'].calls.should.eql(0)
cscript.init(function(err) {
if (err) {
return done(err)
}
mockExecFile['cscript.exe'].err = new Error()
mockExecFile['cscript.exe'].err.code = 'ENOENT'
mockExecFile['where cscript.exe'].stdout = '123'
mockExecFile['cscript.exe'].calls.should.eql(1)
mockExecFile['where cscript.exe'].calls.should.eql(0)
done()
})
})
})
cscript.init(function (err) {
if (err) {
return done(err)
}
it('if cscript.exe fails to execute, try to run "where cscript.exe"', function(done) {
mockExecFile['cscript.exe'].calls.should.eql(0)
mockExecFile['where cscript.exe'].calls.should.eql(0)
mockExecFile['cscript.exe'].calls.should.eql(1)
mockExecFile['where cscript.exe'].calls.should.eql(1)
mockExecFile['cscript.exe'].err = new Error()
mockExecFile['cscript.exe'].err.code = 'ENOENT'
mockExecFile['where cscript.exe'].stdout = '123'
cscript.path().should.eql('123')
done()
})
})
cscript.init(function(err) {
if (err) {
return done(err)
}
beforeEach(function () {
mockFs = {
err: null,
calls: 0,
stat: function (name, cb) {
this.calls++
var self = this
setImmediate(function () {
cb(self.err, {})
})
},
}
mockExecFile['cscript.exe'].calls.should.eql(1)
mockExecFile['where cscript.exe'].calls.should.eql(1)
mockExecFile = function(command, args, options, callback) {
if (!mockExecFile[command]) {
throw new Error('unexpected command ' + command)
}
cscript.path().should.eql('123')
done()
})
})
mockExecFile[command].args = arguments
mockExecFile[command].calls++
beforeEach(function() {
mockFs = {
err: null,
calls: 0,
stat: function(name, cb) {
this.calls++
var self = this
setImmediate(function() {
cb(self.err, {})
})
},
}
if (typeof args === 'function') {
callback = args
args = undefined
options = undefined
}
mockExecFile = function(command, args, options, callback) {
if (!mockExecFile[command]) {
throw new Error('unexpected command ' + command)
}
if (typeof options === 'function') {
callback = options
args = undefined
options = undefined
}
mockExecFile[command].args = arguments
mockExecFile[command].calls++
if (typeof callback !== 'function') {
throw new Error('missing callback')
}
if (typeof args === 'function') {
callback = args
args = undefined
options = undefined
}
setImmediate(function () {
callback(mockExecFile[command].err, mockExecFile[command].stdout, mockExecFile[command].stderr)
})
}
if (typeof options === 'function') {
callback = options
args = undefined
options = undefined
}
mockExecFile['cscript.exe'] = {calls: 0, stdout: '', stderr: '', err: null}
mockExecFile['where cscript.exe'] = {calls: 0, stdout: '', stderr: '', err: null}
if (typeof callback !== 'function') {
throw new Error('missing callback')
}
cscript._mock(mockFs, mockExecFile, false)
})
setImmediate(function() {
callback(mockExecFile[command].err, mockExecFile[command].stdout, mockExecFile[command].stderr)
})
}
afterEach(function () {
cscript._mockReset()
})
mockExecFile['cscript.exe'] = { calls: 0, stdout: '', stderr: '', err: null }
mockExecFile['where cscript.exe'] = { calls: 0, stdout: '', stderr: '', err: null }
cscript._mock(mockFs, mockExecFile, false)
})
afterEach(function() {
cscript._mockReset()
})
})

@@ -12,54 +12,54 @@ /* eslint-disable max-len, no-unused-expressions */

it('removes all the listeners from stdout/stderr to avoid buffering output, but enjoys all the good cleanup code node.js has to offer', function(done) {
it('removes all the listeners from stdout/stderr to avoid buffering output, but enjoys all the good cleanup code node.js has to offer', function(done) {
var child = execFile()('node', [testScript], function(err, stdout, stderr) {
err.should.be.an.Error
stdout.should.eql('')
stderr.should.eql('')
done()
})
})
var child = execFile()('node', [testScript], function(err, stdout, stderr) {
err.should.be.an.Error
stdout.should.eql('')
stderr.should.eql('')
done()
})
})
it('does not buffer stdout', function(done) {
it('does not buffer stdout', function(done) {
var opts = {
bufferStderr: true,
}
var opts = {
bufferStderr: true,
}
var child = execFile(opts)('node', [testScript], function(err, stdout, stderr) {
err.should.be.an.Error
stdout.should.eql('')
stderr.should.containEql('throw new Error(\'error\')')
done()
})
})
var child = execFile(opts)('node', [testScript], function(err, stdout, stderr) {
err.should.be.an.Error
stdout.should.eql('')
stderr.should.containEql('throw new Error(\'error\')')
done()
})
})
it('does not buffer stderr', function(done) {
it('does not buffer stderr', function(done) {
var opts = {
bufferStdout: true,
}
var opts = {
bufferStdout: true,
}
var child = execFile(opts)('node', [testScript], function(err, stdout, stderr) {
err.should.be.an.Error
stdout.should.eql('123\n')
stderr.should.eql('')
done()
})
})
var child = execFile(opts)('node', [testScript], function(err, stdout, stderr) {
err.should.be.an.Error
stdout.should.eql('123\n')
stderr.should.eql('')
done()
})
})
it('buffers everything', function(done) {
it('buffers everything', function(done) {
var opts = {
bufferStdout: true,
bufferStderr: true,
}
var opts = {
bufferStdout: true,
bufferStderr: true,
}
var child = execFile(opts)('node', [testScript], function(err, stdout, stderr) {
err.should.be.an.Error
stdout.should.eql('123\n')
stderr.should.containEql('throw new Error(\'error\')')
done()
})
})
var child = execFile(opts)('node', [testScript], function(err, stdout, stderr) {
err.should.be.an.Error
stdout.should.eql('123\n')
stderr.should.containEql('throw new Error(\'error\')')
done()
})
})
})

@@ -6,106 +6,106 @@ // TODO need to find a better way to test the 32bit/64bit specific scenarios

describe('regedit', function () {
var baseKey = 'HKCU\\software\\ironSource\\regedit\\issues-test\\'
var key
describe('regedit', function() {
var baseKey = 'HKCU\\software\\ironSource\\regedit\\issues-test\\'
var key
// this test fails with a timeout because putValue callback is never invoked
it('putValue with empty string for value fails silently #8', function (done) {
index.createKey(key, function (err) {
if (err) {
return done(err)
}
it('putValue with empty string for value fails silently #8', function(done) {
var values = {}
index.createKey(key, function(err) {
if (err) {
return done(err)
}
values[key] = {'valName': {value: '', type: 'REG_SZ'}}
var values = {}
index.putValue(values, function (err) {
if (err) {
return done(err)
}
values[key] = { 'valName': { value: '', type: 'REG_SZ' } }
index.list(key, function(err, results) {
if (err) {
return done(err)
}
index.putValue(values, function(err) {
if (err) {
return done(err)
}
results.should.have.property(key)
.which.have.property('values')
.which.have.property('valName')
.which.have.property('value', '')
index.list(key, function(err, results) {
if (err) {
return done(err)
}
done()
})
})
})
})
results.should.have.property(key)
.which.have.property('values')
.which.have.property('valName')
.which.have.property('value', '')
it('can putValue REG_DWORD > 0x7fffffff #21', function (done) {
index.createKey(key, function (err) {
if (err) {
return done(err)
}
done()
})
})
})
var values = {}
})
values[key] = {'valName': {value: 0x80000000, type: 'REG_DWORD'}}
it('can putValue REG_DWORD > 0x7fffffff #21', function(done) {
index.createKey(key, function(err) {
if (err) {
return done(err)
}
index.putValue(values, function (err) {
if (err) {
return done(err)
}
var values = {}
index.list(key, function (err, results) {
if (err) {
return done(err)
}
values[key] = { 'valName': { value: 0x80000000, type: 'REG_DWORD' } }
results.should.have.property(key)
.which.have.property('values')
.which.have.property('valName')
.which.have.property('value', 0x80000000)
index.putValue(values, function(err) {
if (err) {
return done(err)
}
done()
})
})
})
})
index.list(key, function(err, results) {
if (err) {
return done(err)
}
it('can putValue REG_QWORD < 9007199254740993 #21', function (done) {
index.createKey(key, function (err) {
if (err) {
return done(err)
}
results.should.have.property(key)
.which.have.property('values')
.which.have.property('valName')
.which.have.property('value', 0x80000000)
var values = {}
done()
})
})
})
})
values[key] = {'valName': {value: 9007199254740993, type: 'REG_QWORD'}}
it('can putValue REG_QWORD < 9007199254740993 #21', function(done) {
index.createKey(key, function(err) {
if (err) {
return done(err)
}
index.putValue(values, function (err) {
if (err) {
return done(err)
}
var values = {}
index.list(key, function (err, results) {
if (err) {
return done(err)
}
values[key] = { 'valName': { value: 9007199254740993, type: 'REG_QWORD' } }
results.should.have.property(key)
.which.have.property('values')
.which.have.property('valName')
.which.have.property('value', 9007199254740992)
index.putValue(values, function(err) {
if (err) {
return done(err)
}
done()
})
index.list(key, function(err, results) {
if (err) {
return done(err)
}
})
})
})
results.should.have.property(key)
.which.have.property('values')
.which.have.property('valName')
.which.have.property('value', 9007199254740992)
beforeEach(function () {
key = baseKey + Date.now()
})
done()
})
})
})
})
beforeEach(function() {
key = baseKey + Date.now()
})
})

@@ -8,14 +8,14 @@ var cp = require('child_process')

describe.skip('json safe stream version', function () {
it('also escapes windows newline', function (done) {
cp.execFile('cscript', ['/NoLogo', vbsScript], function(err, stdout, stderr) {
if (err) {
return done(err)
}
describe.skip('json safe stream version', function() {
it('also escapes windows newline', function(done) {
cp.execFile('cscript', ['/NoLogo', vbsScript], function(err, stdout, stderr) {
if (err) {
return done(err)
}
JSON.parse(stdout).a.should.eql('"' + helper.ESCAPED_WIN_EOL + '测试\\')
JSON.parse(stdout).a.should.eql('"' + helper.ESCAPED_WIN_EOL + '测试\\')
done()
})
})
done()
})
})
})
console.log('123')
setTimeout(function () {
throw new Error('error')
setTimeout(function() {
throw new Error('error')
}, 1000)

@@ -6,46 +6,46 @@ /* eslint-disable no-unused-expressions */

describe('list', function () {
this.timeout(5000)
it('Streaming interface', function (done) {
var testKey = 'hkcu\\software'
describe('list', function() {
this.timeout(5000)
it('Streaming interface', function(done) {
var testKey = 'hkcu\\software'
// use non streaming interface to get expected results
index.list(testKey, function (err, expectedResults) {
index.list(testKey, function(err, expectedResults) {
var actualResults = {}
var error
index.list(testKey)
.once('error', function(e) {
should(e).be.an.Error
error = e
})
.on('data', function(d) {
actualResults[d.key] = d.data
}).once('finish', function () {
actualResults.should.eql(expectedResults)
done(error)
})
})
})
var actualResults = {}
var error
index.list(testKey)
.once('error', function(e) {
should(e).be.an.Error
error = e
})
.on('data', function(d) {
actualResults[d.key] = d.data
}).once('finish', function() {
actualResults.should.eql(expectedResults)
done(error)
})
})
})
it('works for multiple keys', function (done) {
var actualResults = {}
var keys = ['hklm', 'hkcu']
var error
it('works for multiple keys', function(done) {
var actualResults = {}
var keys = ['hklm', 'hkcu']
var error
// use non streaming interface to get expected results
index.list(keys, function (err, expectedResults) {
index.list(keys)
.once('error', function(e) {
error = e
index.list(keys, function(err, expectedResults) {
index.list(keys)
.once('error', function(e) {
error = e
})
.on('data', function(d) {
actualResults[d.key] = d.data
}).once('finish', function() {
actualResults.should.eql(expectedResults)
done(error)
})
})
})
})
.on('data', function(d) {
actualResults[d.key] = d.data
}).once('finish', function () {
actualResults.should.eql(expectedResults)
done(error)
})
})
})
})

@@ -8,692 +8,695 @@ /* eslint-disable no-unused-expressions */

function toLowerCase (str) {
return str.toLowerCase()
function toLowerCase(str) {
return str.toLowerCase()
}
describe('regedit', function () {
describe('list keys and values in a sub key', function () {
var target = 'HKLM\\software\\microsoft\\windows\\CurrentVersion'
describe('regedit', function() {
describe('list keys and values in a sub key', function() {
this.timeout(5000)
it(target, function (done) {
index.list(target, function(err, result) {
if (err) {
return done(err)
}
result.should.have.property(target)
var target = 'HKLM\\software\\microsoft\\windows\\CurrentVersion'
var key = result[target]
key.should.have.property('keys')
key.should.have.property('values')
key.keys.map(toLowerCase).should.containEql('policies')
it(target, function(done) {
index.list(target, function(err, result) {
if (err) {
return done(err)
}
key.values.should.have.property('ProgramFilesDir')
key.values.ProgramFilesDir.should.have.property('value')
key.values.ProgramFilesDir.value.indexOf('C:\\Program Files').should.eql(0)
key.values.ProgramFilesDir.should.have.property('type', 'REG_SZ')
done()
})
})
result.should.have.property(target)
it(target + ' 32bit', function (done) {
index.arch.list32(target, function(err, result) {
if (err) {
return done(err)
}
result.should.have.property(target)
var key = result[target]
var key = result[target]
key.should.have.property('keys')
key.should.have.property('values')
key.keys.map(toLowerCase).should.containEql('policies')
key.values.should.have.property('ProgramFilesDir')
key.values.ProgramFilesDir.should.have.property('value')
key.values.ProgramFilesDir.value.indexOf('C:\\Program Files').should.eql(0)
key.values.ProgramFilesDir.should.have.property('type', 'REG_SZ')
done()
})
})
key.should.have.property('keys')
key.should.have.property('values')
key.keys.map(toLowerCase).should.containEql('policies')
it(target + ' 64bit', function (done) {
index.arch.list64(target, function(err, result) {
if (err) {
return done(err)
}
result.should.have.property(target)
key.values.should.have.property('ProgramFilesDir')
key.values.ProgramFilesDir.should.have.property('value')
key.values.ProgramFilesDir.value.indexOf('C:\\Program Files').should.eql(0)
key.values.ProgramFilesDir.should.have.property('type', 'REG_SZ')
var key = result[target]
key.should.have.property('keys')
key.should.have.property('values')
key.keys.map(toLowerCase).should.containEql('policies')
done()
})
})
key.values.should.have.property('ProgramFilesDir')
key.values.ProgramFilesDir.should.have.property('value', 'C:\\Program Files')
key.values.ProgramFilesDir.should.have.property('type', 'REG_SZ')
done()
})
})
it(target + ' 32bit', function(done) {
this.timeout(5000)
index.arch.list32(target, function(err, result) {
if (err) {
return done(err)
}
it(target + ' arch auto pick', function (done) {
index.arch.list(target, function(err, result) {
if (err) {
return done(err)
}
result.should.have.property(target)
result.should.have.property(target)
var key = result[target]
key.should.have.property('keys')
key.should.have.property('values')
key.keys.map(toLowerCase).should.containEql('policies')
key.values.should.have.property('ProgramFilesDir')
key.values.ProgramFilesDir.should.have.property('value', 'C:\\Program Files')
key.values.ProgramFilesDir.should.have.property('type', 'REG_SZ')
done()
})
})
var key = result[target]
it('can be applied to several independant keys at once', function (done) {
index.list(['hklm', 'hkcu'], function (err, result) {
if (err) {
return done(err)
}
key.should.have.property('keys')
key.should.have.property('values')
key.keys.map(toLowerCase).should.containEql('policies')
result.should.have.property('hklm')
result.hklm.should.have.property('keys')
result.hklm.keys.map(toLowerCase).should.containEql('software')
key.values.should.have.property('ProgramFilesDir')
key.values.ProgramFilesDir.should.have.property('value')
key.values.ProgramFilesDir.value.indexOf('C:\\Program Files').should.eql(0)
key.values.ProgramFilesDir.should.have.property('type', 'REG_SZ')
result.should.have.property('hkcu')
result.hkcu.should.have.property('keys')
result.hkcu.keys.map(toLowerCase).should.containEql('software')
done()
})
})
done()
})
})
it(target + ' 64bit', function(done) {
index.arch.list64(target, function(err, result) {
if (err) {
return done(err)
}
it('handle spaces in registry keys', function (done) {
var key = 'HKCU\\Keyboard Layout'
index.list([key], function(err, result) {
result[key].should.have.property('keys')
result[key].keys.map(toLowerCase).should.containEql('preload')
result[key].keys.map(toLowerCase).should.containEql('substitutes')
result[key].keys.map(toLowerCase).should.containEql('toggle')
done()
})
})
result.should.have.property(target)
it.skip('reads unicode characters from the registry - need to manually create', function (done) {
var key = 'HKCU\\software\\ironsource\\'
var key = result[target]
index.list(key, function(err, result) {
if (err) {
return done(err)
}
result[key].should.have.property('keys')
result[key].keys.should.containEql('测试')
key.should.have.property('keys')
key.should.have.property('values')
key.keys.map(toLowerCase).should.containEql('policies')
done()
})
})
key.values.should.have.property('ProgramFilesDir')
key.values.ProgramFilesDir.should.have.property('value', 'C:\\Program Files')
key.values.ProgramFilesDir.should.have.property('type', 'REG_SZ')
it('will fail for unknown hives', function(done) {
index.list('lala\\software', function(err, result) {
should(err).not.be.null
err.message.should.eql('unsupported hive')
done()
})
})
done()
})
})
it('lists default values', function (done) {
index.list('HKCR\\Directory\\shell\\cmd\\command', function (err, results) {
if (err) {
return done(err)
}
results['HKCR\\Directory\\shell\\cmd\\command'].should.have.property('values')
results['HKCR\\Directory\\shell\\cmd\\command'].values.should.have.property('')
done()
})
})
})
it(target + ' arch auto pick', function(done) {
index.arch.list(target, function(err, result) {
if (err) {
return done(err)
}
describe('create keys', function () {
var key = 'HKCU\\software\\ironSource\\regedit\\test\\'
var now = Date.now().toString()
result.should.have.property(target)
it('will throw an error if we dont have permission', function (done) {
index.createKey('HKLM\\SECURITY\\unauthorized', function(err, result) {
err.should.be.an.Error
err.message.should.eql('access is denied')
done()
})
})
var key = result[target]
it(key + now, function (done) {
index.createKey(key + now, function(err) {
if (err) {
return done(err)
}
key.should.have.property('keys')
key.should.have.property('values')
key.keys.map(toLowerCase).should.containEql('policies')
key.values.should.have.property('ProgramFilesDir')
key.values.ProgramFilesDir.should.have.property('value', 'C:\\Program Files')
key.values.ProgramFilesDir.should.have.property('type', 'REG_SZ')
done()
})
})
it('can be applied to several independant keys at once', function(done) {
index.list(['hklm', 'hkcu'], function(err, result) {
if (err) {
return done(err)
}
result.should.have.property('hklm')
result.hklm.should.have.property('keys')
result.hklm.keys.map(toLowerCase).should.containEql('software')
result.should.have.property('hkcu')
result.hkcu.should.have.property('keys')
result.hkcu.keys.map(toLowerCase).should.containEql('software')
done()
})
})
it('handle spaces in registry keys', function(done) {
var key = 'HKCU\\Keyboard Layout'
index.list([key], function(err, result) {
result[key].should.have.property('keys')
result[key].keys.map(toLowerCase).should.containEql('preload')
result[key].keys.map(toLowerCase).should.containEql('substitutes')
result[key].keys.map(toLowerCase).should.containEql('toggle')
done()
})
})
it.skip('reads unicode characters from the registry - need to manually create', function(done) {
var key = 'HKCU\\software\\ironsource\\'
index.list(key, function(err, result) {
if (err) {
return done(err)
}
result[key].should.have.property('keys')
result[key].keys.should.containEql('测试')
done()
})
})
it('will fail for unknown hives', function(done) {
index.list('lala\\software', function(err, result) {
should(err).not.be.null
err.message.should.eql('unsupported hive')
done()
})
})
it('lists default values', function(done) {
index.list('HKCR\\Directory\\shell\\cmd\\command', function(err, results) {
if (err) {
return done(err)
}
results['HKCR\\Directory\\shell\\cmd\\command'].should.have.property('values')
results['HKCR\\Directory\\shell\\cmd\\command'].values.should.have.property('')
done()
})
})
})
describe('create keys', function() {
var key = 'HKCU\\software\\ironSource\\regedit\\test\\'
var now = Date.now().toString()
it('will throw an error if we dont have permission', function(done) {
index.createKey('HKLM\\SECURITY\\unauthorized', function(err, result) {
err.should.be.an.Error
err.message.should.eql('access is denied')
done()
})
})
it(key + now, function(done) {
index.createKey(key + now, function(err) {
if (err) {
return done(err)
}
// testing using the module itself is not the best idea...
index.list(key, function(err, result) {
if (err) {
return done(err)
}
index.list(key, function(err, result) {
if (err) {
return done(err)
}
result[key].keys.should.containEql(now)
done()
})
})
})
result[key].keys.should.containEql(now)
done()
})
})
})
it(key + now + '测试', function(done) {
index.createKey(key + now + '测试', function (err) {
if (err) {
return done(err)
}
it(key + now + '测试', function(done) {
index.createKey(key + now + '测试', function(err) {
if (err) {
return done(err)
}
index.list(key, function (err, results) {
if (err) {
return done(err)
}
results[key].should.have.property('keys')
results[key].keys.should.containEql(now + '测试')
index.list(key, function(err, results) {
if (err) {
return done(err)
}
done()
})
})
})
results[key].should.have.property('keys')
results[key].keys.should.containEql(now + '测试')
it(key + now + ' S', function (done) {
index.arch.createKey(key + now, function(err) {
if (err) {
return done(err)
}
done()
})
})
})
it(key + now + ' S', function(done) {
index.arch.createKey(key + now, function(err) {
if (err) {
return done(err)
}
// testing using the module itself is not the best idea...
index.arch.list(key, function(err, result) {
if (err) {
return done(err)
}
index.arch.list(key, function(err, result) {
if (err) {
return done(err)
}
result[key].keys.should.containEql(now)
done()
})
})
})
result[key].keys.should.containEql(now)
done()
})
})
})
it(key + now + ' 32bit', function (done) {
index.arch.createKey32(key + now, function(err) {
if (err) {
return done(err)
}
it(key + now + ' 32bit', function(done) {
index.arch.createKey32(key + now, function(err) {
if (err) {
return done(err)
}
// testing using the module itself is not the best idea...
index.arch.list32(key, function(err, result) {
if (err) {
return done(err)
}
index.arch.list32(key, function(err, result) {
if (err) {
return done(err)
}
result[key].keys.should.containEql(now)
done()
})
})
})
result[key].keys.should.containEql(now)
done()
})
})
})
it(key + now + ' 64bit', function (done) {
index.arch.createKey64(key + now, function(err) {
if (err) {
return done(err)
}
it(key + now + ' 64bit', function(done) {
index.arch.createKey64(key + now, function(err) {
if (err) {
return done(err)
}
// testing using the module itself is not the best idea...
index.arch.list64(key, function(err, result) {
if (err) {
return done(err)
}
index.arch.list64(key, function(err, result) {
if (err) {
return done(err)
}
result[key].keys.should.containEql(now)
done()
})
})
})
result[key].keys.should.containEql(now)
done()
})
})
})
afterEach(function () {
now = Date.now().toString()
})
})
afterEach(function() {
now = Date.now().toString()
})
})
describe('delete keys', function () {
var key = 'HKCU\\software\\ironSource\\regedit\\test\\'
var now = Date.now().toString()
it('will throw an error if we attempt to delete a key without permission', function (done) {
index.deleteKey('HKLM\\SECURITY', function(err) {
err.should.be.an.Error
err.message.should.eql('access is denied')
done()
})
})
describe('delete keys', function() {
var key = 'HKCU\\software\\ironSource\\regedit\\test\\'
var now = Date.now().toString()
it(key + now, function (done) {
index.createKey(key + now, function(err) {
if (err) {
return done(err)
}
it('will throw an error if we attempt to delete a key without permission', function(done) {
index.deleteKey('HKLM\\SECURITY', function(err) {
err.should.be.an.Error
err.message.should.eql('access is denied')
done()
})
})
index.list(key, function(err, result) {
if (err) {
return done(err)
}
it(key + now, function(done) {
index.createKey(key + now, function(err) {
if (err) {
return done(err)
}
result[key].keys.should.containEql(now)
index.list(key, function(err, result) {
if (err) {
return done(err)
}
index.deleteKey(key + now, function(err) {
if (err) {
return done(err)
}
result[key].keys.should.containEql(now)
index.list(key, function(err, result1) {
if (err) {
return done(err)
}
index.deleteKey(key + now, function(err) {
if (err) {
return done(err)
}
result1.should.not.containEql(now)
done()
})
})
})
})
})
index.list(key, function(err, result1) {
if (err) {
return done(err)
}
it(key + now + ' S', function (done) {
index.arch.createKey(key + now, function(err) {
if (err) {
return done(err)
}
result1.should.not.containEql(now)
done()
})
})
})
})
})
index.arch.list(key, function(err, result) {
if (err) {
return done(err)
}
it(key + now + ' S', function(done) {
index.arch.createKey(key + now, function(err) {
if (err) {
return done(err)
}
result[key].keys.should.containEql(now)
index.arch.list(key, function(err, result) {
if (err) {
return done(err)
}
index.arch.deleteKey(key + now, function(err) {
if (err) {
return done(err)
}
result[key].keys.should.containEql(now)
index.list(key, function(err, result1) {
if (err) {
return done(err)
}
index.arch.deleteKey(key + now, function(err) {
if (err) {
return done(err)
}
result1.should.not.containEql(now)
done()
})
})
})
})
})
index.list(key, function(err, result1) {
if (err) {
return done(err)
}
it(key + now + ' 32bit', function (done) {
index.arch.createKey32(key + now, function(err) {
if (err) {
return done(err)
}
result1.should.not.containEql(now)
done()
})
})
})
})
})
index.arch.list32(key, function(err, result) {
if (err) {
return done(err)
}
it(key + now + ' 32bit', function(done) {
index.arch.createKey32(key + now, function(err) {
if (err) {
return done(err)
}
result[key].keys.should.containEql(now)
index.arch.list32(key, function(err, result) {
if (err) {
return done(err)
}
index.arch.deleteKey32(key + now, function(err) {
if (err) {
return done(err)
}
result[key].keys.should.containEql(now)
index.list(key, function(err, result1) {
if (err) {
return done(err)
}
index.arch.deleteKey32(key + now, function(err) {
if (err) {
return done(err)
}
result1.should.not.containEql(now)
done()
})
})
})
})
})
index.list(key, function(err, result1) {
if (err) {
return done(err)
}
it(key + now + ' 64bit', function (done) {
index.arch.createKey64(key + now, function(err) {
if (err) {
return done(err)
}
result1.should.not.containEql(now)
done()
})
})
})
})
})
index.arch.list64(key, function(err, result) {
if (err) {
return done(err)
}
it(key + now + ' 64bit', function(done) {
index.arch.createKey64(key + now, function(err) {
if (err) {
return done(err)
}
result[key].keys.should.containEql(now)
index.arch.list64(key, function(err, result) {
if (err) {
return done(err)
}
index.arch.deleteKey64(key + now, function(err) {
if (err) {
return done(err)
}
result[key].keys.should.containEql(now)
index.list(key, function(err, result1) {
if (err) {
return done(err)
}
index.arch.deleteKey64(key + now, function(err) {
if (err) {
return done(err)
}
result1.should.not.containEql(now)
done()
})
})
})
})
})
index.list(key, function(err, result1) {
if (err) {
return done(err)
}
afterEach(function () {
now = Date.now().toString()
})
})
result1.should.not.containEql(now)
done()
})
})
})
})
})
describe('put values', function () {
var key = 'HKCU\\software\\ironSource\\regedit\\test\\'
var now = Date.now().toString()
var map = {}
it('in ' + key + now, function (done) {
index.putValue(map, function(err) {
if (err) {
return done(err)
}
index.list(key + now, function(err, result) {
if (err) {
console.error(result)
return done(err)
}
var values = result[key + now].values
afterEach(function() {
now = Date.now().toString()
})
})
values.should.have.property('a key')
values['a key'].type.should.eql('REG_SZ')
values['a key'].value.should.eql('some string')
describe('put values', function() {
var key = 'HKCU\\software\\ironSource\\regedit\\test\\'
var now = Date.now().toString()
var map = {}
values.should.have.property('b')
values.b.type.should.eql('REG_BINARY')
values.b.value.should.eql([1, 2, 3])
values.should.have.property('c')
values.c.type.should.eql('REG_DWORD')
values.c.value.should.eql(10)
it('in ' + key + now, function(done) {
index.putValue(map, function(err) {
if (err) {
return done(err)
}
values.should.have.property('d')
values.d.type.should.eql('REG_QWORD')
values.d.value.should.eql(100)
index.list(key + now, function(err, result) {
if (err) {
console.error(result)
return done(err)
}
values.should.have.property('e')
values.e.type.should.eql('REG_EXPAND_SZ')
values.e.value.should.eql('expand_string')
values.should.have.property('f')
values.f.type.should.eql('REG_MULTI_SZ')
values.f.value.should.eql(['a', 'b', 'c'])
var values = result[key + now].values
values.should.have.property('测试')
values['测试'].type.should.eql('REG_SZ')
values['测试'].value.should.eql('值 test for non-English environment')
values.should.have.property('a key')
values['a key'].type.should.eql('REG_SZ')
values['a key'].value.should.eql('some string')
values.should.have.property('newline')
values.newline.type.should.eql('REG_SZ')
values.newline.value.should.eql('new\\nline')
values.should.have.property('b')
values.b.type.should.eql('REG_BINARY')
values.b.value.should.eql([1, 2, 3])
done()
})
})
})
values.should.have.property('c')
values.c.type.should.eql('REG_DWORD')
values.c.value.should.eql(10)
it('default value in ' + key + now, function(done) {
var values = {}
values[key + now] = {
'default': {
type: 'reg_default',
value: 'default',
},
}
index.putValue(values, function(err) {
index.list(key + now, function (err, results) {
if (err) {
return done(err)
}
results[key + now].should.have.property('values')
results[key + now].values.should.have.property('', {
type: 'REG_SZ',
value: 'default',
})
done()
})
})
})
values.should.have.property('d')
values.d.type.should.eql('REG_QWORD')
values.d.value.should.eql(100)
it('in ' + key + now + ' S', function (done) {
index.arch.putValue(map, function(err) {
if (err) {
return done(err)
}
index.arch.list(key + now, function(err, result) {
if (err) {
return done(err)
}
var values = result[key + now].values
values.should.have.property('e')
values.e.type.should.eql('REG_EXPAND_SZ')
values.e.value.should.eql('expand_string')
values.should.have.property('a key')
values['a key'].type.should.eql('REG_SZ')
values['a key'].value.should.eql('some string')
values.should.have.property('f')
values.f.type.should.eql('REG_MULTI_SZ')
values.f.value.should.eql(['a', 'b', 'c'])
values.should.have.property('b')
values.b.type.should.eql('REG_BINARY')
values.b.value.should.eql([1, 2, 3])
values.should.have.property('c')
values.c.type.should.eql('REG_DWORD')
values.c.value.should.eql(10)
values.should.have.property('测试')
values['测试'].type.should.eql('REG_SZ')
values['测试'].value.should.eql('值 test for non-English environment')
values.should.have.property('d')
values.d.type.should.eql('REG_QWORD')
values.d.value.should.eql(100)
values.should.have.property('newline')
values.newline.type.should.eql('REG_SZ')
values.newline.value.should.eql('new\\nline')
values.should.have.property('e')
values.e.type.should.eql('REG_EXPAND_SZ')
values.e.value.should.eql('expand_string')
values.should.have.property('f')
values.f.type.should.eql('REG_MULTI_SZ')
values.f.value.should.eql(['a', 'b', 'c'])
done()
})
})
})
values.should.have.property('测试')
values['测试'].type.should.eql('REG_SZ')
values['测试'].value.should.eql('值 test for non-English environment')
it('default value in ' + key + now, function(done) {
var values = {}
values[key + now] = {
'default': {
type: 'reg_default',
value: 'default',
},
}
values.should.have.property('newline')
values.newline.type.should.eql('REG_SZ')
values.newline.value.should.eql('new\\nline')
index.putValue(values, function(err) {
index.list(key + now, function(err, results) {
if (err) {
return done(err)
}
results[key + now].should.have.property('values')
results[key + now].values.should.have.property('', {
type: 'REG_SZ',
value: 'default',
})
done()
})
})
})
done()
})
})
})
it('in ' + key + now + ' S', function(done) {
index.arch.putValue(map, function(err) {
if (err) {
return done(err)
}
it('in ' + key + now + ' 32bit', function (done) {
index.arch.putValue32(map, function(err) {
if (err) {
return done(err)
}
index.arch.list32(key + now, function(err, result) {
if (err) {
return done(err)
}
var values = result[key + now].values
index.arch.list(key + now, function(err, result) {
if (err) {
return done(err)
}
var values = result[key + now].values
values.should.have.property('a key')
values['a key'].type.should.eql('REG_SZ')
values['a key'].value.should.eql('some string')
values.should.have.property('a key')
values['a key'].type.should.eql('REG_SZ')
values['a key'].value.should.eql('some string')
values.should.have.property('b')
values.b.type.should.eql('REG_BINARY')
values.b.value.should.eql([1, 2, 3])
values.should.have.property('c')
values.c.type.should.eql('REG_DWORD')
values.c.value.should.eql(10)
values.should.have.property('b')
values.b.type.should.eql('REG_BINARY')
values.b.value.should.eql([1, 2, 3])
values.should.have.property('d')
values.d.type.should.eql('REG_QWORD')
values.d.value.should.eql(100)
values.should.have.property('c')
values.c.type.should.eql('REG_DWORD')
values.c.value.should.eql(10)
values.should.have.property('e')
values.e.type.should.eql('REG_EXPAND_SZ')
values.e.value.should.eql('expand_string')
values.should.have.property('f')
values.f.type.should.eql('REG_MULTI_SZ')
values.f.value.should.eql(['a', 'b', 'c'])
values.should.have.property('d')
values.d.type.should.eql('REG_QWORD')
values.d.value.should.eql(100)
values.should.have.property('测试')
values['测试'].type.should.eql('REG_SZ')
values['测试'].value.should.eql('值 test for non-English environment')
values.should.have.property('e')
values.e.type.should.eql('REG_EXPAND_SZ')
values.e.value.should.eql('expand_string')
values.should.have.property('newline')
values.newline.type.should.eql('REG_SZ')
values.newline.value.should.eql('new\\nline')
values.should.have.property('f')
values.f.type.should.eql('REG_MULTI_SZ')
values.f.value.should.eql(['a', 'b', 'c'])
done()
})
})
})
values.should.have.property('测试')
values['测试'].type.should.eql('REG_SZ')
values['测试'].value.should.eql('值 test for non-English environment')
it('in ' + key + now + '64bit', function (done) {
index.arch.putValue64(map, function(err) {
if (err) {
return done(err)
}
index.arch.list64(key + now, function(err, result) {
if (err) {
return done(err)
}
var values = result[key + now].values
values.should.have.property('newline')
values.newline.type.should.eql('REG_SZ')
values.newline.value.should.eql('new\\nline')
values.should.have.property('a key')
values['a key'].type.should.eql('REG_SZ')
values['a key'].value.should.eql('some string')
done()
})
})
})
values.should.have.property('b')
values.b.type.should.eql('REG_BINARY')
values.b.value.should.eql([1, 2, 3])
values.should.have.property('c')
values.c.type.should.eql('REG_DWORD')
values.c.value.should.eql(10)
it('in ' + key + now + ' 32bit', function(done) {
index.arch.putValue32(map, function(err) {
if (err) {
return done(err)
}
values.should.have.property('d')
values.d.type.should.eql('REG_QWORD')
values.d.value.should.eql(100)
index.arch.list32(key + now, function(err, result) {
if (err) {
return done(err)
}
var values = result[key + now].values
values.should.have.property('e')
values.e.type.should.eql('REG_EXPAND_SZ')
values.e.value.should.eql('expand_string')
values.should.have.property('f')
values.f.type.should.eql('REG_MULTI_SZ')
values.f.value.should.eql(['a', 'b', 'c'])
values.should.have.property('a key')
values['a key'].type.should.eql('REG_SZ')
values['a key'].value.should.eql('some string')
values.should.have.property('测试')
values['测试'].type.should.eql('REG_SZ')
values['测试'].value.should.eql('值 test for non-English environment')
values.should.have.property('b')
values.b.type.should.eql('REG_BINARY')
values.b.value.should.eql([1, 2, 3])
values.should.have.property('newline')
values.newline.type.should.eql('REG_SZ')
values.newline.value.should.eql('new\\nline')
values.should.have.property('c')
values.c.type.should.eql('REG_DWORD')
values.c.value.should.eql(10)
done()
})
})
})
values.should.have.property('d')
values.d.type.should.eql('REG_QWORD')
values.d.value.should.eql(100)
beforeEach(function (done) {
index.createKey(key + now, done)
map[key + now] = {
'a key': {
type: 'reg_sz',
value: 'some string',
},
values.should.have.property('e')
values.e.type.should.eql('REG_EXPAND_SZ')
values.e.value.should.eql('expand_string')
'b': {
type: 'reg_binary',
value: [1, 2, 3],
},
values.should.have.property('f')
values.f.type.should.eql('REG_MULTI_SZ')
values.f.value.should.eql(['a', 'b', 'c'])
'c': {
type: 'reg_dword',
value: 10,
},
values.should.have.property('测试')
values['测试'].type.should.eql('REG_SZ')
values['测试'].value.should.eql('值 test for non-English environment')
'd': {
type: 'reg_qword',
value: 100,
},
values.should.have.property('newline')
values.newline.type.should.eql('REG_SZ')
values.newline.value.should.eql('new\\nline')
'e': {
type: 'reg_expand_sz',
value: 'expand_string',
},
done()
})
})
})
'f': {
type: 'reg_multi_sz',
value: ['a', 'b', 'c'],
},
it('in ' + key + now + '64bit', function(done) {
index.arch.putValue64(map, function(err) {
if (err) {
return done(err)
}
'测试': {
type: 'reg_sz',
value: '值 test for non-English environment',
},
index.arch.list64(key + now, function(err, result) {
if (err) {
return done(err)
}
var values = result[key + now].values
'newline': {
type: 'reg_sz',
value: 'new\nline',
},
}
})
values.should.have.property('a key')
values['a key'].type.should.eql('REG_SZ')
values['a key'].value.should.eql('some string')
afterEach(function () {
now = Date.now().toString()
})
})
values.should.have.property('b')
values.b.type.should.eql('REG_BINARY')
values.b.value.should.eql([1, 2, 3])
values.should.have.property('c')
values.c.type.should.eql('REG_DWORD')
values.c.value.should.eql(10)
values.should.have.property('d')
values.d.type.should.eql('REG_QWORD')
values.d.value.should.eql(100)
values.should.have.property('e')
values.e.type.should.eql('REG_EXPAND_SZ')
values.e.value.should.eql('expand_string')
values.should.have.property('f')
values.f.type.should.eql('REG_MULTI_SZ')
values.f.value.should.eql(['a', 'b', 'c'])
values.should.have.property('测试')
values['测试'].type.should.eql('REG_SZ')
values['测试'].value.should.eql('值 test for non-English environment')
values.should.have.property('newline')
values.newline.type.should.eql('REG_SZ')
values.newline.value.should.eql('new\\nline')
done()
})
})
})
beforeEach(function(done) {
index.createKey(key + now, done)
map[key + now] = {
'a key': {
type: 'reg_sz',
value: 'some string',
},
'b': {
type: 'reg_binary',
value: [1, 2, 3],
},
'c': {
type: 'reg_dword',
value: 10,
},
'd': {
type: 'reg_qword',
value: 100,
},
'e': {
type: 'reg_expand_sz',
value: 'expand_string',
},
'f': {
type: 'reg_multi_sz',
value: ['a', 'b', 'c'],
},
'测试': {
type: 'reg_sz',
value: '值 test for non-English environment',
},
'newline': {
type: 'reg_sz',
value: 'new\nline',
},
}
})
afterEach(function() {
now = Date.now().toString()
})
})
})
var parsed = require('./parsed.json')
for (var i = 0; i < parsed.length; i++) {
var entry = parsed[i]
console.log('var e%d = new Error(\'%s\')', i, entry.error)
console.log('e%d.description = \'%s\'', i, entry.description)
console.log('e%d.code = %d', i, entry.code)
console.log('errors[%d] = e%d', entry.code, i)
var entry = parsed[i]
console.log('var e%d = new Error(\'%s\')', i, entry.error)
console.log('e%d.description = \'%s\'', i, entry.description)
console.log('e%d.code = %d', i, entry.code)
console.log('errors[%d] = e%d', entry.code, i)
}

@@ -14,7 +14,7 @@ /* eslint-disable max-len */

if (start === -1) {
throw new Error('missing injection start marker')
throw new Error('missing injection start marker')
}
if (end === -1) {
throw new Error('missing injection end marker')
throw new Error('missing injection end marker')
}

@@ -21,0 +21,0 @@

@@ -9,17 +9,17 @@ var fs = require('fs')

for (var i = 0; i < errors.length; i++) {
var splitted = errors[i].split('\n')
var splitted = errors[i].split('\n')
var result = {
error: 'wbem' + splitted[0],
code: parseInt(splitted[1]),
description: splitted[2],
}
var result = {
error: 'wbem' + splitted[0],
code: parseInt(splitted[1]),
description: splitted[2],
}
if (result.description) {
result.description = result.description.replace(/'/g, '\\\'')
}
if (result.description) {
result.description = result.description.replace(/'/g, '\\\'')
}
results.push(result)
results.push(result)
}
console.log(JSON.stringify(results))
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc