Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/AKD-224: Added Alibaba RDS Log Duration plugin and test cases #689

Merged
merged 149 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
149 commits
Select commit Hold shift + click to select a range
e1708af
SPLOIT-113: Added Plain Text Parameters plugin for CloudFormation
AkhtarAmir Aug 12, 2020
2122ade
Added vpcEndpointAcceptance plugin and spec file
AkhtarAmir Aug 13, 2020
306d721
SPLOIT-113: Added Plain Text Parameters plugin for CloudFormation
AkhtarAmir Aug 14, 2020
7c8616c
Added plugin and spec file for launch wizard security groups
AkhtarAmir Aug 14, 2020
de52e8a
Merge branch 'master' into feature/ec2-plugin-mark-launch-wizard-secu…
AkhtarAmir Aug 14, 2020
f3b72f6
Merge pull request #1 from AkhtarAmir/feature/ec2-plugin-mark-launch-…
AkhtarAmir Aug 14, 2020
d32cbac
Merge branch 'master' of https://github.com/AkhtarAmir/scans into fea…
AkhtarAmir Aug 14, 2020
3da6672
Refactored code in plaintextParameters plugin and spec file
AkhtarAmir Aug 14, 2020
928c712
Merge pull request #2 from AkhtarAmir/feature/SPLOIT-113
AkhtarAmir Aug 14, 2020
ce65325
SPLOIT-113: Updated custom settings
AkhtarAmir Aug 14, 2020
f3e3ab5
Merge pull request #3 from AkhtarAmir/feature/SPLOIT-113
AkhtarAmir Aug 14, 2020
e70b96a
Made PR requested changes
AkhtarAmir Aug 14, 2020
f62a1d5
SPLOIT-113: Added regex to check if NoEcho is enabled
AkhtarAmir Aug 14, 2020
865e0b6
Merge pull request #4 from AkhtarAmir/feature/SPLOIT-113
AkhtarAmir Aug 14, 2020
9745614
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Aug 15, 2020
1b80ac4
Accommodated PR changes
AkhtarAmir Aug 17, 2020
c0dc834
Fixed eslint issues
AkhtarAmir Aug 18, 2020
7d457bd
Update exports.js
AkhtarAmir Aug 18, 2020
8c2466c
Fixed eslint issues
AkhtarAmir Aug 18, 2020
ccb92ee
Update index.js
AkhtarAmir Aug 18, 2020
93c553d
Update index.js
AkhtarAmir Aug 18, 2020
cf21d1d
Added cloudformation in china and gov regions
AkhtarAmir Aug 18, 2020
aac8ece
Accomodated PR changes
AkhtarAmir Aug 18, 2020
7707dbd
Updated status in result of failure
AkhtarAmir Aug 18, 2020
a4ea92f
SPLOIT-113: Added Plain Text Parameters plugin for CloudFormation
AkhtarAmir Aug 14, 2020
8e5b6be
Added plugin and spec file for launch wizard security groups
AkhtarAmir Aug 14, 2020
a9afe44
Added vpcEndpointAcceptance plugin and spec file
AkhtarAmir Aug 13, 2020
0323a98
Refactored code in plaintextParameters plugin and spec file
AkhtarAmir Aug 14, 2020
aab9f79
SPLOIT-113: Updated custom settings
AkhtarAmir Aug 14, 2020
12d88c1
Made PR requested changes
AkhtarAmir Aug 14, 2020
7dd1a5b
SPLOIT-113: Added regex to check if NoEcho is enabled
AkhtarAmir Aug 14, 2020
c8a23c3
Accommodated PR changes
AkhtarAmir Aug 17, 2020
92821dd
Fixed eslint issues
AkhtarAmir Aug 18, 2020
e32accc
Update index.js
AkhtarAmir Aug 18, 2020
90094a2
Update index.js
AkhtarAmir Aug 18, 2020
c29ab07
Accomodated PR changes
AkhtarAmir Aug 18, 2020
49f1202
Updated status in result of failure
AkhtarAmir Aug 18, 2020
fa70d92
Updated master from upstream/master
AkhtarAmir Aug 21, 2020
357cd0b
SPLOIT-113: Added Plain Text Parameters plugin for CloudFormation
AkhtarAmir Aug 14, 2020
77ca002
Added plugin and spec file for launch wizard security groups
AkhtarAmir Aug 14, 2020
73172b8
Added vpcEndpointAcceptance plugin and spec file
AkhtarAmir Aug 13, 2020
7b448ff
Refactored code in plaintextParameters plugin and spec file
AkhtarAmir Aug 14, 2020
50d9d70
SPLOIT-113: Updated custom settings
AkhtarAmir Aug 14, 2020
46ff92c
Made PR requested changes
AkhtarAmir Aug 14, 2020
ec1e5ef
SPLOIT-113: Added regex to check if NoEcho is enabled
AkhtarAmir Aug 14, 2020
e89dd5e
Accommodated PR changes
AkhtarAmir Aug 17, 2020
4d7ee30
Fixed eslint issues
AkhtarAmir Aug 18, 2020
f5c9bf0
Update index.js
AkhtarAmir Aug 18, 2020
53e18b8
Update index.js
AkhtarAmir Aug 18, 2020
6ec73bc
Accomodated PR changes
AkhtarAmir Aug 18, 2020
2f55a11
Updated status in result of failure
AkhtarAmir Aug 18, 2020
0ba2fbf
SPLOIT-113: Added Plain Text Parameters plugin for CloudFormation
AkhtarAmir Aug 12, 2020
e9415b9
SPLOIT-113: Added Plain Text Parameters plugin for CloudFormation
AkhtarAmir Aug 14, 2020
8820775
Added plugin and spec file for launch wizard security groups
AkhtarAmir Aug 14, 2020
8e6b23b
Added vpcEndpointAcceptance plugin and spec file
AkhtarAmir Aug 13, 2020
82d8406
Refactored code in plaintextParameters plugin and spec file
AkhtarAmir Aug 14, 2020
b022a52
SPLOIT-113: Updated custom settings
AkhtarAmir Aug 14, 2020
d3ee380
Made PR requested changes
AkhtarAmir Aug 14, 2020
560d273
SPLOIT-113: Added regex to check if NoEcho is enabled
AkhtarAmir Aug 14, 2020
9195d32
Accommodated PR changes
AkhtarAmir Aug 17, 2020
0287cc5
Fixed eslint issues
AkhtarAmir Aug 18, 2020
1315ccd
Update exports.js
AkhtarAmir Aug 18, 2020
229461c
Update index.js
AkhtarAmir Aug 18, 2020
f5a3b8b
Update index.js
AkhtarAmir Aug 18, 2020
c574f76
Accomodated PR changes
AkhtarAmir Aug 18, 2020
1a4b495
Updated status in result of failure
AkhtarAmir Aug 18, 2020
a45a9f7
Merge branch 'master' of https://github.com/AkhtarAmir/scans into master
AkhtarAmir Aug 28, 2020
156d027
Removed unnecesary rebase changes
AkhtarAmir Aug 28, 2020
32ee6d9
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Sep 12, 2020
c687820
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Sep 22, 2020
29075e7
Merge branch 'master' of https://github.com/aquasecurity/cloudsploit …
AkhtarAmir Sep 24, 2020
c51edd1
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Sep 25, 2020
0768693
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Oct 16, 2020
2d04307
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Oct 20, 2020
c6b7eb1
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Nov 5, 2020
159f5dd
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Nov 21, 2020
d713e12
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Nov 26, 2020
b63a6d3
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Nov 30, 2020
472380f
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Nov 30, 2020
a95a46b
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Nov 30, 2020
f83f331
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Nov 30, 2020
55b0319
Merge branch 'master' of https://github.com/aquasecurity/cloudsploit
AkhtarAmir Dec 20, 2020
f627c6a
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Dec 22, 2020
6fe875d
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Jan 21, 2021
d129f4b
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Jan 21, 2021
c132394
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Jan 22, 2021
68e9bfe
Merge branch 'master' of https://github.com/aquasecurity/cloudsploit
AkhtarAmir Jan 23, 2021
0cbc28f
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Jan 23, 2021
2fa5e63
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Jan 25, 2021
7319bca
Merge branch 'master' of https://github.com/AkhtarAmir/scans
AkhtarAmir Jan 25, 2021
4c73161
Added superlinter
AkhtarAmir Jan 26, 2021
6cda1ef
Added scans ci
AkhtarAmir Jan 27, 2021
072a98a
Updated Ci file
AkhtarAmir Jan 27, 2021
cb40648
Updated Node version in CI file
AkhtarAmir Jan 27, 2021
b0138cb
removed spech check command
AkhtarAmir Jan 27, 2021
239b8a6
Delete scan_ci.yml
AkhtarAmir Jan 27, 2021
63cd684
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Jan 27, 2021
ab41137
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Jan 27, 2021
f04d8d8
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Jan 27, 2021
9c56577
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Jan 28, 2021
8c3e0ef
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Jan 29, 2021
32f8e04
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Jan 29, 2021
2db8162
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Jan 29, 2021
46cfe9d
Added spellcheck
AkhtarAmir Feb 1, 2021
5f0adec
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Feb 3, 2021
ea01ba2
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Mar 2, 2021
9f518b6
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Mar 5, 2021
0bf276d
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Mar 12, 2021
5271345
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Mar 14, 2021
2852187
Azure MySQL Enforce SSL Connection remediated
AkhtarAmir Mar 18, 2021
da2417f
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Mar 23, 2021
ffe9864
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Mar 24, 2021
48d11fd
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Mar 26, 2021
2d04881
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Mar 29, 2021
c8edb8a
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Mar 29, 2021
566a513
Modified index and engine files to fix azure remediation invalid toke…
AkhtarAmir Mar 30, 2021
7670ef0
Merge branch 'master' of https://github.com/AkhtarAmir/scans into rem…
AkhtarAmir Mar 30, 2021
2409824
Update engine.js
AkhtarAmir Mar 30, 2021
fdaf02e
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Apr 1, 2021
5796cc8
Merge branch 'modification/engine-remediate' of https://github.com/Ak…
AkhtarAmir Apr 5, 2021
bd37241
Added new argument for cloud
AkhtarAmir Apr 5, 2021
c1373ac
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Apr 16, 2021
3b6aa18
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Apr 16, 2021
cd0b677
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Apr 16, 2021
6647704
Merge branch 'modification/add-cloud-argument' of https://github.com/…
AkhtarAmir Apr 19, 2021
b0afaa5
Modified index for Alibaba cloud
AkhtarAmir Apr 19, 2021
459af26
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Apr 20, 2021
a130ed8
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Apr 20, 2021
239f7fd
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Apr 20, 2021
324c055
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Apr 22, 2021
627cf17
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir Apr 23, 2021
e302ec8
Added logic for Alibaba collector
AkhtarAmir Apr 26, 2021
00b8d84
Modified collector
AkhtarAmir May 3, 2021
10157cf
Added Alibaba RAM Users MFA Enabled plugin and test cases
AkhtarAmir May 4, 2021
e66546b
Merge remote-tracking branch 'upstream/master' into master
AkhtarAmir May 4, 2021
9564733
Merge branch 'master' of https://github.com/AkhtarAmir/scans into mod…
AkhtarAmir May 4, 2021
33dbf83
Modified collector
AkhtarAmir May 3, 2021
111bb7d
Merge branch 'master' of https://github.com/AkhtarAmir/scans into fea…
AkhtarAmir May 4, 2021
1de9dda
Merge branch 'master' of https://github.com/AkhtarAmir/scans into fea…
AkhtarAmir May 4, 2021
e31d517
Merge branch 'feature/alibaba-collector' of https://github.com/Akhtar…
AkhtarAmir May 4, 2021
e426c71
Merge branch 'feature/alibaba-collector' of https://github.com/Akhtar…
AkhtarAmir May 4, 2021
b39407f
Merge branch 'feature/akd-191' of https://github.com/AkhtarAmir/scans…
AkhtarAmir May 4, 2021
245ae98
Added Alibaba RDS SSL Encryption Enabled plugin and test cases
AkhtarAmir May 4, 2021
e54691e
Merge branch 'master' of https://github.com/AkhtarAmir/scans into fea…
AkhtarAmir May 4, 2021
e439cc1
Merge branch 'feature/alibaba-collector' of https://github.com/Akhtar…
AkhtarAmir May 4, 2021
d536268
Merge branch 'feature/alibaba-collector' of https://github.com/Akhtar…
AkhtarAmir May 6, 2021
c0707f2
Merge branch 'feature/akd-215' of https://github.com/AkhtarAmir/scans…
AkhtarAmir May 6, 2021
9d49871
Added Alibaba RDS Log Duration plugin and test cases
AkhtarAmir May 6, 2021
96bee12
Merge branch 'aqua_master' into feature/akd-224
giorod3 May 20, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion collectors/alibaba/collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ var regions = helpers.regions();
var regionEndpointMap = {
ecs: ['cn-wulanchabu', 'cn-zhangjiak', 'cn-huhehaote', 'cn-heyuan', 'cn-chengdu', 'ap-southeast-2', 'cn-guangzhou',
'ap-southeast-3', 'ap-southeast-5', 'ap-northeast-1', 'ap-south-1', 'eu-central-1', 'eu-west-1', 'me-east-1'],
kms: regions['kms']
kms: regions['kms'],
rds: ['cn-zhangjiakou', 'cn-huhehaote', 'cn-chengdu', 'ap-southeast-2', 'ap-southeast-3', 'ap-southeast-5',
'ap-northeast-1', 'ap-south-1', 'eu-central-1', 'eu-west-1', 'me-east-1']
};

