11// const path = require('path');
22const { exec } = require ( '../src/proxy/processors/push-action/checkSensitiveData.js' ) ; // Adjust path as necessary
33const sinon = require ( 'sinon' ) ;
4+ const { Action} = require ( '../src/proxy/actions/Action.js' )
5+ const { Step} = require ( '../src/proxy/actions/Step.js' )
46
57describe ( 'Sensitive Data Detection' , ( ) => {
68 let logStub ;
@@ -19,78 +21,76 @@ describe('Sensitive Data Detection', () => {
1921 } ;
2022
2123 it ( 'should detect sensitive data in CSV file and block execution' , async ( ) => {
22- const action = {
23- steps : [ {
24- stepName : 'diff' ,
25- content : createDiffContent ( [ 'test/test_data/sensitive_data.csv' ] ) // Ensure this path is correct
26- } ]
27- } ;
24+ const action = new Action ( 'action_id' , 'push' , 'create' , Date . now ( ) , 'owner/repo' ) ;
25+ const step = new Step ( 'diff' ) ;
26+
27+ // Create diff content simulating sensitive data in CSV
28+ step . setContent ( createDiffContent ( [ 'test/test_data/sensitive_data.csv' ] ) ) ;
29+ action . addStep ( step )
30+
2831 await exec ( null , action ) ;
2932 sinon . assert . calledWith ( logStub , sinon . match ( / Y o u r p u s h h a s b e e n b l o c k e d d u e t o s e n s i t i v e d a t a d e t e c t i o n / ) ) ;
3033 } ) ;
3134
3235 it ( 'should detect sensitive data in XLSX file and block execution' , async ( ) => {
33- const action = {
34- steps : [ {
35- stepName : 'diff' ,
36- content : createDiffContent ( [ 'test/test_data/sensitive_data2.xlsx' ] ) // Ensure this path is correct
37- } ]
38- } ;
36+ const action = new Action ( 'action_id' , 'push' , 'create' , Date . now ( ) , 'owner/repo' ) ;
37+ const step = new Step ( 'diff' ) ;
38+ step . setContent ( createDiffContent ( [ 'test/test_data/sensitive_data2.xlsx' ] ) ) ;
39+ action . addStep ( step ) ;
40+
3941 await exec ( null , action ) ;
4042 sinon . assert . calledWith ( logStub , sinon . match ( / Y o u r p u s h h a s b e e n b l o c k e d d u e t o s e n s i t i v e d a t a d e t e c t i o n / ) ) ;
4143 } ) ;
4244
4345 it ( 'should detect sensitive data in a log file and block execution' , async ( ) => {
44- const action = {
45- steps : [ {
46- stepName : 'diff' ,
47- content : createDiffContent ( [ 'test/test_data/sensitive_data3.log' ] ) // Ensure this path is correct
48- } ]
49- } ;
46+
47+ const action = new Action ( 'action_id' , 'push' , 'create' , Date . now ( ) , 'owner/repo' ) ;
48+ const step = new Step ( 'diff' ) ;
49+ step . setContent ( createDiffContent ( [ 'test/test_data/sensitive_data3.log' ] ) ) ;
50+ action . addStep ( step ) ;
5051 await exec ( null , action ) ;
5152 sinon . assert . calledWith ( logStub , sinon . match ( / Y o u r p u s h h a s b e e n b l o c k e d d u e t o s e n s i t i v e d a t a d e t e c t i o n / ) ) ;
5253 } ) ;
5354
5455 it ( 'should detect sensitive data in a JSON file and block execution' , async ( ) => {
55- const action = {
56- steps : [ {
57- stepName : 'diff' ,
58- content : createDiffContent ( [ 'test/test_data/sensitive_data4.json' ] ) // Ensure this path is correct
59- } ]
60- } ;
56+
57+
58+ const action = new Action ( 'action_id' , 'push' , 'create' , Date . now ( ) , 'owner/repo' ) ;
59+ const step = new Step ( 'diff' ) ;
60+ step . setContent ( createDiffContent ( [ 'test/test_data/sensitive_data4.json' ] ) ) ;
61+ action . addStep ( step ) ;
6162 await exec ( null , action ) ;
6263 sinon . assert . calledWith ( logStub , sinon . match ( / Y o u r p u s h h a s b e e n b l o c k e d d u e t o s e n s i t i v e d a t a d e t e c t i o n / ) ) ;
6364 } ) ;
6465
6566 it ( 'should allow execution if no sensitive data is found' , async ( ) => {
66- const action = {
67- steps : [ {
68- stepName : 'diff' ,
69- content : createDiffContent ( [ 'test_data/no_sensitive_data.txt' ] ) // Ensure this path is correct
70- } ]
71- } ;
67+
68+
69+ const action = new Action ( 'action_id' , 'push' , 'create' , Date . now ( ) , 'owner/repo' ) ;
70+ const step = new Step ( 'diff' ) ;
71+ step . setContent ( createDiffContent ( [ 'test_data/no_sensitive_data.txt' ] ) ) ;
72+ action . addStep ( step ) ;
7273 await exec ( null , action ) ;
7374 sinon . assert . neverCalledWith ( logStub , sinon . match ( / Y o u r p u s h h a s b e e n b l o c k e d d u e t o s e n s i t i v e d a t a d e t e c t i o n / ) ) ;
7475 } ) ;
7576
7677 it ( 'should allow execution for an empty file' , async ( ) => {
77- const action = {
78- steps : [ {
79- stepName : 'diff' ,
80- content : createDiffContent ( [ 'test_data/empty_file.txt' ] ) // Ensure this path is correct
81- } ]
82- } ;
78+
79+
80+ const action = new Action ( 'action_id' , 'push' , 'create' , Date . now ( ) , 'owner/repo' ) ;
81+ const step = new Step ( 'diff' ) ;
82+ step . setContent ( createDiffContent ( [ 'test_data/empty_file.txt' ] ) ) ;
83+ action . addStep ( step ) ;
8384 await exec ( null , action ) ;
8485 sinon . assert . neverCalledWith ( logStub , sinon . match ( / Y o u r p u s h h a s b e e n b l o c k e d d u e t o s e n s i t i v e d a t a d e t e c t i o n / ) ) ;
8586 } ) ;
8687
8788 it ( 'should handle file-not-found scenario gracefully' , async ( ) => {
88- const action = {
89- steps : [ {
90- stepName : 'diff' ,
91- content : createDiffContent ( [ 'test_data/non_existent_file.txt' ] ) // Ensure this path is correct
92- } ]
93- } ;
89+
90+ const action = new Action ( 'action_id' , 'push' , 'create' , Date . now ( ) , 'owner/repo' ) ;
91+ const step = new Step ( 'diff' ) ;
92+ step . setContent ( createDiffContent ( [ 'test_data/non_existent_file.txt' ] ) ) ;
93+ action . addStep ( step ) ;
9494 try {
9595 await exec ( null , action ) ;
9696 } catch ( error ) {
0 commit comments