From c889f2eec07b28c47b134b5ed3d5414c6a9f854e Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@keylocation.sg> Date: Fri, 1 Sep 2017 07:43:49 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20don=E2=80=99t=20massage=20encrypted=20np?= =?UTF-8?q?m=20token=20(#760)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/config/decrypt.js | 11 +++++++++-- lib/config/massage.js | 2 +- lib/config/validation.js | 2 +- test/config/decrypt.spec.js | 6 ++++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/config/decrypt.js b/lib/config/decrypt.js index 45a5ff94cc..1a13820645 100644 --- a/lib/config/decrypt.js +++ b/lib/config/decrypt.js @@ -18,13 +18,19 @@ function decryptConfig( if (privateKey) { for (const encryptedKey of Object.keys(val)) { try { - decryptedConfig[encryptedKey] = crypto + const decryptedStr = crypto .privateDecrypt( privateKey, new Buffer(val[encryptedKey], 'base64') ) .toString(); - logger.debug(`Decrypted ${encryptedKey}`); + logger.info(`Decrypted ${encryptedKey}`); + if (encryptedKey === 'npmToken') { + logger.info('Migrating npmToken to npmrc'); + decryptedConfig.npmrc = `//registry.npmjs.org/:_authToken=${decryptedStr}\n`; + } else { + decryptedConfig[encryptedKey] = decryptedStr; + } } catch (err) { logger.warn({ err }, `Error decrypting ${encryptedKey}`); } @@ -47,6 +53,7 @@ function decryptConfig( } } delete decryptedConfig.encrypted; + logger.trace({ config: decryptedConfig }, 'decryptedConfig'); return decryptedConfig; } diff --git a/lib/config/massage.js b/lib/config/massage.js index dd66e43825..fdc0cae08f 100644 --- a/lib/config/massage.js +++ b/lib/config/massage.js @@ -18,7 +18,7 @@ function massageConfig(config) { const val = config[key]; if (allowedStrings.includes(key) && typeof val === 'string') { massagedConfig[key] = [val]; - } else if (key === 'npmToken') { + } else if (key === 'npmToken' && val.length < 30) { massagedConfig.npmrc = `//registry.npmjs.org/:_authToken=${val}\n`; delete massagedConfig.npmToken; } else if (isObject(val)) { diff --git a/lib/config/validation.js b/lib/config/validation.js index b19b562f25..4f233e8425 100644 --- a/lib/config/validation.js +++ b/lib/config/validation.js @@ -15,7 +15,7 @@ function validateConfig(config) { let warnings = []; function isIgnored(key) { - const ignoredNodes = ['api', 'depType']; + const ignoredNodes = ['api', 'depType', 'npmToken']; return ignoredNodes.indexOf(key) !== -1; } diff --git a/test/config/decrypt.spec.js b/test/config/decrypt.spec.js index 95508e4b15..456f42bd37 100644 --- a/test/config/decrypt.spec.js +++ b/test/config/decrypt.spec.js @@ -44,6 +44,8 @@ describe('config/massage', () => { encrypted: { branchPrefix: 'FLA9YHIzpE7YetAg/P0X46npGRCMqn7hgyzwX5ZQ9wYgu9BRRbTiBVsUIFTyM5BuP1Q22slT2GkWvFvum7GU236Y6QiT7Nr8SLvtsJn2XUuq8H7REFKzdy3+wqyyWbCErYTFyY1dcPM7Ht+CaGDWdd8u/FsoX7AdMRs/X1jNUo6iSmlUiyGlYDKF+QMnCJom1VPVgZXWsGKdjI2MLny991QMaiv0VajmFIh4ENv4CtXOl/1twvIl/6XTXAaqpJJKDTPZEuydi+PHDZmal2RAOfrkH4m0UURa7SlfpUlIg+EaqbNGp85hCYXLwRcEET1OnYr3rH1oYkcYJ40any1tvQ==', + npmToken: + 'FLA9YHIzpE7YetAg/P0X46npGRCMqn7hgyzwX5ZQ9wYgu9BRRbTiBVsUIFTyM5BuP1Q22slT2GkWvFvum7GU236Y6QiT7Nr8SLvtsJn2XUuq8H7REFKzdy3+wqyyWbCErYTFyY1dcPM7Ht+CaGDWdd8u/FsoX7AdMRs/X1jNUo6iSmlUiyGlYDKF+QMnCJom1VPVgZXWsGKdjI2MLny991QMaiv0VajmFIh4ENv4CtXOl/1twvIl/6XTXAaqpJJKDTPZEuydi+PHDZmal2RAOfrkH4m0UURa7SlfpUlIg+EaqbNGp85hCYXLwRcEET1OnYr3rH1oYkcYJ40any1tvQ==', }, }, }, @@ -54,6 +56,10 @@ describe('config/massage', () => { expect(res.packageFiles[0].devDependencies.branchPrefix).toEqual( 'abcdef-ghijklm-nopqf-stuvwxyz' ); + expect(res.packageFiles[0].devDependencies.npmToken).not.toBeDefined(); + expect(res.packageFiles[0].devDependencies.npmrc).toEqual( + '//registry.npmjs.org/:_authToken=abcdef-ghijklm-nopqf-stuvwxyz\n' + ); }); }); }); -- GitLab