Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
467635bc14 | ||
|
|
8b3605dd04 |
@@ -2,7 +2,7 @@ const {parse, format} = require('url');
|
||||
const {isUndefined} = require('lodash');
|
||||
const gitUrlParse = require('git-url-parse');
|
||||
|
||||
const GIT_TOKENS = ['GH_TOKEN', 'GITHUB_TOKEN', 'GL_TOKEN', 'GITLAB_TOKEN', 'GIT_CREDENTIALS'];
|
||||
const GIT_TOKENS = ['GIT_CREDENTIALS', 'GH_TOKEN', 'GITHUB_TOKEN', 'GL_TOKEN', 'GITLAB_TOKEN'];
|
||||
|
||||
/**
|
||||
* Generate the git repository URL with creadentials.
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
const {escapeRegExp} = require('lodash');
|
||||
|
||||
const regexp = new RegExp(
|
||||
Object.keys(process.env)
|
||||
.filter(envVar => /token|password|credential|secret|private/i.test(envVar))
|
||||
.map(envVar => escapeRegExp(process.env[envVar]))
|
||||
.join('|'),
|
||||
'g'
|
||||
);
|
||||
const toReplace = Object.keys(process.env).filter(envVar => /token|password|credential|secret|private/i.test(envVar));
|
||||
const regexp = new RegExp(toReplace.map(envVar => escapeRegExp(process.env[envVar])).join('|'), 'g');
|
||||
|
||||
module.exports = output => output.replace(regexp, '[secure]');
|
||||
module.exports = output => {
|
||||
return output && toReplace.length > 0 ? output.toString().replace(regexp, '[secure]') : output;
|
||||
};
|
||||
|
||||
@@ -32,3 +32,11 @@ test.serial('Escape regexp special characters', t => {
|
||||
'https://user:[secure]@host.com'
|
||||
);
|
||||
});
|
||||
|
||||
test.serial('Accept "undefined" input', t => {
|
||||
t.is(require('../lib/hide-sensitive')(), undefined);
|
||||
});
|
||||
|
||||
test.serial('Return same string if no environment variable has to be replaced', t => {
|
||||
t.is(require('../lib/hide-sensitive')('test'), 'test');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user