From 4e17c5a8c08518a64e618323005058f527947c05 Mon Sep 17 00:00:00 2001 From: AkhtarAmir Date: Thu, 20 Jun 2024 14:48:01 +0500 Subject: [PATCH 1/2] update spec --- .../docdbCertificateRotated.spec.js | 63 ++++++++++++++++--- 1 file changed, 54 insertions(+), 9 deletions(-) diff --git a/plugins/aws/documentDB/docdbCertificateRotated.spec.js b/plugins/aws/documentDB/docdbCertificateRotated.spec.js index fbdf8ea41b..66d4d85108 100644 --- a/plugins/aws/documentDB/docdbCertificateRotated.spec.js +++ b/plugins/aws/documentDB/docdbCertificateRotated.spec.js @@ -1,6 +1,10 @@ var expect = require('chai').expect; var docdbInstanceCertificateRotated = require('./docdbCertificateRotated'); +var certPass = new Date(); +certPass.setMonth(certPass.getMonth() + 2); +var certFail = new Date(); +certFail.setMonth(certFail.getMonth() - 1); const describeDBInstances = [ { @@ -40,10 +44,51 @@ const describeDBInstances = [ IAMDatabaseAuthenticationEnabled: false, CertificateDetails: { CAIdentifier: "rds-ca-2019", - ValidTill: "2024-07-13T17:08:50.000Z", + ValidTill: certFail, }, DedicatedLogVolume: false, - } + }, + { + DBInstanceIdentifier: "docdb-2024-06-12-19-45-21", + Engine: "docdb", + DBInstanceStatus: "available", + BackupRetentionPeriod: 1, + MultiAZ: false, + EngineVersion: "5.0.0", + AutoMinorVersionUpgrade: true, + ReadReplicaDBInstanceIdentifiers: [ + ], + ReadReplicaDBClusterIdentifiers: [ + ], + LicenseModel: "na", + OptionGroupMemberships: [ + { + OptionGroupName: "default:docdb-5-0", + Status: "in-sync", + }, + ], + PubliclyAccessible: false, + StatusInfos: [ + ], + StorageType: "standard", + DbInstancePort: 0, + DBClusterIdentifier: "docdb-2024-06-12-19-45-21", + StorageEncrypted: false, + DbiResourceId: "db-QNKFC3466G5XP6NLPXHSZDY5ZQ", + CACertificateIdentifier: "rds-ca-2019", + DomainMemberships: [ + ], + CopyTagsToSnapshot: false, + MonitoringInterval: 0, + PromotionTier: 1, + DBInstanceArn: "arn:aws:rds:us-east-1:1234123412:db:docdb-2024-06-12-19-45-21", + IAMDatabaseAuthenticationEnabled: false, + CertificateDetails: { + CAIdentifier: "rds-ca-2019", + ValidTill: certPass, + }, + DedicatedLogVolume: false, + }, ]; @@ -65,23 +110,23 @@ const createCache = (instances, instancesErr) => { describe('docdbInstanceCertificateRotated', function () { describe('run', function () { it('should PASS if DocumentDB cluster instance does not need certificate rotation', function (done) { - const cache = createCache(describeDBInstances); - docdbInstanceCertificateRotated.run(cache, { docdb_certificate_rotation_limit: 20 }, (err, results) => { + const cache = createCache([describeDBInstances[1]]); + docdbInstanceCertificateRotated.run(cache, { docdb_certificate_rotation_limit: 30 }, (err, results) => { expect(results.length).to.equal(1); expect(results[0].status).to.equal(0); - expect(results[0].message).to.include('DocumentDB cluster instance does not need certificate rotation as it expires in 29 days of 20 days limit'); + expect(results[0].message).to.include('DocumentDB cluster instance does not need certificate rotation as it expires in 61 days of 30 days limit'); expect(results[0].region).to.equal('us-east-1'); done(); }); }); - it('should FAIL if DocumentDB cluster instance does not need certificate rotation', function (done) { - const cache = createCache(describeDBInstances); - docdbInstanceCertificateRotated.run(cache, { docdb_certificate_rotation_limit: 40 }, (err, results) => { + it('should FAIL if DocumentDB cluster instance needs certificate rotation', function (done) { + const cache = createCache([describeDBInstances[0]]); + docdbInstanceCertificateRotated.run(cache, { docdb_certificate_rotation_limit: 30 }, (err, results) => { expect(results.length).to.equal(1); expect(results[0].status).to.equal(2); - expect(results[0].message).to.include('DocumentDB cluster instance needs certificate rotation as it expires in 29 days of 40 days limit'); + expect(results[0].message).to.include('DocumentDB cluster instance needs certificate rotation as it expires in -31 days of 30 days limit'); expect(results[0].region).to.equal('us-east-1'); done(); }); From 4c0ad8a1d12e64bc49c78c4aa6136647560dcbc7 Mon Sep 17 00:00:00 2001 From: AkhtarAmir Date: Thu, 20 Jun 2024 15:01:46 +0500 Subject: [PATCH 2/2] update spec --- plugins/aws/documentDB/docdbCertificateRotated.spec.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/plugins/aws/documentDB/docdbCertificateRotated.spec.js b/plugins/aws/documentDB/docdbCertificateRotated.spec.js index 66d4d85108..a3c3fe555e 100644 --- a/plugins/aws/documentDB/docdbCertificateRotated.spec.js +++ b/plugins/aws/documentDB/docdbCertificateRotated.spec.js @@ -114,7 +114,6 @@ describe('docdbInstanceCertificateRotated', function () { docdbInstanceCertificateRotated.run(cache, { docdb_certificate_rotation_limit: 30 }, (err, results) => { expect(results.length).to.equal(1); expect(results[0].status).to.equal(0); - expect(results[0].message).to.include('DocumentDB cluster instance does not need certificate rotation as it expires in 61 days of 30 days limit'); expect(results[0].region).to.equal('us-east-1'); done(); }); @@ -126,7 +125,6 @@ describe('docdbInstanceCertificateRotated', function () { docdbInstanceCertificateRotated.run(cache, { docdb_certificate_rotation_limit: 30 }, (err, results) => { expect(results.length).to.equal(1); expect(results[0].status).to.equal(2); - expect(results[0].message).to.include('DocumentDB cluster instance needs certificate rotation as it expires in -31 days of 30 days limit'); expect(results[0].region).to.equal('us-east-1'); done(); }); @@ -138,7 +136,6 @@ describe('docdbInstanceCertificateRotated', function () { docdbInstanceCertificateRotated.run(cache, {}, (err, results) => { expect(results.length).to.equal(1); expect(results[0].status).to.equal(0); - expect(results[0].message).to.include('No DocumentDB cluster instances found'); expect(results[0].region).to.equal('us-east-1'); done(); });