Skip to content

Commit fd26523

Browse files
committed
refactor: modified proxy.config to support the feature
1 parent df82548 commit fd26523

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

proxy.config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@
7777
"block": {
7878
"literals": [],
7979
"patterns": [],
80-
"providers": {}
80+
"providers": {},
81+
"proxyFileTypes":[]
8182
}
8283
}
8384
},

src/proxy/processors/push-action/checkSensitiveData.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ const csv = require('csv-parser');
33
const XLSX = require('xlsx');
44
const path = require('path');
55
const Step = require('../../actions').Step;
6+
const config = require('../../../config');
7+
68
// const { exec: getDiffExec } = require('./getDiff');
79
// Function to check for sensitive data patterns
10+
const commitConfig = config.getCommitConfig();
811
const checkForSensitiveData = (cell) => {
912
const sensitivePatterns = [
1013
/\d{3}-\d{2}-\d{4}/, // Social Security Number (SSN)
@@ -83,7 +86,7 @@ const checkLogJsonFiles = async (filePath) => {
8386
return reject(err);
8487
}
8588
if (checkForSensitiveData(data)) {
86-
console.log(`\x1b[33mSensitive data found in ${filePath}\x1b[0m`);
89+
console.log(`\x1b[Sensitive data found in ${filePath}\x1b[0m`);
8790
sensitiveDataFound = true;
8891
}
8992
resolve(sensitiveDataFound);
@@ -92,7 +95,14 @@ const checkLogJsonFiles = async (filePath) => {
9295
};
9396
// Function to parse the file based on its extension
9497
const parseFile = async (filePath) => {
98+
9599
const ext = path.extname(filePath).toLowerCase();
100+
const FilestoCheck = commitConfig.diff.block.proxyFileTypes;
101+
if(!FilestoCheck.includes(ext)){
102+
103+
console.log(`${ext} should be included in CommitConfig for proxy Check!`);
104+
return false;
105+
}
96106

97107
switch (ext) {
98108
case '.csv':

test/CheckSensitive.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const sinon = require('sinon');
44
const {Action}=require('../src/proxy/actions/Action.js')
55
const {Step}=require('../src/proxy/actions/Step.js')
66

7+
78
describe('Sensitive Data Detection', () => {
89
let logStub;
910

@@ -19,7 +20,7 @@ describe('Sensitive Data Detection', () => {
1920
// Format file paths in diff format
2021
return filePaths.map(filePath => `diff --git a/${filePath} b/${filePath}`).join('\n');
2122
};
22-
23+
// make sure the file types are added in proxyfiletypes in proxy.config.json
2324
it('should detect sensitive data in CSV file and block execution', async () => {
2425
const action = new Action('action_id', 'push', 'create', Date.now(), 'owner/repo');
2526
const step = new Step('diff');

0 commit comments

Comments
 (0)