2023-01-05 04:28:40 -08:00
|
|
|
import { v4 as uuid } from 'uuid';
|
|
|
|
import * as Db from '@/Db';
|
|
|
|
import { audit } from '@/audit';
|
|
|
|
import { FILESYSTEM_INTERACTION_NODE_TYPES, FILESYSTEM_REPORT } from '@/audit/constants';
|
|
|
|
import { getRiskSection, saveManualTriggerWorkflow } from './utils';
|
|
|
|
import * as testDb from '../shared/testDb';
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
2023-01-13 09:12:22 -08:00
|
|
|
await testDb.init();
|
2023-01-05 04:28:40 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
2023-01-13 09:12:22 -08:00
|
|
|
await testDb.truncate(['Workflow']);
|
2023-01-05 04:28:40 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(async () => {
|
2023-01-13 09:12:22 -08:00
|
|
|
await testDb.terminate();
|
2023-01-05 04:28:40 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should report filesystem interaction nodes', async () => {
|
|
|
|
const map = [...FILESYSTEM_INTERACTION_NODE_TYPES].reduce<{ [nodeType: string]: string }>(
|
|
|
|
(acc, cur) => {
|
|
|
|
return (acc[cur] = uuid()), acc;
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
|
|
|
|
const promises = Object.entries(map).map(async ([nodeType, nodeId]) => {
|
2023-07-27 02:53:37 -07:00
|
|
|
const details = Db.collections.Workflow.create({
|
2023-01-05 04:28:40 -08:00
|
|
|
name: 'My Test Workflow',
|
|
|
|
active: false,
|
|
|
|
connections: {},
|
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
id: nodeId,
|
|
|
|
name: 'My Node',
|
|
|
|
type: nodeType,
|
|
|
|
typeVersion: 1,
|
|
|
|
position: [0, 0] as [number, number],
|
2023-06-20 10:13:18 -07:00
|
|
|
parameters: {},
|
2023-01-05 04:28:40 -08:00
|
|
|
},
|
|
|
|
],
|
2023-06-20 10:13:18 -07:00
|
|
|
});
|
2023-01-05 04:28:40 -08:00
|
|
|
|
|
|
|
return Db.collections.Workflow.save(details);
|
|
|
|
});
|
|
|
|
|
|
|
|
await Promise.all(promises);
|
|
|
|
|
|
|
|
const testAudit = await audit(['filesystem']);
|
|
|
|
|
|
|
|
const section = getRiskSection(
|
|
|
|
testAudit,
|
|
|
|
FILESYSTEM_REPORT.RISK,
|
|
|
|
FILESYSTEM_REPORT.SECTIONS.FILESYSTEM_INTERACTION_NODES,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(section.location).toHaveLength(FILESYSTEM_INTERACTION_NODE_TYPES.size);
|
|
|
|
|
|
|
|
for (const loc of section.location) {
|
|
|
|
if (loc.kind === 'node') {
|
|
|
|
expect(loc.nodeId).toBe(map[loc.nodeType]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should not report non-filesystem-interaction node', async () => {
|
|
|
|
await saveManualTriggerWorkflow();
|
|
|
|
|
|
|
|
const testAudit = await audit(['filesystem']);
|
|
|
|
|
|
|
|
expect(testAudit).toBeEmptyArray();
|
|
|
|
});
|