-
Notifications
You must be signed in to change notification settings - Fork 747
Expand file tree
/
Copy pathcloudFunctionV2DefaultServiceAccount.spec.js
More file actions
173 lines (150 loc) · 5.63 KB
/
Copy pathcloudFunctionV2DefaultServiceAccount.spec.js
File metadata and controls
173 lines (150 loc) · 5.63 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
var expect = require('chai').expect;
var plugin = require('./cloudFunctionV2DefaultServiceAccount');
const functions = [
{
"name": "projects/my-test-project/locations/us-central1/functions/function-1",
"environment": "GEN_2",
"state": "ACTIVE",
"updateTime": "2021-09-24T06:18:15.265Z",
"buildConfig": {
"runtime": "nodejs20",
"entryPoint": "helloWorld"
},
"serviceConfig": {
"serviceAccountEmail": "aqua@appspot.gserviceaccount.com",
"ingressSettings": "ALLOW_ALL"
}
},
{
"name": "projects/my-test-project/locations/us-central1/functions/function-2",
"environment": "GEN_2",
"state": "ACTIVE",
"updateTime": "2021-09-24T06:18:15.265Z",
"buildConfig": {
"runtime": "nodejs20",
"entryPoint": "helloWorld"
},
"serviceConfig": {
"serviceAccountEmail": "custom-sa@my-test-project.iam.gserviceaccount.com",
"ingressSettings": "ALLOW_INTERNAL_AND_GCLB"
},
"labels": { 'deployment-tool': 'console-cloud' }
},
{
"name": "projects/my-test-project/locations/us-central1/functions/function-3",
"environment": "GEN_2",
"state": "ACTIVE",
"updateTime": "2021-09-24T06:18:15.265Z",
"buildConfig": {
"runtime": "nodejs20",
"entryPoint": "helloWorld"
},
"serviceConfig": {
"ingressSettings": "ALLOW_INTERNAL_ONLY"
}
},
{
"name": "projects/my-test-project/locations/us-central1/functions/function-4",
"environment": "GEN_1",
"state": "ACTIVE",
"runtime": "nodejs14",
"serviceAccountEmail": "aqua@appspot.gserviceaccount.com"
}
];
const createCache = (list, err) => {
return {
functionsv2: {
list: {
'us-central1': {
err: err,
data: list
}
}
}
}
};
describe('functionDefaultServiceAccount', function () {
describe('run', function () {
it('should give passing result if no Cloud Functions V2 found', function (done) {
const callback = (err, results) => {
expect(results.length).to.be.above(0);
expect(results[0].status).to.equal(0);
expect(results[0].message).to.include('No Google Cloud functions found');
expect(results[0].region).to.equal('us-central1');
done()
};
const cache = createCache(
[],
null
);
plugin.run(cache, {}, callback);
});
it('should give unknown result if unable to query for Google Cloud functions', function (done) {
const callback = (err, results) => {
expect(results.length).to.be.above(0);
expect(results[0].status).to.equal(3);
expect(results[0].message).to.include('Unable to query for Google Cloud functions');
expect(results[0].region).to.equal('us-central1');
done()
};
const cache = createCache(
[],
{message: 'error'},
);
plugin.run(cache, {}, callback);
});
it('should give passing result if Cloud Function is not using default service account', function (done) {
const callback = (err, results) => {
expect(results.length).to.be.above(0);
expect(results[0].status).to.equal(0);
expect(results[0].message).to.include('Cloud Function is not using default service account');
expect(results[0].region).to.equal('us-central1');
done()
};
const cache = createCache(
[functions[1]],
null
);
plugin.run(cache, {}, callback);
});
it('should give failing result if Cloud Function is using default service account', function (done) {
const callback = (err, results) => {
expect(results.length).to.be.above(0);
expect(results[0].status).to.equal(2);
expect(results[0].message).to.include('Cloud Function is using default service account');
expect(results[0].region).to.equal('us-central1');
done();
};
const cache = createCache(
[functions[0]],
null
);
plugin.run(cache, {}, callback);
});
it('should give failing result if Cloud Function does not have a service account configured', function (done) {
const callback = (err, results) => {
expect(results.length).to.be.above(0);
expect(results[0].status).to.equal(2);
expect(results[0].message).to.include('Cloud Function does not have a service account configured');
expect(results[0].region).to.equal('us-central1');
done();
};
const cache = createCache(
[functions[2]],
null
);
plugin.run(cache, {}, callback);
});
it('should not check Gen 1 functions in v2 API response', function (done) {
const callback = (err, results) => {
expect(results.length).to.equal(0);
done();
};
const cache = createCache(
[functions[3]],
null
);
plugin.run(cache, {}, callback);
});
})
});