[test api] Make the format capable of sub-objects.
This commit is contained in:
parent
04c0f3a001
commit
0358545ae5
2 changed files with 23 additions and 8 deletions
|
@ -168,11 +168,14 @@ File.prototype.stringify = function () {
|
||||||
if (this.secure) {
|
if (this.secure) {
|
||||||
data = Object.keys(data).reduce(function (acc, key) {
|
data = Object.keys(data).reduce(function (acc, key) {
|
||||||
var value = self.format.stringify(data[key]);
|
var value = self.format.stringify(data[key]);
|
||||||
acc[key] = cipherConvert(value, {
|
acc[key] = {
|
||||||
alg: self.secure.alg,
|
alg: self.secure.alg,
|
||||||
secret: self.secure.secret,
|
value: cipherConvert(value, {
|
||||||
encs: { input: 'utf8', output: 'hex' }
|
alg: self.secure.alg,
|
||||||
});
|
secret: self.secure.secret,
|
||||||
|
encs: { input: 'utf8', output: 'hex' }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
|
@ -195,8 +198,8 @@ File.prototype.parse = function (contents) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return Object.keys(parsed).reduce(function (acc, key) {
|
return Object.keys(parsed).reduce(function (acc, key) {
|
||||||
var decrypted = cipherConvert(parsed[key], {
|
var decrypted = cipherConvert(parsed[key].value, {
|
||||||
alg: self.secure.alg,
|
alg: parsed[key].alg || self.secure.alg,
|
||||||
secret: self.secure.secret,
|
secret: self.secure.secret,
|
||||||
encs: { input: 'hex', output: 'utf8' }
|
encs: { input: 'hex', output: 'utf8' }
|
||||||
});
|
});
|
||||||
|
|
|
@ -226,7 +226,7 @@ vows.describe('nconf/stores/file').addBatch({
|
||||||
"When using the nconf file store": {
|
"When using the nconf file store": {
|
||||||
topic: function () {
|
topic: function () {
|
||||||
var secureStore = new nconf.File({
|
var secureStore = new nconf.File({
|
||||||
file: 'mock-file-path.json',
|
file: path.join(__dirname, '..', 'fixtures', 'secure.json'),
|
||||||
secure: 'super-secretzzz'
|
secure: 'super-secretzzz'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -236,13 +236,25 @@ vows.describe('nconf/stores/file').addBatch({
|
||||||
"the stringify() method should encrypt properly": function (store) {
|
"the stringify() method should encrypt properly": function (store) {
|
||||||
var contents = JSON.parse(store.stringify());
|
var contents = JSON.parse(store.stringify());
|
||||||
Object.keys(data).forEach(function (key) {
|
Object.keys(data).forEach(function (key) {
|
||||||
assert.isString(contents[key]);
|
assert.isObject(contents[key]);
|
||||||
|
assert.isString(contents[key].value);
|
||||||
|
assert.equal(contents[key].alg, 'aes-256-ctr');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
"the parse() method should decrypt properly": function (store) {
|
"the parse() method should decrypt properly": function (store) {
|
||||||
var contents = store.stringify();
|
var contents = store.stringify();
|
||||||
var parsed = store.parse(contents);
|
var parsed = store.parse(contents);
|
||||||
assert.deepEqual(parsed, data);
|
assert.deepEqual(parsed, data);
|
||||||
|
},
|
||||||
|
"the load() method should decrypt properly": function (store) {
|
||||||
|
store.load(function (err, loaded) {
|
||||||
|
assert.isNull(err);
|
||||||
|
assert.deepEqual(loaded, data);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
"the loadSync() method should decrypt properly": function (store) {
|
||||||
|
var loaded = store.loadSync()
|
||||||
|
assert.deepEqual(loaded, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).export(module);
|
}).export(module);
|
||||||
|
|
Loading…
Reference in a new issue