From 06ec1bccba6464c2659d3a9c1a40313d49e3d5a6 Mon Sep 17 00:00:00 2001 From: Ali Imran Date: Sun, 21 Mar 2021 18:48:37 +0500 Subject: [PATCH] spec: Added test case file for Blob Service Encryption plugin --- .../storageaccounts/blobServiceEncryption.js | 2 +- .../blobServiceEncryption.spec.js | 99 +++++++++++++++++++ 2 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 plugins/azure/storageaccounts/blobServiceEncryption.spec.js diff --git a/plugins/azure/storageaccounts/blobServiceEncryption.js b/plugins/azure/storageaccounts/blobServiceEncryption.js index fec0dd4f21..a94cd03825 100644 --- a/plugins/azure/storageaccounts/blobServiceEncryption.js +++ b/plugins/azure/storageaccounts/blobServiceEncryption.js @@ -30,7 +30,7 @@ module.exports = { if (storageAccounts.err || !storageAccounts.data) { helpers.addResult(results, 3, - 'Unable to query for for storage accounts: ' + helpers.addError(storageAccounts), location); + 'Unable to query for storage accounts: ' + helpers.addError(storageAccounts), location); return rcb(); } diff --git a/plugins/azure/storageaccounts/blobServiceEncryption.spec.js b/plugins/azure/storageaccounts/blobServiceEncryption.spec.js new file mode 100644 index 0000000000..fa589c2f11 --- /dev/null +++ b/plugins/azure/storageaccounts/blobServiceEncryption.spec.js @@ -0,0 +1,99 @@ +var expect = require('chai').expect; +var blobServiceIEncryption = require('./blobServiceEncryption'); + +const storageAccounts = [ + { + 'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Storage/storageAccounts/acc', + 'location': 'eastus', + 'name': 'acc', + 'encryption': { + 'services': { + 'blob': { + 'enabled': true + } + } + } + }, + { + 'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Storage/storageAccounts/acc', + 'location': 'eastus', + 'name': 'acc', + 'encryption': { + 'services': { + 'blob': { + 'enabled': false + } + } + } + } +]; + +const createCache = (storageAccounts) => { + return { + storageAccounts: { + list: { + 'eastus': { + data: storageAccounts + } + } + } + }; +}; + +const createErrorCache = () => { + return { + storageAccounts: { + list: { + 'eastus': {} + } + } + }; +}; + +describe('blobServiceEncryption', function() { + describe('run', function() { + it('should give passing result if no storage accounts', function(done) { + const cache = createCache([]); + blobServiceIEncryption.run(cache, {}, (err, results) => { + expect(results.length).to.equal(1); + expect(results[0].status).to.equal(0); + expect(results[0].message).to.include('No storage accounts found'); + expect(results[0].region).to.equal('eastus'); + done(); + }); + }); + + it('should give unknown result if unable to query for storage accounts', function(done) { + const cache = createErrorCache(); + blobServiceIEncryption.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 for storage accounts'); + expect(results[0].region).to.equal('eastus'); + done(); + }); + }); + + it('should give passing result if blob encryption is enabled', function(done) { + const cache = createCache([storageAccounts[0]]); + blobServiceIEncryption.run(cache, {}, (err, results) => { + expect(results.length).to.equal(1); + expect(results[0].status).to.equal(0); + expect(results[0].message).to.include('Blob encryption is enabled'); + expect(results[0].region).to.equal('eastus'); + done(); + }); + }); + + it('should give failing result if blob encryption is not enabled', function(done) { + const cache = createCache([storageAccounts[1]]); + blobServiceIEncryption.run(cache, {}, (err, results) => { + expect(results.length).to.equal(1); + expect(results[0].status).to.equal(2); + expect(results[0].message).to.include('Blob encryption is not enabled'); + expect(results[0].region).to.equal('eastus'); + done(); + }); + }); + }); +}); \ No newline at end of file