[test api] Make the format capable of sub-objects.

master
indexzero 2015-09-20 00:26:34 -07:00
parent 04c0f3a001
commit 0358545ae5
2 changed files with 23 additions and 8 deletions

View File

@ -168,11 +168,14 @@ File.prototype.stringify = function () {
if (this.secure) {
data = Object.keys(data).reduce(function (acc, key) {
var value = self.format.stringify(data[key]);
acc[key] = cipherConvert(value, {
acc[key] = {
alg: self.secure.alg,
secret: self.secure.secret,
encs: { input: 'utf8', output: 'hex' }
});
value: cipherConvert(value, {
alg: self.secure.alg,
secret: self.secure.secret,
encs: { input: 'utf8', output: 'hex' }
})
}
return acc;
}, {});
@ -195,8 +198,8 @@ File.prototype.parse = function (contents) {
}
return Object.keys(parsed).reduce(function (acc, key) {
var decrypted = cipherConvert(parsed[key], {
alg: self.secure.alg,
var decrypted = cipherConvert(parsed[key].value, {
alg: parsed[key].alg || self.secure.alg,
secret: self.secure.secret,
encs: { input: 'hex', output: 'utf8' }
});

View File

@ -226,7 +226,7 @@ vows.describe('nconf/stores/file').addBatch({
"When using the nconf file store": {
topic: function () {
var secureStore = new nconf.File({
file: 'mock-file-path.json',
file: path.join(__dirname, '..', 'fixtures', 'secure.json'),
secure: 'super-secretzzz'
});
@ -236,13 +236,25 @@ vows.describe('nconf/stores/file').addBatch({
"the stringify() method should encrypt properly": function (store) {
var contents = JSON.parse(store.stringify());
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) {
var contents = store.stringify();
var parsed = store.parse(contents);
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);