Skip to content

Commit

Permalink
commited
Browse files Browse the repository at this point in the history
  • Loading branch information
AkhtarAmir authored and AkhtarAmir committed Jun 20, 2024
2 parents 9274552 + 5ad172e commit 0c5b98a
Showing 1 changed file with 52 additions and 10 deletions.
62 changes: 52 additions & 10 deletions plugins/aws/documentDB/docdbCertificateRotated.spec.js
Original file line number Diff line number Diff line change
@@ -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 = [
{
Expand Down Expand Up @@ -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,
},
];


Expand All @@ -65,23 +110,21 @@ 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].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].region).to.equal('us-east-1');
done();
});
Expand All @@ -93,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();
});
Expand Down

0 comments on commit 0c5b98a

Please sign in to comment.