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

spec: Added test case file for Blob Service Encryption plugin #599

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion plugins/azure/storageaccounts/blobServiceEncryption.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
99 changes: 99 additions & 0 deletions plugins/azure/storageaccounts/blobServiceEncryption.spec.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
});
});