forked from aquasecurity/cloudsploit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmysqlSlowQueryLog.spec.js
More file actions
138 lines (123 loc) · 4.59 KB
/
Copy pathmysqlSlowQueryLog.spec.js
File metadata and controls
138 lines (123 loc) · 4.59 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
var assert = require('assert');
var expect = require('chai').expect;
var plugin = require('./mysqlSlowQueryLog');
const createCache = (err, data) => {
return {
instances: {
sql: {
list: {
'global': {
err: err,
data: data
}
}
}
},
projects: {
get: {
'global': {
data: [{ name: 'test-project' }]
}
}
}
}
};
describe('mysqlSlowQueryLog', 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 passing result if sql instance database type is not of MySQL type', 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('SQL instance database type is not of MySQL type');
expect(results[0].region).to.equal('global');
done()
};
const cache = createCache(
null,
[{
name: "testing-instance",
databaseVersion: "POSTGRES_13",
}],
);
plugin.run(cache, {}, callback);
});
it('should give passing result if sql instance has slow query log flag enabled', 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('SQL instance has slow query log flag enabled');
expect(results[0].region).to.equal('global');
done()
};
const cache = createCache(
null,
[{
instanceType: "CLOUD_SQL_INSTANCE",
name: "testing-instance",
databaseVersion: "MYSQL_5_7",
settings: {
databaseFlags: [
{
name: "slow_query_log",
value: "on",
},
]}
}],
);
plugin.run(cache, {}, callback);
});
it('should give failing result if sql instance has slow query log flag disabled', 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('SQL instance has slow query log flag disabled');
expect(results[0].region).to.equal('global');
done()
};
const cache = createCache(
null,
[{
instanceType: "CLOUD_SQL_INSTANCE",
name: "testing-instance",
databaseVersion: "MYSQL_5_7",
settings: {
databaseFlags: [
{
name: "slow_query_log",
value: "off",
},
]}
}],
);
plugin.run(cache, {}, callback);
});
})
})