1- const path = require ( 'path' ) ;
1+ // const path = require('path');
22const { exec } = require ( '../src/proxy/processors/push-action/checkSensitiveData.js' ) ; // Adjust path as necessary
33const sinon = require ( 'sinon' ) ;
44
@@ -13,13 +13,16 @@ describe('Sensitive Data Detection', () => {
1313 logStub . restore ( ) ; // Restore console.log after each test
1414 } ) ;
1515
16+ const createDiffContent = ( filePaths ) => {
17+ // Format file paths in diff format
18+ return filePaths . map ( filePath => `diff --git a/${ filePath } b/${ filePath } ` ) . join ( '\n' ) ;
19+ } ;
20+
1621 it ( 'should detect sensitive data in CSV file and block execution' , async ( ) => {
1722 const action = {
1823 steps : [ {
1924 stepName : 'diff' ,
20- content : {
21- filePaths : [ path . join ( __dirname , 'test_data/sensitive_data.csv' ) ] // Ensure this path is correct
22- }
25+ content : createDiffContent ( [ 'test/test_data/sensitive_data.csv' ] ) // Ensure this path is correct
2326 } ]
2427 } ;
2528 await exec ( null , action ) ;
@@ -30,9 +33,7 @@ describe('Sensitive Data Detection', () => {
3033 const action = {
3134 steps : [ {
3235 stepName : 'diff' ,
33- content : {
34- filePaths : [ path . join ( __dirname , 'test_data/sensitive_data2.xlsx' ) ] // Ensure this path is correct
35- }
36+ content : createDiffContent ( [ 'test/test_data/sensitive_data2.xlsx' ] ) // Ensure this path is correct
3637 } ]
3738 } ;
3839 await exec ( null , action ) ;
@@ -43,9 +44,7 @@ describe('Sensitive Data Detection', () => {
4344 const action = {
4445 steps : [ {
4546 stepName : 'diff' ,
46- content : {
47- filePaths : [ path . join ( __dirname , 'test_data/sensitive_data3.log' ) ] // Ensure this path is correct
48- }
47+ content : createDiffContent ( [ 'test/test_data/sensitive_data3.log' ] ) // Ensure this path is correct
4948 } ]
5049 } ;
5150 await exec ( null , action ) ;
@@ -56,9 +55,7 @@ describe('Sensitive Data Detection', () => {
5655 const action = {
5756 steps : [ {
5857 stepName : 'diff' ,
59- content : {
60- filePaths : [ path . join ( __dirname , 'test_data/sensitive_data4.json' ) ] // Ensure this path is correct
61- }
58+ content : createDiffContent ( [ 'test/test_data/sensitive_data4.json' ] ) // Ensure this path is correct
6259 } ]
6360 } ;
6461 await exec ( null , action ) ;
@@ -69,9 +66,7 @@ describe('Sensitive Data Detection', () => {
6966 const action = {
7067 steps : [ {
7168 stepName : 'diff' ,
72- content : {
73- filePaths : [ path . join ( __dirname , 'test_data/no_sensitive_data.txt' ) ] // Ensure this path is correct
74- }
69+ content : createDiffContent ( [ 'test_data/no_sensitive_data.txt' ] ) // Ensure this path is correct
7570 } ]
7671 } ;
7772 await exec ( null , action ) ;
@@ -82,9 +77,7 @@ describe('Sensitive Data Detection', () => {
8277 const action = {
8378 steps : [ {
8479 stepName : 'diff' ,
85- content : {
86- filePaths : [ path . join ( __dirname , 'test_data/empty_file.txt' ) ] // Ensure this path is correct
87- }
80+ content : createDiffContent ( [ 'test_data/empty_file.txt' ] ) // Ensure this path is correct
8881 } ]
8982 } ;
9083 await exec ( null , action ) ;
@@ -95,9 +88,7 @@ describe('Sensitive Data Detection', () => {
9588 const action = {
9689 steps : [ {
9790 stepName : 'diff' ,
98- content : {
99- filePaths : [ path . join ( __dirname , 'test_data/non_existent_file.txt' ) ] // Ensure this path is correct
100- }
91+ content : createDiffContent ( [ 'test_data/non_existent_file.txt' ] ) // Ensure this path is correct
10192 } ]
10293 } ;
10394 try {
0 commit comments