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/appservice #612

Merged
merged 6 commits into from
Mar 26, 2021
Merged
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
85 changes: 85 additions & 0 deletions plugins/azure/appservice/clientCertEnabled.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
var expect = require('chai').expect;
var clientCertEnabled = require('./clientCertEnabled');

const webApps = [
{
'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Web/sites/app1',
'name': 'app1',
'clientCertEnabled': true
},
{
'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Web/sites/app1',
'name': 'app1',
'clientCertEnabled': false
}
];

const createCache = (webApps) => {
return {
webApps: {
list: {
'eastus':{
data: webApps
}
}
}
};
};

const createErrorCache = () => {
return {
webApps: {
list: {
'eastus': {}
}
}
};
};

describe('clientCertEnabled', function() {
describe('run', function() {
it('should give passing result if no web apps', function(done) {
const cache = createCache([]);
clientCertEnabled.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
expect(results[0].message).to.include('No existing App Services found');
expect(results[0].region).to.equal('eastus');
done();
});
});

it('should give unknown result if unable to query app service', function(done) {
const cache = createErrorCache();
clientCertEnabled.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 App Service');
expect(results[0].region).to.equal('eastus');
done();
});
});

it('should give passing result if app service has client certificates enabled', function(done) {
const cache = createCache([webApps[0]]);
clientCertEnabled.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
expect(results[0].message).to.include('The App Service has Client Certificates enabled');
expect(results[0].region).to.equal('eastus');
done();
});
});

it('should give failing result if app service does not have client certificates enabled', function(done) {
const cache = createCache([webApps[1]]);
clientCertEnabled.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(2);
expect(results[0].message).to.include('The App Service does not have Client Certificates enabled');
expect(results[0].region).to.equal('eastus');
done();
});
});
});
});
125 changes: 125 additions & 0 deletions plugins/azure/appservice/http20Enabled.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
var expect = require('chai').expect;
var http20Enabled = require('./http20Enabled');

const webApps = [
{
'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Web/sites/app1',
'name': 'app1'
}
];

const configurations = [
{
'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Web/sites/app1/config/web',
'http20Enabled': true
},
{
'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Web/sites/app1/config/web',
'http20Enabled': false
}
];

const createCache = (webApps, configurations) => {
let configs = {};
if (webApps.length > 0) {
configs[webApps[0].id] = {
data: configurations
};
}
return {
webApps: {
list: {
'eastus': {
data: webApps
}
},
listConfigurations: {
'eastus': configs
}
}
};
};

const createErrorCache = (key) => {
if (key === 'webApp') {
return {
webApps: {
list: {
'eastus': {}
}
}
};
} else {
return {
webApps: {
list: {
'eastus': {
data: [webApps[0]]
}
},
listConfigurations: {
'eastus': {}
}
}
};
}
};

describe('http20Enabled', function() {
describe('run', function() {
it('should give passing result if no web apps', function(done) {
const cache = createCache([], []);
http20Enabled.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
expect(results[0].message).to.include('No existing App Services found');
expect(results[0].region).to.equal('eastus');
done();
});
});

it('should give unknown result if unable to query for app service', function(done) {
const cache = createErrorCache('webApp');
http20Enabled.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 App Services');
expect(results[0].region).to.equal('eastus');
done();
});
});

it('should give unknown result if unable to query app service', function(done) {
const cache = createErrorCache('configs');
http20Enabled.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 App Service');
expect(results[0].region).to.equal('eastus');
done();
});
});

it('should give passing result if app service has http 2.0 enabled', function(done) {
const cache = createCache([webApps[0]], [configurations[0]]);
http20Enabled.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
expect(results[0].message).to.include('App Service has HTTP 2.0 enabled');
expect(results[0].region).to.equal('eastus');
done();
});
});

it('should give failing result if app service does not have http 2.0 enabled', function(done) {
const cache = createCache([webApps[0]], [configurations[1]]);
http20Enabled.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(2);
expect(results[0].message).to.include('App Service does not have HTTP 2.0 enabled');
expect(results[0].region).to.equal('eastus');
done();
});
});
});
});
85 changes: 85 additions & 0 deletions plugins/azure/appservice/httpsOnlyEnabled.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
var expect = require('chai').expect;
var httpsOnlyEnabled = require('./httpsOnlyEnabled');

const webApps = [
{
'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Web/sites/app1',
'name': 'app1',
'httpsOnly': true
},
{
'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Web/sites/app1',
'name': 'app1',
'httpsOnly': false
}
];

const createCache = (webApps) => {
return {
webApps: {
list: {
'eastus':{
data: webApps
}
}
}
};
};

const createErrorCache = () => {
return {
webApps: {
list: {
'eastus': {}
}
}
};
};

describe('httpsOnlyEnabled', function() {
describe('run', function() {
it('should give passing result if no web apps', function(done) {
const cache = createCache([]);
httpsOnlyEnabled.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
expect(results[0].message).to.include('No existing App Services found');
expect(results[0].region).to.equal('eastus');
done();
});
});

it('should give unknown result if unable to query app service', function(done) {
const cache = createErrorCache();
httpsOnlyEnabled.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 App Service');
expect(results[0].region).to.equal('eastus');
done();
});
});

it('should give passing result if app service has HTTPS only enabled', function(done) {
const cache = createCache([webApps[0]]);
httpsOnlyEnabled.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
expect(results[0].message).to.include('The App Service has HTTPS Only enabled');
expect(results[0].region).to.equal('eastus');
done();
});
});

it('should give failing result if app service does not have HTTPS only enabled', function(done) {
const cache = createCache([webApps[1]]);
httpsOnlyEnabled.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(2);
expect(results[0].message).to.include('The App Service does not have HTTPS Only enabled');
expect(results[0].region).to.equal('eastus');
done();
});
});
});
});
85 changes: 85 additions & 0 deletions plugins/azure/appservice/identityEnabled.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
var expect = require('chai').expect;
var identityEnabled = require('./identityEnabled');

const webApps = [
{
'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Web/sites/app1',
'name': 'app1',
'identity': true
},
{
'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Web/sites/app1',
'name': 'app1',
'identity': false
}
];

const createCache = (webApps) => {
return {
webApps: {
list: {
'eastus':{
data: webApps
}
}
}
};
};

const createErrorCache = () => {
return {
webApps: {
list: {
'eastus': {}
}
}
};
};

describe('identityEnabled', function() {
describe('run', function() {
it('should give passing result if no web apps', function(done) {
const cache = createCache([]);
identityEnabled.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
expect(results[0].message).to.include('No existing App Services found');
expect(results[0].region).to.equal('eastus');
done();
});
});

it('should give unknown result if unable to query app service', function(done) {
const cache = createErrorCache();
identityEnabled.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 App Service');
expect(results[0].region).to.equal('eastus');
done();
});
});

it('should give passing result if app service has identity assigned', function(done) {
const cache = createCache([webApps[0]]);
identityEnabled.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(0);
expect(results[0].message).to.include('The App Service has identities assigned');
expect(results[0].region).to.equal('eastus');
done();
});
});

it('should give failing result if app service app service does not have any identity assigned', function(done) {
const cache = createCache([webApps[1]]);
identityEnabled.run(cache, {}, (err, results) => {
expect(results.length).to.equal(1);
expect(results[0].status).to.equal(2);
expect(results[0].message).to.include('The App Service does not have an identity assigned');
expect(results[0].region).to.equal('eastus');
done();
});
});
});
});
Loading