forked from aquasecurity/cloudsploit
-
Notifications
You must be signed in to change notification settings - Fork 2
/
exports.spec.js
111 lines (94 loc) · 6.84 KB
/
exports.spec.js
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
var expect = require('chai').expect;
var tests = require('./exports');
// This function is used to ensure function arguments
// are configured correctly for each plugin
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
var ARGUMENT_NAMES = /([^\s,]+)/g;
function getParamNames(func) {
var fnStr = func.toString().replace(STRIP_COMMENTS, '');
var result = fnStr.slice(fnStr.indexOf('(')+1, fnStr.indexOf(')')).match(ARGUMENT_NAMES);
if (result === null) result = [];
return result;
}
describe('exports', function () {
it('should use the proper format for each test', function () {
for (var cloud in tests) {
for (var test in tests[cloud]) {
var lTest = tests[cloud][test];
// Check test properties
expect(lTest, `Test: ${test} is not an object`).to.be.an('object');
['title', 'category', 'description', 'more_info',
'recommended_action', 'link', 'apis'].forEach(function(prop){
expect(lTest, `Test: ${test} does not have property: ${prop}`).to.have.property(prop);
});
// Check settings properties, if they exist
if (lTest.settings) {
expect(lTest.settings).to.be.an('object');
Object.values(lTest.settings).forEach(function(setting){
expect(setting).to.be.an('object');
['name', 'description', 'regex', 'default'].forEach(function(prop){
expect(setting, `Test: ${test} does not have settings property: ${prop}`).to.have.property(prop);
});
});
}
// Check run function and arguments
expect(lTest.run, `Test: ${test} run is not a function`).to.be.an('function');
var runParams = getParamNames(lTest.run);
expect(runParams[0], `Test: ${test} run function parameter 1 is not: cache`).to.equal('cache');
expect(runParams[1], `Test: ${test} run function parameter 2 is not: settings`).to.equal('settings');
expect(runParams[2], `Test: ${test} run function parameter 3 is not: callback`).to.equal('callback');
// Check remediate function and arguments
if (lTest.remediate) {
expect(lTest.remediate, `Test: ${test} remediate is not a function`).to.be.an('function');
var remediateParams = getParamNames(lTest.remediate);
expect(remediateParams[0], `Test: ${test} remediate function parameter 1 is not: config`).to.equal('config');
expect(remediateParams[1], `Test: ${test} remediate function parameter 2 is not: cache`).to.equal('cache');
expect(remediateParams[2], `Test: ${test} remediate function parameter 3 is not: settings`).to.equal('settings');
expect(remediateParams[3], `Test: ${test} remediate function parameter 4 is not: resource`).to.equal('resource');
expect(remediateParams[4], `Test: ${test} remediate function parameter 4 is not: callback`).to.equal('callback');
// Check remediation properties, if they exist
expect(lTest.apis_remediate).to.be.an('array');
lTest.apis_remediate.forEach(function(apiCall){
expect(apiCall, `Test: ${test} API call in apis_remediate is not a string`).to.be.an('string');
});
expect(lTest.actions, `Test: ${test} actions is not an object`).to.be.an('object');
expect(lTest.actions.remediate, `Test: ${test} actions.remediate is not an array`).to.be.an('array');
expect(lTest.actions.rollback, `Test: ${test} actions.rollback is not an array`).to.be.an('array');
lTest.actions.remediate.forEach(function(apiCall){
expect(apiCall, `Test: ${test} actions.remediate call is not a string`).to.be.an('string');
});
lTest.actions.rollback.forEach(function(apiCall){
expect(apiCall, `Test: ${test} actions.rollback call is not a string`).to.be.an('string');
});
expect(lTest.permissions, `Test: ${test} permissions is not an object`).to.be.an('object');
expect(lTest.permissions.remediate, `Test: ${test} permissions.remediate is not an array`).to.be.an('array');
expect(lTest.permissions.rollback, `Test: ${test} permissions.rollback is not an array`).to.be.an('array');
lTest.permissions.remediate.forEach(function(apiCall){
expect(apiCall, `Test: ${test} permissions.remediate call is not a string`).to.be.an('string');
});
lTest.permissions.rollback.forEach(function(apiCall){
expect(apiCall, `Test: ${test} actions.rollback call is not a string`).to.be.an('string');
});
expect(lTest.remediation_description, `Test: ${test} remediation_description parameter is not a string`).to.be.an('string');
if (lTest.realtime_triggers) {
expect(lTest.realtime_triggers, `Test: ${test} realtime_triggers parameter is not an array`).to.be.an('array');
lTest.realtime_triggers.forEach(function(lTrigger){
expect(lTrigger, `Test: ${test} realtime_triggers property is not a string`).to.be.an('string');
});
}
expect(lTest.remediation_min_version, `Test: ${test} remediation_min_version parameter is not a string`).to.be.a('string');
expect(lTest.remediation_min_version.length, `Test: ${test} remediation_min_version parameter length is not 12`).to.equal(12);
}
if (lTest.rollback) {
expect(lTest.rollback, `Test: ${test} rollback is not a function`).to.be.an('function');
var rollbackParams = getParamNames(lTest.rollback);
expect(rollbackParams[0], `Test: ${test} rollback function parameter 1 is not: config`).to.equal('config');
expect(rollbackParams[1], `Test: ${test} rollback function parameter 2 is not: cache`).to.equal('cache');
expect(rollbackParams[2], `Test: ${test} rollback function parameter 3 is not: settings`).to.equal('settings');
expect(rollbackParams[3], `Test: ${test} rollback function parameter 4 is not: resource`).to.equal('resource');
expect(rollbackParams[4], `Test: ${test} rollback function parameter 4 is not: callback`).to.equal('callback');
}
}
}
});
});