Skip to content

Commit 7240f33

Browse files
committed
feat: integrate checkEXIFJpeg validation in push action chain
1 parent d4981e3 commit 7240f33

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

src/proxy/chain.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const pushActionChain = [
1010
proc.push.pullRemote,
1111
proc.push.writePack,
1212
proc.push.getDiff,
13-
proc.push.checkEXIFJpeg,
13+
proc.push.checkExifJpeg,
1414
proc.push.clearBareClone,
1515
proc.push.scanDiff,
1616
proc.push.blockForAuth,

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const config = require('../../../config');
44

55
const commitConfig = config.getCommitConfig();
66
const validExtensions = ['.jpeg', '.png', '.jpg', '.tiff'];
7-
//Make sure you have modified the proxy.config.json;
7+
// Make sure you have modified the proxy.config.json;
88
// Function to check sensitive EXIF data
99
const checkSensitiveExifData = (metadata) => {
1010
let allSafe = true;
@@ -33,7 +33,7 @@ const getExifData = async (filePath) => {
3333
const metadata = await exifTool.read(filePath);
3434
return metadata ? checkSensitiveExifData(metadata) : true;
3535
} catch (error) {
36-
log(`Error reading EXIF data from ${filePath}: ${error.message}`);
36+
console.log(`Error reading EXIF data from ${filePath}: ${error.message}`);
3737
return false;
3838
} finally {
3939
await exifTool.end();
@@ -59,12 +59,12 @@ const extractFilePathsFromDiff = (diffContent) => {
5959
const exec = async (req, action, log = console.log) => {
6060

6161
const diffStep = action.steps.find((s) => s.stepName === 'diff');
62-
const step = new Step('checkExifDataFromImage');
63-
const allowed_file_type = commitConfig.diff.block.ProxyFileTypes;
62+
const step = new Step('checkExifJpeg');
63+
const allowedFileType = commitConfig.diff.block.ProxyFileTypes;
6464

6565
if (diffStep && diffStep.content) {
6666
const filePaths = extractFilePathsFromDiff(diffStep.content);
67-
const filteredPaths = filePaths.filter(path => validExtensions.some(ext => path.endsWith(ext) && allowed_file_type.includes(ext)));
67+
const filteredPaths = filePaths.filter(path => validExtensions.some(ext => path.endsWith(ext) && allowedFileType.includes(ext)));
6868

6969
if (filteredPaths.length > 0) {
7070
const exifResults = await Promise.all(filteredPaths.map(filePath => getExifData(filePath)));
@@ -87,5 +87,5 @@ const exec = async (req, action, log = console.log) => {
8787
return action;
8888
};
8989

90-
exec.displayName = 'logFileChanges.exec';
90+
exec.displayName = 'CheckExif.exec';
9191
module.exports = { exec };

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ exports.checkCommitMessages = require('./checkCommitMessages').exec;
1111
exports.checkAuthorEmails = require('./checkAuthorEmails').exec;
1212
exports.checkUserPushPermission = require('./checkUserPushPermission').exec;
1313
exports.clearBareClone = require('./clearBareClone').exec;
14-
exports.checkEXIFJpeg = require('./checkExifJpeg').exec;
14+
exports.checkExifJpeg = require('./checkExifJpeg').exec;

test/chain.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const chai = require('chai');
22
const sinon = require('sinon');
33
const { PluginLoader } = require('../src/plugin');
44

5+
56
chai.should();
67
const expect = chai.expect;
78

@@ -26,6 +27,7 @@ const mockPushProcessors = {
2627
writePack: sinon.stub(),
2728
getDiff: sinon.stub(),
2829
clearBareClone: sinon.stub(),
30+
checkExifJpeg : sinon.stub(),
2931
scanDiff: sinon.stub(),
3032
blockForAuth: sinon.stub(),
3133
};
@@ -39,6 +41,7 @@ mockPushProcessors.checkIfWaitingAuth.displayName = 'checkIfWaitingAuth';
3941
mockPushProcessors.pullRemote.displayName = 'pullRemote';
4042
mockPushProcessors.writePack.displayName = 'writePack';
4143
mockPushProcessors.getDiff.displayName = 'getDiff';
44+
mockPushProcessors.checkEXIFJpeg.displayName = 'checkEXIFJpeg';
4245
mockPushProcessors.clearBareClone.displayName = 'clearBareClone';
4346
mockPushProcessors.scanDiff.displayName = 'scanDiff';
4447
mockPushProcessors.blockForAuth.displayName = 'blockForAuth';
@@ -104,6 +107,7 @@ describe('proxy chain', function () {
104107
mockPushProcessors.parsePush.resolves(continuingAction);
105108
mockPushProcessors.checkRepoInAuthorisedList.resolves(continuingAction);
106109
mockPushProcessors.checkCommitMessages.resolves(continuingAction);
110+
mockPushProcessors.checkEXIFJpeg.resolves(continuingAction);
107111
mockPushProcessors.checkAuthorEmails.resolves(continuingAction);
108112
mockPushProcessors.checkUserPushPermission.resolves(continuingAction);
109113

@@ -120,6 +124,7 @@ describe('proxy chain', function () {
120124
expect(mockPushProcessors.checkIfWaitingAuth.called).to.be.true;
121125
expect(mockPushProcessors.pullRemote.called).to.be.false;
122126
expect(mockPushProcessors.audit.called).to.be.true;
127+
expect(mockPushProcessors.checkEXIFJpeg.called).to.be.false;
123128

124129
expect(result.type).to.equal('push');
125130
expect(result.allowPush).to.be.false;
@@ -135,7 +140,9 @@ describe('proxy chain', function () {
135140
mockPushProcessors.checkCommitMessages.resolves(continuingAction);
136141
mockPushProcessors.checkAuthorEmails.resolves(continuingAction);
137142
mockPushProcessors.checkUserPushPermission.resolves(continuingAction);
143+
mockPushProcessors.checkEXIFJpeg.resolves(continuingAction);
138144
// this stops the chain from further execution
145+
139146
mockPushProcessors.checkIfWaitingAuth.resolves({ type: 'push', continue: () => true, allowPush: true });
140147
const result = await chain.executeChain(req);
141148

@@ -148,6 +155,7 @@ describe('proxy chain', function () {
148155
expect(mockPushProcessors.checkIfWaitingAuth.called).to.be.true;
149156
expect(mockPushProcessors.pullRemote.called).to.be.false;
150157
expect(mockPushProcessors.audit.called).to.be.true;
158+
expect(mockPushProcessors.checkEXIFJpeg.called).to.be.false;
151159

152160
expect(result.type).to.equal('push');
153161
expect(result.allowPush).to.be.true;
@@ -167,9 +175,11 @@ describe('proxy chain', function () {
167175
mockPushProcessors.pullRemote.resolves(continuingAction);
168176
mockPushProcessors.writePack.resolves(continuingAction);
169177
mockPushProcessors.getDiff.resolves(continuingAction);
178+
mockPushProcessors.checkEXIFJpeg.resolves(continuingAction);
170179
mockPushProcessors.clearBareClone.resolves(continuingAction);
171180
mockPushProcessors.scanDiff.resolves(continuingAction);
172181
mockPushProcessors.blockForAuth.resolves(continuingAction);
182+
173183

174184
const result = await chain.executeChain(req);
175185

@@ -183,6 +193,7 @@ describe('proxy chain', function () {
183193
expect(mockPushProcessors.pullRemote.called).to.be.true;
184194
expect(mockPushProcessors.writePack.called).to.be.true;
185195
expect(mockPushProcessors.getDiff.called).to.be.true;
196+
expect(mockPushProcessors.checkEXIFJpeg.called).to.be.true;
186197
expect(mockPushProcessors.clearBareClone.called).to.be.true;
187198
expect(mockPushProcessors.scanDiff.called).to.be.true;
188199
expect(mockPushProcessors.blockForAuth.called).to.be.true;

0 commit comments

Comments
 (0)