Skip to content

Commit 29e8136

Browse files
authored
feat: mask sensitive data in logs (#4630)
1 parent 9f830b9 commit 29e8136

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

lib/codecept.js

+3
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ class Codecept {
9292

9393
// debug mode
9494
global.debugMode = false;
95+
96+
// mask sensitive data
97+
global.maskSensitiveData = this.config.maskSensitiveData || false;
9598
}
9699
}
97100

lib/output.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const colors = require('chalk');
22
const figures = require('figures');
3+
const { maskSensitiveData } = require('invisi-data')
34

45
const styles = {
56
error: colors.bgRed.white.bold,
@@ -57,8 +58,9 @@ module.exports = {
5758
* @param {string} msg
5859
*/
5960
debug(msg) {
61+
const _msg = isMaskedData() ? maskSensitiveData(msg) : msg
6062
if (outputLevel >= 2) {
61-
print(' '.repeat(this.stepShift), styles.debug(`${figures.pointerSmall} ${msg}`));
63+
print(' '.repeat(this.stepShift), styles.debug(`${figures.pointerSmall} ${_msg}`));
6264
}
6365
},
6466

@@ -67,8 +69,9 @@ module.exports = {
6769
* @param {string} msg
6870
*/
6971
log(msg) {
72+
const _msg = isMaskedData() ? maskSensitiveData(msg) : msg
7073
if (outputLevel >= 3) {
71-
print(' '.repeat(this.stepShift), styles.log(truncate(` ${msg}`, this.spaceShift)));
74+
print(' '.repeat(this.stepShift), styles.log(truncate(` ${_msg}`, this.spaceShift)));
7275
}
7376
},
7477

@@ -120,7 +123,8 @@ module.exports = {
120123
stepLine += colors.grey(step.comment.split('\n').join('\n' + ' '.repeat(4)));
121124
}
122125

123-
print(' '.repeat(this.stepShift), truncate(stepLine, this.spaceShift));
126+
const _stepLine = isMaskedData() ? maskSensitiveData(stepLine) : stepLine
127+
print(' '.repeat(this.stepShift), truncate(_stepLine, this.spaceShift));
124128
},
125129

126130
/** @namespace */
@@ -167,7 +171,7 @@ module.exports = {
167171
scenario: {
168172
/**
169173
* @param {Mocha.Test} test
170-
*/
174+
*/
171175

172176
started(test) {},
173177

@@ -254,3 +258,7 @@ function truncate(msg, gap = 0) {
254258
}
255259
return msg;
256260
}
261+
262+
function isMaskedData() {
263+
return global.maskSensitiveData === true || false
264+
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
"graphql": "16.9.0",
148148
"husky": "9.1.7",
149149
"inquirer-test": "2.0.1",
150+
"invisi-data": "^1.0.0",
150151
"jsdoc": "4.0.4",
151152
"jsdoc-typeof-plugin": "1.0.0",
152153
"json-server": "0.17.4",

typings/index.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ declare namespace CodeceptJS {
114114
* ```
115115
*/
116116
emptyOutputFolder?: boolean;
117+
/**
118+
* mask sensitive data in output logs
119+
*
120+
* ```js
121+
* maskSensitiveData: true
122+
* ```
123+
*/
124+
maskSensitiveData?: boolean;
117125
/**
118126
* Pattern to filter tests by name.
119127
* This option is useful if you plan to use multiple configs for different environments.

0 commit comments

Comments
 (0)