| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699 |
- /* eslint-disable no-unused-expressions */
- // TODO need to find a better way to test the 32bit/64bit specific scenarios
- var index = require('../index')
- var should = require('should')
- 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'
- it(target, function (done) {
- index.list(target, function(err, result) {
- if (err) {
- return done(err)
- }
-
- 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')
- key.values.ProgramFilesDir.value.indexOf('C:\\Program Files').should.eql(0)
- key.values.ProgramFilesDir.should.have.property('type', 'REG_SZ')
-
- done()
- })
- })
- 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]
-
- 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()
- })
- })
- it(target + ' 64bit', function (done) {
- index.arch.list64(target, function(err, result) {
- if (err) {
- return done(err)
- }
-
- 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()
- })
- })
- it(target + ' arch auto pick', function (done) {
- index.arch.list(target, function(err, result) {
- if (err) {
- return done(err)
- }
-
- 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()
- })
- })
- 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)
- }
- result[key].keys.should.containEql(now)
- done()
- })
- })
- })
- 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 + '测试')
- 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)
- }
- 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)
- }
-
- // testing using the module itself is not the best idea...
- index.arch.list32(key, function(err, result) {
- if (err) {
- return done(err)
- }
- 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)
- }
-
- // testing using the module itself is not the best idea...
- index.arch.list64(key, function(err, result) {
- if (err) {
- return done(err)
- }
- result[key].keys.should.containEql(now)
- done()
- })
- })
- })
- 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()
- })
- })
- it(key + now, function (done) {
- index.createKey(key + now, function(err) {
- if (err) {
- return done(err)
- }
- index.list(key, function(err, result) {
- if (err) {
- return done(err)
- }
- result[key].keys.should.containEql(now)
- index.deleteKey(key + now, function(err) {
- if (err) {
- return done(err)
- }
- index.list(key, function(err, result1) {
- if (err) {
- return done(err)
- }
- result1.should.not.containEql(now)
- done()
- })
- })
- })
- })
- })
- it(key + now + ' S', function (done) {
- index.arch.createKey(key + now, function(err) {
- if (err) {
- return done(err)
- }
- index.arch.list(key, function(err, result) {
- if (err) {
- return done(err)
- }
- result[key].keys.should.containEql(now)
- index.arch.deleteKey(key + now, function(err) {
- if (err) {
- return done(err)
- }
- index.list(key, function(err, result1) {
- if (err) {
- return done(err)
- }
- result1.should.not.containEql(now)
- done()
- })
- })
- })
- })
- })
- it(key + now + ' 32bit', function (done) {
- index.arch.createKey32(key + now, function(err) {
- if (err) {
- return done(err)
- }
- index.arch.list32(key, function(err, result) {
- if (err) {
- return done(err)
- }
- result[key].keys.should.containEql(now)
- index.arch.deleteKey32(key + now, function(err) {
- if (err) {
- return done(err)
- }
- index.list(key, function(err, result1) {
- if (err) {
- return done(err)
- }
- result1.should.not.containEql(now)
- done()
- })
- })
- })
- })
- })
- it(key + now + ' 64bit', function (done) {
- index.arch.createKey64(key + now, function(err) {
- if (err) {
- return done(err)
- }
- index.arch.list64(key, function(err, result) {
- if (err) {
- return done(err)
- }
- result[key].keys.should.containEql(now)
- index.arch.deleteKey64(key + now, function(err) {
- if (err) {
- return done(err)
- }
- index.list(key, function(err, result1) {
- if (err) {
- return done(err)
- }
- result1.should.not.containEql(now)
- done()
- })
- })
- })
- })
- })
- afterEach(function () {
- now = Date.now().toString()
- })
- })
- 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
- 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('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()
- })
- })
- })
- 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()
- })
- })
- })
- 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('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('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()
- })
- })
- })
- 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
- 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('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()
- })
- })
- })
- 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('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('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()
- })
- })
- })
|