Skip to content

Commit

Permalink
fix: masked value issue in data table (#3885)
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent authored Oct 6, 2023
1 parent c58ba23 commit 3cc123f
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/data/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = function (context) {
.inject({ current: dataRow.data }));
}
});
maskSecretInTitle(scenarios);
return new DataScenarioConfig(scenarios);
},
only: {
Expand All @@ -42,6 +43,7 @@ module.exports = function (context) {
.inject({ current: dataRow.data }));
}
});
maskSecretInTitle(scenarios);
return new DataScenarioConfig(scenarios);
},
},
Expand Down Expand Up @@ -71,12 +73,6 @@ function replaceTitle(title, dataRow) {
// it should be printed
if (Object.prototype.toString.call(dataRow.data) === (Object()).toString()
&& dataRow.data.toString() !== (Object()).toString()) {
Object.entries(dataRow.data).forEach(entry => {
const [key, value] = entry;
if (value instanceof Secret) {
dataRow.data[key] = value.getMasked();
}
});
return `${title} | ${dataRow.data}`;
}

Expand Down Expand Up @@ -119,3 +115,15 @@ function detectDataType(dataTable) {

throw new Error('Invalid data type. Data accepts either: DataTable || generator || Array || function');
}

function maskSecretInTitle(scenarios) {
scenarios.forEach(scenario => {
const res = [];

scenario.test.title.split(',').forEach(item => {
res.push(item.replace(/{"_secret":"(.*)"}/, '"*****"'));
});

scenario.test.title = res.join(',');
});
}

0 comments on commit 3cc123f

Please sign in to comment.