-
Notifications
You must be signed in to change notification settings - Fork 739
Expand file tree
/
Copy pathlambdaFuncUrlNotInUse.spec.js
More file actions
135 lines (114 loc) · 4.88 KB
/
lambdaFuncUrlNotInUse.spec.js
File metadata and controls
135 lines (114 loc) · 4.88 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
125
126
127
128
129
130
131
132
133
134
135
var expect = require('chai').expect;
var lambdaFunctionURLNotInUse = require('./lambdaFuncUrlNotInUse');
const createCache = (lambdaData, functionUrlConfigs) => {
return {
lambda: {
listFunctions: {
'us-east-1': {
err: null,
data: lambdaData
}
},
listFunctionUrlConfigs: functionUrlConfigs
}
};
};
describe('Lambda Function URL Not in Use', function () {
describe('run', function () {
it('should return unknown result if unable to list the lambda functions', function (done) {
const callback = (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(3);
expect(results[0].region).to.equal('us-east-1');
expect(results[0].message).to.include('Unable to query for Lambda functions');
done();
};
const cache = createCache(null, {});
lambdaFunctionURLNotInUse.run(cache, {}, callback);
});
it('should return passing result if no lambda function found in region', function (done) {
const callback = (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
expect(results[0].region).to.equal('us-east-1');
expect(results[0].message).to.include('No Lambda functions found');
done();
};
const cache = createCache([], {});
lambdaFunctionURLNotInUse.run(cache, {}, callback);
});
it('should return passing result if lambda function URL is not configured', function (done) {
const lambdaData = [
{
"FunctionName": "test-lambda",
"FunctionArn": "arn:aws:lambda:us-east-1:000011112222:function:test-lambda"
}
];
const functionUrlConfigs = {
'us-east-1': {
'test-lambda': {
'err': null,
'data': {
'FunctionUrlConfigs': []
}
}
}
};
const callback = (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
expect(results[0].region).to.equal('us-east-1');
expect(results[0].message).to.include('Lambda function Url is not configured');
done();
};
const cache = createCache(lambdaData, functionUrlConfigs);
lambdaFunctionURLNotInUse.run(cache, {}, callback);
});
it('should return failing result if lambda function URL is configured', function (done) {
const lambdaData = [
{
"FunctionName": "test-lambda",
"FunctionArn": "arn:aws:lambda:us-east-1:000011112222:function:test-lambda"
}
];
const functionUrlConfigs = {
'us-east-1': {
'test-lambda': {
'err': null,
'data': {
'FunctionUrlConfigs': [{
FunctionUrl: "https://tetsuewfebwfweffesvvs.lambda-url.us-east-1.on.aws/",
}]
}
}
}
};
const callback = (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(2);
expect(results[0].region).to.equal('us-east-1');
expect(results[0].message).to.include('Lambda function Url is configured');
done();
};
const cache = createCache(lambdaData, functionUrlConfigs);
lambdaFunctionURLNotInUse.run(cache, {}, callback);
});
it('should return unknown result if unable to list the lambda function url config', function (done) {
const lambdaData = [
{
"FunctionName": "test-lambda",
"FunctionArn": "arn:aws:lambda:us-east-1:000011112222:function:test-lambda"
}
];
const callback = (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(3);
expect(results[0].region).to.equal('us-east-1');
expect(results[0].message).to.include('Unable to query for Lambda function URL configs: Unable to obtain data');
done();
};
const cache = createCache(lambdaData, null);
lambdaFunctionURLNotInUse.run(cache, {}, callback);
});
});
});