forked from aquasecurity/cloudsploit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlCMKEncryption.spec.js
More file actions
150 lines (137 loc) · 5.08 KB
/
Copy pathsqlCMKEncryption.spec.js
File metadata and controls
150 lines (137 loc) · 5.08 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
var expect = require('chai').expect;
var plugin = require('./sqlCMKEncryption');
const cryptoKeys = [
{
name: "projects/test-dev-aqua/locations/global/keyRings/test-kr/cryptoKeys/test-key-2",
primary: {
name: "projects/test-dev-aqua/locations/global/keyRings/test-kr/cryptoKeys/test-key-1/cryptoKeyVersions/1",
state: "DESTROYED",
createTime: "2021-06-17T08:01:36.739860492Z",
destroyEventTime: "2021-06-18T11:17:00.798768Z",
protectionLevel: "SOFTWARE",
algorithm: "GOOGLE_SYMMETRIC_ENCRYPTION",
generateTime: "2021-06-17T08:01:36.739860492Z",
},
purpose: "ENCRYPT_DECRYPT",
createTime: "2021-06-17T08:01:36.739860492Z",
nextRotationTime: "2021-09-14T19:00:00Z",
rotationPeriod: "7776000s",
versionTemplate: {
protectionLevel: "SOFTWARE",
algorithm: "GOOGLE_SYMMETRIC_ENCRYPTION",
},
}
];
const createCache = (err, data, keysList, keysErr) => {
return {
instances: {
sql: {
list: {
'global': {
err: err,
data: data
}
}
}
},
cryptoKeys: {
list: {
'global': {
err: keysErr,
data: keysList
}
}
},
projects: {
get: {
'global': {
data: [{ name: 'test-project' }]
}
}
}
}
};
describe('sqlCMKEncryption', function () {
describe('run', function () {
it('should give unknown result if a sql instance error is passed or no data is present', 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 SQL instances');
expect(results[0].region).to.equal('global');
done()
};
const cache = createCache(
['error'],
null,
);
plugin.run(cache, {}, callback);
});
it('should give passing result if no sql instances are 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 SQL instances found');
expect(results[0].region).to.equal('global');
done()
};
const cache = createCache(
null,
[],
);
plugin.run(cache, {}, callback);
});
it('should give failing result if sql instance does not have desired encryption level', 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('which is less than');
expect(results[0].region).to.equal('global');
done()
};
const cache = createCache(
null,
[{
instanceType: "CLOUD_SQL_INSTANCE",
name: "testing-instance",
databaseVersion: "POSTGRES_13",
settings: {
storageAutoResizeLimit: '100',
storageAutoResize: false,
}
}],
cryptoKeys,
null
);
plugin.run(cache, {}, callback);
});
it('should give passing result if SQL instance has desired encryption level', 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('which is greater than or equal to');
expect(results[0].region).to.equal('global');
done()
};
const cache = createCache(
null,
[{
instanceType: "CLOUD_SQL_INSTANCE",
name: "testing-instance",
databaseVersion: "POSTGRES_13",
settings: {
storageAutoResizeLimit: '100',
storageAutoResize: true,
},
diskEncryptionConfiguration: {
kmsKeyName: 'projects/test-dev-aqua/locations/global/keyRings/test-kr/cryptoKeys/test-key-2',
kind: 'sql#diskEncryptionConfiguration'
},
}],
cryptoKeys,
null
);
plugin.run(cache, { sql_storage_auto_increase_limit: '150'}, callback);
});
})
})