2017-09-01 04:45:51 +00:00
|
|
|
const { decryptConfig } = require('../../lib/config/decrypt.js');
|
|
|
|
const logger = require('../_fixtures/logger');
|
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
const privateKey = fs.readFileSync('test/_fixtures/keys/private.pem');
|
|
|
|
|
2017-11-03 06:51:44 +00:00
|
|
|
describe('config/decrypt', () => {
|
|
|
|
describe('decryptConfig()', () => {
|
2017-09-01 04:45:51 +00:00
|
|
|
let config;
|
|
|
|
beforeEach(() => {
|
2017-11-03 06:51:44 +00:00
|
|
|
config = {};
|
2017-09-01 04:45:51 +00:00
|
|
|
});
|
|
|
|
it('returns empty with no privateKey', () => {
|
|
|
|
delete config.encrypted;
|
2017-11-03 06:51:44 +00:00
|
|
|
const res = decryptConfig(config, logger);
|
2017-09-01 04:45:51 +00:00
|
|
|
expect(res).toMatchObject(config);
|
|
|
|
});
|
|
|
|
it('warns if no privateKey found', () => {
|
|
|
|
config.encrypted = { a: '1' };
|
2017-11-03 06:51:44 +00:00
|
|
|
const res = decryptConfig(config, logger);
|
2017-09-01 04:45:51 +00:00
|
|
|
expect(res.encrypted).not.toBeDefined();
|
|
|
|
expect(res.a).not.toBeDefined();
|
|
|
|
});
|
|
|
|
it('handles invalid encrypted type', () => {
|
|
|
|
config.encrypted = 1;
|
|
|
|
config.privateKey = privateKey;
|
2017-11-03 06:51:44 +00:00
|
|
|
const res = decryptConfig(config, logger, privateKey);
|
2017-09-01 04:45:51 +00:00
|
|
|
expect(res.encrypted).not.toBeDefined();
|
|
|
|
});
|
|
|
|
it('handles invalid encrypted value', () => {
|
|
|
|
config.encrypted = { a: 1 };
|
|
|
|
config.privateKey = privateKey;
|
2017-11-03 06:51:44 +00:00
|
|
|
const res = decryptConfig(config, logger, privateKey);
|
2017-09-01 04:45:51 +00:00
|
|
|
expect(res.encrypted).not.toBeDefined();
|
|
|
|
expect(res.a).not.toBeDefined();
|
|
|
|
});
|
|
|
|
it('decrypts nested', () => {
|
|
|
|
config.privateKey = privateKey;
|
|
|
|
config.packageFiles = [
|
|
|
|
{
|
|
|
|
packageFile: 'package.json',
|
|
|
|
devDependencies: {
|
|
|
|
encrypted: {
|
|
|
|
branchPrefix:
|
|
|
|
'FLA9YHIzpE7YetAg/P0X46npGRCMqn7hgyzwX5ZQ9wYgu9BRRbTiBVsUIFTyM5BuP1Q22slT2GkWvFvum7GU236Y6QiT7Nr8SLvtsJn2XUuq8H7REFKzdy3+wqyyWbCErYTFyY1dcPM7Ht+CaGDWdd8u/FsoX7AdMRs/X1jNUo6iSmlUiyGlYDKF+QMnCJom1VPVgZXWsGKdjI2MLny991QMaiv0VajmFIh4ENv4CtXOl/1twvIl/6XTXAaqpJJKDTPZEuydi+PHDZmal2RAOfrkH4m0UURa7SlfpUlIg+EaqbNGp85hCYXLwRcEET1OnYr3rH1oYkcYJ40any1tvQ==',
|
2017-09-01 05:43:49 +00:00
|
|
|
npmToken:
|
|
|
|
'FLA9YHIzpE7YetAg/P0X46npGRCMqn7hgyzwX5ZQ9wYgu9BRRbTiBVsUIFTyM5BuP1Q22slT2GkWvFvum7GU236Y6QiT7Nr8SLvtsJn2XUuq8H7REFKzdy3+wqyyWbCErYTFyY1dcPM7Ht+CaGDWdd8u/FsoX7AdMRs/X1jNUo6iSmlUiyGlYDKF+QMnCJom1VPVgZXWsGKdjI2MLny991QMaiv0VajmFIh4ENv4CtXOl/1twvIl/6XTXAaqpJJKDTPZEuydi+PHDZmal2RAOfrkH4m0UURa7SlfpUlIg+EaqbNGp85hCYXLwRcEET1OnYr3rH1oYkcYJ40any1tvQ==',
|
2017-09-01 04:45:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
2017-11-03 06:51:44 +00:00
|
|
|
const res = decryptConfig(config, logger, privateKey);
|
2017-09-01 04:45:51 +00:00
|
|
|
expect(res.encrypted).not.toBeDefined();
|
|
|
|
expect(res.packageFiles[0].devDependencies.encrypted).not.toBeDefined();
|
|
|
|
expect(res.packageFiles[0].devDependencies.branchPrefix).toEqual(
|
|
|
|
'abcdef-ghijklm-nopqf-stuvwxyz'
|
|
|
|
);
|
2017-09-01 05:43:49 +00:00
|
|
|
expect(res.packageFiles[0].devDependencies.npmToken).not.toBeDefined();
|
|
|
|
expect(res.packageFiles[0].devDependencies.npmrc).toEqual(
|
|
|
|
'//registry.npmjs.org/:_authToken=abcdef-ghijklm-nopqf-stuvwxyz\n'
|
|
|
|
);
|
2017-09-01 04:45:51 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|