Skip to content

Commit

Permalink
test: add test for edge cases
Browse files Browse the repository at this point in the history
Signed-off-by: ChaitanyaD48 <chaitanya.d48@gmail.com>
  • Loading branch information
ChaitanyaD48 committed Oct 27, 2024
1 parent c449a9c commit 8b257a2
Showing 1 changed file with 50 additions and 10 deletions.
60 changes: 50 additions & 10 deletions test/CheckSensitive.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
const path = require('path');
const { exec } = require('../src/proxy/processors/push-action/checkSensitiveData.js'); // Adjust path as necessary
const sinon = require('sinon');

describe('Sensitive Data Detection', () => {
let logStub;

beforeEach(() => {
logStub = sinon.stub(console, 'log'); // Stub console.log before each test
});

afterEach(() => {
logStub.restore(); // Restore console.log after each test
});

it('should detect sensitive data in CSV file and block execution', async () => {
const action = {
steps: [{
Expand All @@ -19,10 +23,9 @@ describe('Sensitive Data Detection', () => {
}]
};
await exec(null, action);
const loggedMessages = logStub.getCalls().map(call => call.args[0]);
console.log('Captured log messages for CSV:', loggedMessages);
sinon.assert.calledWith(logStub, sinon.match(/Your push has been blocked due to sensitive data detection/));
});

it('should detect sensitive data in XLSX file and block execution', async () => {
const action = {
steps: [{
Expand All @@ -33,10 +36,9 @@ describe('Sensitive Data Detection', () => {
}]
};
await exec(null, action);
const loggedMessages = logStub.getCalls().map(call => call.args[0]);
console.log('Captured log messages for XLSX:', loggedMessages);
sinon.assert.calledWith(logStub, sinon.match(/Your push has been blocked due to sensitive data detection/));
});

it('should detect sensitive data in a log file and block execution', async () => {
const action = {
steps: [{
Expand All @@ -47,10 +49,9 @@ describe('Sensitive Data Detection', () => {
}]
};
await exec(null, action);
const loggedMessages = logStub.getCalls().map(call => call.args[0]);
console.log('Captured log messages for log file:', loggedMessages);
sinon.assert.calledWith(logStub, sinon.match(/Your push has been blocked due to sensitive data detection/));
});

it('should detect sensitive data in a JSON file and block execution', async () => {
const action = {
steps: [{
Expand All @@ -61,9 +62,48 @@ describe('Sensitive Data Detection', () => {
}]
};
await exec(null, action);
const loggedMessages = logStub.getCalls().map(call => call.args[0]);
console.log('Captured log messages for JSON file:', loggedMessages);
sinon.assert.calledWith(logStub, sinon.match(/Your push has been blocked due to sensitive data detection/));
});

});

it('should allow execution if no sensitive data is found', async () => {
const action = {
steps: [{
stepName: 'diff',
content: {
filePaths: [path.join(__dirname, 'test_data/no_sensitive_data.txt')] // Ensure this path is correct
}
}]
};
await exec(null, action);
sinon.assert.neverCalledWith(logStub, sinon.match(/Your push has been blocked due to sensitive data detection/));
});

it('should allow execution for an empty file', async () => {
const action = {
steps: [{
stepName: 'diff',
content: {
filePaths: [path.join(__dirname, 'test_data/empty_file.txt')] // Ensure this path is correct
}
}]
};
await exec(null, action);
sinon.assert.neverCalledWith(logStub, sinon.match(/Your push has been blocked due to sensitive data detection/));
});

it('should handle file-not-found scenario gracefully', async () => {
const action = {
steps: [{
stepName: 'diff',
content: {
filePaths: [path.join(__dirname, 'test_data/non_existent_file.txt')] // Ensure this path is correct
}
}]
};
try {
await exec(null, action);
} catch (error) {
sinon.assert.match(error.message, /ENOENT: no such file or directory/);
}
});
});

0 comments on commit 8b257a2

Please sign in to comment.