var globalServices = [
Expand Down Expand Up @@ -170,6 +172,14 @@ var postcalls = [
}
},
RDS: {
DescribeParameters: {
reliesOnService: 'rds',
reliesOnCall: 'DescribeDBInstances',
filterKey: ['DBInstanceId'],
filterValue: ['DBInstanceId'],
resultKey: 'DBInstanceId',
apiVersion: '2014-08-15'
},
DescribeDBInstanceSSL: {
reliesOnService: 'rds',
reliesOnCall: 'DescribeDBInstances',
Expand Down
1 change: 1 addition & 0 deletions exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ module.exports = {
'logSinksEnabled' : require(__dirname + '/plugins/google/logging/logSinksEnabled.js'),
},
alibaba: {
'rdsLogDuration' : require(__dirname + '/plugins/alibaba/rds/rdsLogDuration.js'),
'dataDisksEncrypted' : require(__dirname + '/plugins/alibaba/ecs/dataDisksEncrypted.js'),
'rdsSslEncryptionEnabled' : require(__dirname + '/plugins/alibaba/rds/rdsSslEncryptionEnabled.js'),
'passwordRequiresUppercase' : require(__dirname + '/plugins/alibaba/ram/passwordRequiresUppercase.js'),
Expand Down
93 changes: 93 additions & 0 deletions plugins/alibaba/rds/rdsLogDuration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
var async = require('async');
var helpers = require('../../../helpers/alibaba');

module.exports = {
title: 'RDS Log Duration',
category: 'RDS',
description: 'Ensure that RDS DB instances have log_duration paraemeter enabled.',
more_info: 'Enabling log_duration parameter logs the duration of each completed SQL statement generating query and error logs ' +
'which can be used to identify, troubleshoot, and repair configuration errors and sub-optimal performance.',
link: 'https://partners-intl.aliyun.com/help/doc-detail/26179.htm',
recommended_action: 'Modify RDS DB instances to set value for log_duration parameter to ON',
apis: ['RDS:DescribeDBInstances', 'RDS:DescribeParameters', 'STS:GetCallerIdentity'],

run: function(cache, settings, callback) {
var results = [];
var source = {};
var regions = helpers.regions();
var defaultRegion = helpers.defaultRegion(settings);

var accountId = helpers.addSource(cache, source, ['sts', 'GetCallerIdentity', defaultRegion, 'data']);

async.each(regions.rds, function(region, rcb) {
var describeDBInstances = helpers.addSource(cache, source,
['rds', 'DescribeDBInstances', region]);

if (!describeDBInstances) {
return rcb();
}

if (describeDBInstances.err || !describeDBInstances.data) {
helpers.addResult(results, 3,
`Unable to query RDS DB instances: ${helpers.addError(describeDBInstances)}`,
region);
return rcb();
}

if (!describeDBInstances.data.length) {
helpers.addResult(results, 0, 'No RDS DB instances found', region);
return rcb();
}

async.each(describeDBInstances.data, function(instance, cb){
if (!instance.DBInstanceId) return cb();

var resource = helpers.createArn('rds', accountId, 'instance', instance.DBInstanceId, region);

if (instance.Engine && instance.Engine.toUpperCase() !== 'POSTGRESQL') {
helpers.addResult(results, 0,
`Log Duration is not supported for ${instance.Engine} engine type`,
region, resource);
return cb();
}

var describeParameters = helpers.addSource(cache, source,
['rds', 'DescribeParameters', region, instance.DBInstanceId]);

if (!describeParameters || describeParameters.err || !describeParameters.data) {
helpers.addResult(results, 3,
`Unable to query DB parameters: ${helpers.addError(describeParameters)}`,
region, resource);
return cb();
}

if (describeParameters.data.RunningParameters &&
describeParameters.data.RunningParameters.DBInstanceParameter &&
describeParameters.data.RunningParameters.DBInstanceParameter.length) {
let parameters = describeParameters.data.RunningParameters.DBInstanceParameter;
let found = parameters.find(parameter => parameter.ParameterName == 'log_duration' && parameter.ParameterValue.toLowerCase() == 'on');

if (found) {
helpers.addResult(results, 0,
'RDS DB instance has log_duration parameter enabled',
region, resource);
} else {
helpers.addResult(results, 2,
'RDS DB instance does not have log_duration parameter enabled',
region, resource);
}
} else {
helpers.addResult(results, 2,
'RDS DB instance does not have log_duration parameter enabled',
region, resource);
}

cb();
}, function(){
rcb();
});
}, function(){
callback(null, results, source);
});
}
};
193 changes: 193 additions & 0 deletions plugins/alibaba/rds/rdsLogDuration.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
var expect = require('chai').expect;
var rdsLogDuration = require('./rdsLogDuration.js');

const describeDBInstances = [
{
"EngineVersion": "13.0",
"DBInstanceStatus": "Running",
"ResourceGroupId": "rg-aekzsj44b4lt5fa",
"DBInstanceNetType": "Intranet",
"DBInstanceClass": "pg.n2.small.2c",
"CreateTime": "2021-05-04T17:13:45Z",
"VSwitchId": "vsw-rj94uhhrj5qz5008lwi1x",
"DBInstanceType": "Primary",
"PayType": "Postpaid",
"LockMode": "Unlock",
"MutriORsignle": false,
"InstanceNetworkType": "VPC",
"InsId": 1,
"VpcId": "vpc-rj9vu86hdve3qr173ew17",
"DBInstanceId": "pgm-2ev213kfnogf7mfi",
"ConnectionMode": "Standard",
"ReadOnlyDBInstanceIds": {
"ReadOnlyDBInstanceId": []
},
"VpcCloudInstanceId": "pgm-2ev213kfnogf7mfi",
"ExpireTime": "",
"LockReason": "",
"Engine": "PostgreSQL"
}
];

const describeParameters = [
{
"RunningParameters": {
"DBInstanceParameter": [
{
"ParameterValue": "on",
"ParameterName": "log_duration",
"ParameterDescription": "Logs the duration of each completed SQL statement."
},
{
"ParameterValue": "off",
"ParameterName": "jit",
"ParameterDescription": "allow JIT compilation"
},
{
"ParameterValue": "0",
"ParameterName": "lock_timeout",
"ParameterDescription": "Sets the maximum allowed duration of any wait for a lock. A value of 0 turns off the timeout."
},
{
"ParameterValue": "off",
"ParameterName": "log_connections",
"ParameterDescription": "Logs each successful connection."
},
{
"ParameterValue": "off",
"ParameterName": "log_disconnections",
"ParameterDescription": "Logs end of a session, including duration."
},
{
"ParameterValue": "1000",
"ParameterName": "log_min_duration_statement",
"ParameterDescription": "SQL with execution time exceeding this value will be logged. Note that a too small value may cause performance degradation and increase the amount of logs."
},
{
"ParameterValue": "ddl",
"ParameterName": "log_statement",
"ParameterDescription": "Sets the type of statements logged. Setting it to all or mod will cause performance degradation and increase the amount of logs."
},
{
"ParameterValue": "-1",
"ParameterName": "old_snapshot_threshold",
"ParameterDescription": "Time before a snapshot is too old to read pages changed after the snapshot was taken."
},
{
"ParameterValue": "disable",
"ParameterName": "sql_firewall.firewall",
"ParameterDescription": "The parameter is to detemine running mode of sql_firewall extension."
},
{
"ParameterValue": "off",
"ParameterName": "ssl",
"ParameterDescription": "Enables SSL connections."
},
{
"ParameterValue": "TLSv1",
"ParameterName": "ssl_min_protocol_version",
"ParameterDescription": "Sets the minimum SSL/TLS protocol version to use"
},
{
"ParameterValue": "0",
"ParameterName": "statement_timeout",
"ParameterDescription": "Sets the maximum allowed duration of any statement. A value of 0 turns off the timeout."
},
]
},
"EngineVersion": "13.0",
"Engine": "PostgreSQL"
},
{
"RunningParameters": {
"DBInstanceParameter": [
{
"ParameterValue": "off",
"ParameterName": "log_duration",
"ParameterDescription": "Logs the duration of each completed SQL statement."
},
]
}
}
];

const createCache = (dbInstances, describeParameters, dbInstancesErr, describeParametersErr) => {
let instanceId = (dbInstances && dbInstances.length) ? dbInstances[0].DBInstanceId : null;
return {
rds: {
DescribeDBInstances: {
'cn-hangzhou': {
data: dbInstances,
err: dbInstancesErr
},
},
DescribeParameters: {
'cn-hangzhou': {
[instanceId]: {
data: describeParameters,
err: describeParametersErr
}
}
}
},
};
};

describe('rdsLogDuration', function () {
describe('run', function () {
it('should FAIL if RDS DB instance does not have log_duration parameter enabled', function (done) {
const cache = createCache(describeDBInstances, describeParameters[1]);
rdsLogDuration.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(2);
expect(results[0].message).to.include('RDS DB instance does not have log_duration parameter enabled');
expect(results[0].region).to.equal('cn-hangzhou');
done();
});
});

it('should PASS if RDS DB instance has log_duration parameter enabled', function (done) {
const cache = createCache(describeDBInstances, describeParameters[0]);
rdsLogDuration.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
expect(results[0].message).to.include('RDS DB instance has log_duration parameter enabled');
expect(results[0].region).to.equal('cn-hangzhou');
done();
});
});

it('should PASS if no RDS DB instances found', function (done) {
const cache = createCache([]);
rdsLogDuration.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
expect(results[0].message).to.include('No RDS DB instances found');
expect(results[0].region).to.equal('cn-hangzhou');
done();
});
});

it('should UNKNOWN if unable to query RDS DB instances', function (done) {
const cache = createCache([], null, { err: 'Unable to query RDS DB instances' });
rdsLogDuration.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(3);
expect(results[0].message).to.include('Unable to query RDS DB instances');
expect(results[0].region).to.equal('cn-hangzhou');
done();
});
});

it('should UNKNOWN if unable to query DB parameters', function (done) {
const cache = createCache([describeDBInstances[0]], {}, null, { err: 'Unable to query DB parameters' });
rdsLogDuration.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(3);
expect(results[0].message).to.include('Unable to query DB parameters');
expect(results[0].region).to.equal('cn-hangzhou');
done();
});
});
})
})