Skip to content

Commit

Permalink
Revised keyVaultSecretExpiryNonRbac
Browse files Browse the repository at this point in the history
  • Loading branch information
AkhtarAmir authored and AkhtarAmir committed Nov 6, 2024
1 parent 262aa08 commit d83a461
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions plugins/azure/keyvaults/keyVaultSecretExpiryNonRbac.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var expect = require('chai').expect;
var auth = require('./keyVaultSecretExpiry');
var auth = require('./keyVaultSecretExpiryNonRbac');

var secretExpiryPass = new Date();
secretExpiryPass.setMonth(secretExpiryPass.getMonth() + 2);
Expand All @@ -20,9 +20,12 @@ const listKeyVaults = [
"sku": {
"family": "A",
"name": "Standard"
},
"properties": {
"enableRbacAuthorization": false // Non-RBAC vault
}
},
{
{
"id": "/subscriptions/abcdef123-ebf6-437f-a3b0-28fc0d22117e/resourceGroups/Default-ActivityLogAlerts/providers/Microsoft.KeyVault/vaults/testvault",
"name": "testvault",
"type": "Microsoft.KeyVault/vaults",
Expand All @@ -31,6 +34,9 @@ const listKeyVaults = [
"sku": {
"family": "A",
"name": "Standard"
},
"properties": {
"enableRbacAuthorization": true // RBAC vault
}
}
];
Expand Down Expand Up @@ -138,7 +144,7 @@ const createCache = (err, list, get) => {
}
};

describe('keyVaultSecretExpiry', function() {
describe('keyVaultSecretExpiryNonRbac', function() {
describe('run', function() {
it('should give passing result if no secrets found', function(done) {
const callback = (err, results) => {
Expand All @@ -152,7 +158,19 @@ describe('keyVaultSecretExpiry', function() {
auth.run(createCache(null, [], {}), {}, callback);
});

it('should give passing result if secret expiration is not enabled', function(done) {
it('should give passing result if vault is RBAC-enabled', function(done) {
const callback = (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
expect(results[0].message).to.include('Key Vault is RBAC-enabled');
expect(results[0].region).to.equal('eastus');
done()
};

auth.run(createCache(null, [listKeyVaults[1]], {}), {}, callback);
});

it('should give passing result if secret expiration is not enabled in non-RBAC vault', function(done) {
const callback = (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
Expand All @@ -164,7 +182,7 @@ describe('keyVaultSecretExpiry', function() {
auth.run(createCache(null, [listKeyVaults[0]], getSecrets[0]), {}, callback);
});

it('should give passing result if secret expiry is not yet reached', function(done) {
it('should give passing result if secret expiry is not yet reached in non-RBAC vault', function(done) {
const callback = (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
Expand Down

0 comments on commit d83a461

Please sign in to comment.