forked from aquasecurity/cloudsploit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambdaVpcConfig.spec.js
More file actions
124 lines (112 loc) · 3.76 KB
/
Copy pathlambdaVpcConfig.spec.js
File metadata and controls
124 lines (112 loc) · 3.76 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
const expect = require('chai').expect;
var lambdaVpcConfig = require('./lambdaVpcConfig');
const listFunctions = [
{
"FunctionName": "test-lambda",
"FunctionArn": "arn:aws:lambda:us-east-1:000011112222:function:test-lambda",
"Runtime": "nodejs12.x",
"Role": "arn:aws:iam::000011112222:role/lambda-role",
"Handler": "index.handler",
"VpcConfig": {
"SubnetIds": [
"subnet-6a8b635b",
"subnet-c21b84cc"
],
"SecurityGroupIds": [
"sg-001639e564442dfec"
],
"VpcId": "vpc-99de2fe4"
},
},
{
"FunctionName": "testing-123",
"FunctionArn": "arn:aws:lambda:us-east-1:000011112222:function:testing-123",
"Runtime": "nodejs4.3",
"Role": "arn:aws:iam::000011112222:role/service-role/testing-123-role-7t7oo29b",
"Handler": "index.handler",
}
];
const createCache = (listFunctions) => {
return {
lambda: {
listFunctions: {
'us-east-1': {
data: listFunctions
}
}
}
};
};
const createErrorCache = () => {
return {
lambda: {
listFunctions: {
'us-east-1': {
err: {
message: 'error listing Lambda functions'
}
}
}
}
};
};
const createNullCache = () => {
return {
lambda: {
listFunctions: {
'us-east-1': null
}
}
};
};
describe('lambdaVpcConfig', function () {
describe('run', function () {
it('should PASS if the function is whitelisted', function (done) {
const cache = createCache([listFunctions[1]]);
lambdaVpcConfig.run(cache, { lambda_whitelist: 'testing-123' }, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
done();
});
});
it('should PASS if function is being launched into a VPC', function (done) {
const cache = createCache([listFunctions[0]]);
lambdaVpcConfig.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
done();
});
});
it('should FAIL if function is not being launched into a VPC', function (done) {
const cache = createCache([listFunctions[1]]);
lambdaVpcConfig.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(2);
done();
});
});
it('should PASS if no Lambda functons found', function (done) {
const cache = createCache([]);
lambdaVpcConfig.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
done();
});
});
it('should UNKNOWN if unable to list Lambda functions', function (done) {
const cache = createErrorCache();
lambdaVpcConfig.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(3);
done();
});
});
it('should not return anything if list Lambda functions response not found', function (done) {
const cache = createNullCache();
lambdaVpcConfig.run(cache, {}, (err, results) => {
expect(results.length).to.equal(0);
done();
});
});
});
});