forked from finos/git-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckExif.test.js
More file actions
79 lines (52 loc) · 2.93 KB
/
CheckExif.test.js
File metadata and controls
79 lines (52 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const { exec } = require('../src/proxy/processors/push-action/checkExifJpeg.js');
const sinon = require('sinon');
const { Action } = require('../src/proxy/actions/Action.js');
const { Step } = require('../src/proxy/actions/Step.js');
describe('Check EXIF Data From Images', () => {
let logStub;
beforeEach(() => {
// Stub console.log and config.getCommitConfig for isolation in each test case
logStub = sinon.stub(console, 'log');
});
afterEach(() => {
// Restore stubs to avoid cross-test interference
logStub.restore();
// configStub.restore();
});
const createDiffContent = (filePaths) => {
// Creates diff-like content for each file path to simulate actual git diff output
return filePaths.map(filePath => `diff --git a/${filePath} b/${filePath}`).join('\n');
};
it('Should block push when sensitive EXIF metadata is found (GPS)', async () => {
// Create action and step instances with test data that should trigger blocking
const action = new Action('action_id', 'push', 'create', Date.now(), 'owner/repo');
const step = new Step('diff');
// Set content with sensitive EXIF metadata in the test image file
step.setContent(createDiffContent(['test/test_data/jpg/Sensitive_EXIF.jpg']));
action.addStep(step);
await exec(null, action);
// Check that console.log was called with the blocking message
sinon.assert.calledWith(logStub, sinon.match(/Your push has been blocked due to sensitive EXIF metadata detection in an image/));
});
it('Should block push when sensitive EXIF metadata is found (Camera Info)', async () => {
const action = new Action('action_id', 'push', 'create', Date.now(), 'owner/repo');
const step = new Step('diff');
// Set content for a file that contains Camera-Info EXIF data
step.setContent(createDiffContent(['test/test_data/jpg/Sensitive_Data_EXIF_2.jpg']));
action.addStep(step);
await exec(null, action);
// Assert blocking message was logged
sinon.assert.calledWith(logStub, sinon.match(/Your push has been blocked due to sensitive EXIF metadata detection in an image/));
});
it('Should allow push when no sensitive EXIF metadata is found', async () => {
// Configure with no sensitive EXIF parameters
const action = new Action('action_id', 'push', 'create', Date.now(), 'owner/repo');
const step = new Step('diff');
// Set content for a non-sensitive EXIF file
step.setContent(createDiffContent(['test/test_data/jpg/Not_Sensitive_EXIF.jpg']));
action.addStep(step);
await exec(null, action);
// Ensure no blocking message was logged
sinon.assert.neverCalledWith(logStub, sinon.match(/Your push has been blocked due to sensitive EXIF metadata detection in an image/));
});
});