forked from aquasecurity/cloudsploit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambdaOldRuntimes.spec.js
More file actions
107 lines (96 loc) · 3.22 KB
/
Copy pathlambdaOldRuntimes.spec.js
File metadata and controls
107 lines (96 loc) · 3.22 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
const expect = require('chai').expect;
var lambdaOldRuntimes = require('./lambdaOldRuntimes');
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",
"TracingConfig": { "Mode": "PassThrough" }
},
{
"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",
"TracingConfig": { "Mode": "Active" }
}
];
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('lambdaOldRuntimes', function () {
describe('run', function () {
it('should PASS if no functions using out-of-date runtimes', function (done) {
const cache = createCache([listFunctions[0]]);
lambdaOldRuntimes.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
done();
});
});
it('should FAIL if function is using out-of-date runtime', function (done) {
const cache = createCache([listFunctions[1]]);
lambdaOldRuntimes.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([]);
lambdaOldRuntimes.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();
lambdaOldRuntimes.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();
lambdaOldRuntimes.run(cache, {}, (err, results) => {
expect(results.length).to.equal(0);
done();
});
});
});
});