@@ -2,6 +2,7 @@ import test from 'ava';
22import proxyquire from 'proxyquire' ;
33import { stub } from 'sinon' ;
44import tempy from 'tempy' ;
5+ import clearModule from 'clear-module' ;
56import SemanticReleaseError from '@semantic-release/error' ;
67import DEFINITIONS from '../lib/plugins/definitions' ;
78import { gitHead as getGitHead } from '../lib/git' ;
@@ -12,21 +13,25 @@ const envBackup = Object.assign({}, process.env);
1213// Save the current working diretory
1314const cwd = process . cwd ( ) ;
1415
15- stub ( process . stdout , 'write' ) ;
16- stub ( process . stderr , 'write' ) ;
17-
1816test . beforeEach ( t => {
17+ clearModule ( '../lib/hide-sensitive' ) ;
18+
1919 // Stub the logger functions
2020 t . context . log = stub ( ) ;
2121 t . context . error = stub ( ) ;
2222 t . context . logger = { log : t . context . log , error : t . context . error } ;
23+ t . context . stdout = stub ( process . stdout , 'write' ) ;
24+ t . context . stderr = stub ( process . stderr , 'write' ) ;
2325} ) ;
2426
25- test . afterEach . always ( ( ) => {
27+ test . afterEach . always ( t => {
2628 // Restore process.env
2729 process . env = envBackup ;
2830 // Restore the current working directory
2931 process . chdir ( cwd ) ;
32+
33+ t . context . stdout . restore ( ) ;
34+ t . context . stderr . restore ( ) ;
3035} ) ;
3136
3237test . serial ( 'Plugins are called with expected values' , async t => {
@@ -571,6 +576,31 @@ test.serial('Exclude commits with [skip release] or [release skip] from analysis
571576 t . deepEqual ( analyzeCommits . args [ 0 ] [ 1 ] . commits [ 0 ] . message , commits [ commits . length - 1 ] . message ) ;
572577} ) ;
573578
579+ test . serial ( 'Hide sensitive environment variable values from the logs' , async t => {
580+ process . env . MY_TOKEN = 'secret token' ;
581+ await gitRepo ( ) ;
582+
583+ const options = {
584+ branch : 'master' ,
585+ repositoryUrl : 'git@hostname.com:owner/module.git' ,
586+ verifyConditions : async ( pluginConfig , { logger} ) => {
587+ console . log ( `Console: The token ${ process . env . MY_TOKEN } is invalid` ) ;
588+ logger . log ( `Log: The token ${ process . env . MY_TOKEN } is invalid` ) ;
589+ logger . error ( `Error: The token ${ process . env . MY_TOKEN } is invalid` ) ;
590+ throw new Error ( `Invalid token ${ process . env . MY_TOKEN } ` ) ;
591+ } ,
592+ } ;
593+ const semanticRelease = proxyquire ( '..' , {
594+ 'env-ci' : ( ) => ( { isCi : true , branch : 'master' , isPr : false } ) ,
595+ } ) ;
596+
597+ await t . throws ( semanticRelease ( options ) ) ;
598+ t . regex ( t . context . stdout . args [ 7 ] [ 0 ] , / C o n s o l e : T h e t o k e n \[ s e c u r e \] i s i n v a l i d / ) ;
599+ t . regex ( t . context . stdout . args [ 8 ] [ 0 ] , / L o g : T h e t o k e n \[ s e c u r e \] i s i n v a l i d / ) ;
600+ t . regex ( t . context . stderr . args [ 0 ] [ 0 ] , / E r r o r : T h e t o k e n \[ s e c u r e \] i s i n v a l i d / ) ;
601+ t . regex ( t . context . stderr . args [ 1 ] [ 0 ] , / I n v a l i d t o k e n \[ s e c u r e \] / ) ;
602+ } ) ;
603+
574604test . serial ( 'Throw SemanticReleaseError if repositoryUrl is not set and cannot be found from repo config' , async t => {
575605 // Create a git repository, set the current working directory at the root of the repo
576606 await gitRepo ( ) ;
0 commit comments