From e2e64ec2ecea136ad7d6fc880747d9848474d56b Mon Sep 17 00:00:00 2001 From: Ali Imran Date: Sun, 21 Mar 2021 21:59:49 +0500 Subject: [PATCH 1/4] spec: Added test case file for Client Certificates Enabled plugin --- .../appservice/clientCertEnabled.spec.js | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 plugins/azure/appservice/clientCertEnabled.spec.js diff --git a/plugins/azure/appservice/clientCertEnabled.spec.js b/plugins/azure/appservice/clientCertEnabled.spec.js new file mode 100644 index 0000000000..14e3ea9aaa --- /dev/null +++ b/plugins/azure/appservice/clientCertEnabled.spec.js @@ -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(); + }); + }); + }); +}); \ No newline at end of file From ee2e170cd548478d4e36e146d6949d920d05dc29 Mon Sep 17 00:00:00 2001 From: Ali Imran Date: Sun, 21 Mar 2021 23:23:36 +0500 Subject: [PATCH 2/4] spec: Added test case file for HTTP 2.0 Enabled plugin --- .../azure/appservice/http20Enabled.spec.js | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 plugins/azure/appservice/http20Enabled.spec.js diff --git a/plugins/azure/appservice/http20Enabled.spec.js b/plugins/azure/appservice/http20Enabled.spec.js new file mode 100644 index 0000000000..4e529776fb --- /dev/null +++ b/plugins/azure/appservice/http20Enabled.spec.js @@ -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(); + }); + }); + }); +}); \ No newline at end of file From ff9175b6cfe70fc57878a151233ba955ebb9b778 Mon Sep 17 00:00:00 2001 From: Ali Imran Date: Sun, 21 Mar 2021 23:31:45 +0500 Subject: [PATCH 3/4] spec: Added test case file for Identity Enabled plugin --- .../azure/appservice/identityEnabled.spec.js | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 plugins/azure/appservice/identityEnabled.spec.js diff --git a/plugins/azure/appservice/identityEnabled.spec.js b/plugins/azure/appservice/identityEnabled.spec.js new file mode 100644 index 0000000000..d4990fa1db --- /dev/null +++ b/plugins/azure/appservice/identityEnabled.spec.js @@ -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(); + }); + }); + }); +}); \ No newline at end of file From 47e6ffb0f0417bccaa1acbc9e7ab6e9cda3f4fc7 Mon Sep 17 00:00:00 2001 From: Ali Imran Date: Mon, 22 Mar 2021 01:52:43 +0500 Subject: [PATCH 4/4] spec/appservice --- .../azure/appservice/httpsOnlyEnabled.spec.js | 85 ++++++++++ plugins/azure/appservice/javaVersion.spec.js | 145 ++++++++++++++++++ .../appservice/netFrameworkVersion.spec.js | 145 ++++++++++++++++++ plugins/azure/appservice/phpVersion.spec.js | 145 ++++++++++++++++++ .../azure/appservice/pythonVersion.spec.js | 129 ++++++++++++++++ .../azure/appservice/tlsVersionCheck.spec.js | 125 +++++++++++++++ 6 files changed, 774 insertions(+) create mode 100644 plugins/azure/appservice/httpsOnlyEnabled.spec.js create mode 100644 plugins/azure/appservice/javaVersion.spec.js create mode 100644 plugins/azure/appservice/netFrameworkVersion.spec.js create mode 100644 plugins/azure/appservice/phpVersion.spec.js create mode 100644 plugins/azure/appservice/pythonVersion.spec.js create mode 100644 plugins/azure/appservice/tlsVersionCheck.spec.js diff --git a/plugins/azure/appservice/httpsOnlyEnabled.spec.js b/plugins/azure/appservice/httpsOnlyEnabled.spec.js new file mode 100644 index 0000000000..79feef203f --- /dev/null +++ b/plugins/azure/appservice/httpsOnlyEnabled.spec.js @@ -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(); + }); + }); + }); +}); \ No newline at end of file diff --git a/plugins/azure/appservice/javaVersion.spec.js b/plugins/azure/appservice/javaVersion.spec.js new file mode 100644 index 0000000000..de404fe86b --- /dev/null +++ b/plugins/azure/appservice/javaVersion.spec.js @@ -0,0 +1,145 @@ +var expect = require('chai').expect; +var javaVersion = require('./javaVersion'); + +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', + 'javaVersion': null + }, + { + 'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Web/sites/app1/config/web', + 'javaVersion': '1.8' + }, + { + 'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Web/sites/app1/config/web', + 'javaVersion': '1.0' + } +]; + +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('javaVersion', function() { + describe('run', function() { + it('should give passing result if no web apps', function(done) { + const cache = createCache([], []); + javaVersion.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 passing result if no java app found', function(done) { + const cache = createCache([webApps[0]], [configurations[0]]); + javaVersion.run(cache, {}, (err, results) => { + expect(results.length).to.equal(1); + expect(results[0].status).to.equal(0); + expect(results[0].message).to.include('No App Services with Java 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'); + javaVersion.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 app has no configs', function(done) { + const cache = createErrorCache('configs'); + javaVersion.run(cache, {}, (err, results) => { + expect(results.length).to.equal(2); + + expect(results[0].status).to.equal(3); + expect(results[0].message).to.include('Unable to query App Service'); + + expect(results[1].status).to.equal(0); + expect(results[1].message).to.include('No App Services with Java found'); + + expect(results[0].region).to.equal('eastus'); + done(); + }); + }); + + it('should give passing result if app has latest java version', function(done) { + const cache = createCache([webApps[0]], [configurations[1]]); + javaVersion.run(cache, {}, (err, results) => { + expect(results.length).to.equal(1); + expect(results[0].status).to.equal(0); + expect(results[0].message).to.include('The Java version (1.8) is the latest version'); + expect(results[0].region).to.equal('eastus'); + done(); + }); + }); + + it('should give failing result if app service does not have latest java version', function(done) { + const cache = createCache([webApps[0]], [configurations[2]]); + javaVersion.run(cache, {}, (err, results) => { + expect(results.length).to.equal(1); + expect(results[0].status).to.equal(2); + expect(results[0].message).to.include('The Java version (1.0) is not the latest version'); + expect(results[0].region).to.equal('eastus'); + done(); + }); + }); + }); +}); \ No newline at end of file diff --git a/plugins/azure/appservice/netFrameworkVersion.spec.js b/plugins/azure/appservice/netFrameworkVersion.spec.js new file mode 100644 index 0000000000..fac88cea7f --- /dev/null +++ b/plugins/azure/appservice/netFrameworkVersion.spec.js @@ -0,0 +1,145 @@ +var expect = require('chai').expect; +var netFrameworkVersion = require('./netFrameworkVersion'); + +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', + 'netFrameworkVersion': null + }, + { + 'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Web/sites/app1/config/web', + 'netFrameworkVersion': '4.0' + }, + { + 'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Web/sites/app1/config/web', + 'netFrameworkVersion': '3.0' + } +]; + +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('netFrameworkVersion', function() { + describe('run', function() { + it('should give passing result if no web apps', function(done) { + const cache = createCache([], []); + netFrameworkVersion.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 passing result if no .NET app found', function(done) { + const cache = createCache([webApps[0]], [configurations[0]]); + netFrameworkVersion.run(cache, {}, (err, results) => { + expect(results.length).to.equal(1); + expect(results[0].status).to.equal(0); + expect(results[0].message).to.include('No App Services with .NET 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'); + netFrameworkVersion.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 app has no configs', function(done) { + const cache = createErrorCache('configs'); + netFrameworkVersion.run(cache, {}, (err, results) => { + expect(results.length).to.equal(2); + + expect(results[0].status).to.equal(3); + expect(results[0].message).to.include('Unable to query App Service'); + + expect(results[1].status).to.equal(0); + expect(results[1].message).to.include('No App Services with .NET found'); + + expect(results[0].region).to.equal('eastus'); + done(); + }); + }); + + it('should give passing result if app has latest .NET version', function(done) { + const cache = createCache([webApps[0]], [configurations[1]]); + netFrameworkVersion.run(cache, {}, (err, results) => { + expect(results.length).to.equal(1); + expect(results[0].status).to.equal(0); + expect(results[0].message).to.include('The .NET version (4.0) is the latest version'); + expect(results[0].region).to.equal('eastus'); + done(); + }); + }); + + it('should give failing result if app service does not have latest .NET version', function(done) { + const cache = createCache([webApps[0]], [configurations[2]]); + netFrameworkVersion.run(cache, {}, (err, results) => { + expect(results.length).to.equal(1); + expect(results[0].status).to.equal(2); + expect(results[0].message).to.include('The .NET version (3.0) is not the latest version'); + expect(results[0].region).to.equal('eastus'); + done(); + }); + }); + }); +}); \ No newline at end of file diff --git a/plugins/azure/appservice/phpVersion.spec.js b/plugins/azure/appservice/phpVersion.spec.js new file mode 100644 index 0000000000..4f3afc8ec7 --- /dev/null +++ b/plugins/azure/appservice/phpVersion.spec.js @@ -0,0 +1,145 @@ +var expect = require('chai').expect; +var phpVersion = require('./phpVersion'); + +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', + 'phpVersion': null + }, + { + 'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Web/sites/app1/config/web', + 'phpVersion': '7.3' + }, + { + 'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Web/sites/app1/config/web', + 'phpVersion': '5.5' + } +]; + +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('phpVersion', function() { + describe('run', function() { + it('should give passing result if no web apps', function(done) { + const cache = createCache([], []); + phpVersion.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 passing result if no PHP app found', function(done) { + const cache = createCache([webApps[0]], [configurations[0]]); + phpVersion.run(cache, {}, (err, results) => { + expect(results.length).to.equal(1); + expect(results[0].status).to.equal(0); + expect(results[0].message).to.include('No App Services with PHP 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'); + phpVersion.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 app has no configs', function(done) { + const cache = createErrorCache('configs'); + phpVersion.run(cache, {}, (err, results) => { + expect(results.length).to.equal(2); + + expect(results[0].status).to.equal(3); + expect(results[0].message).to.include('Unable to query App Service'); + + expect(results[1].status).to.equal(0); + expect(results[1].message).to.include('No App Services with PHP found'); + + expect(results[0].region).to.equal('eastus'); + done(); + }); + }); + + it('should give passing result if app has latest PHP version', function(done) { + const cache = createCache([webApps[0]], [configurations[1]]); + phpVersion.run(cache, {}, (err, results) => { + expect(results.length).to.equal(1); + expect(results[0].status).to.equal(0); + expect(results[0].message).to.include('The PHP version (7.3) is the latest version'); + expect(results[0].region).to.equal('eastus'); + done(); + }); + }); + + it('should give failing result if app service does not have latest PHP version', function(done) { + const cache = createCache([webApps[0]], [configurations[2]]); + phpVersion.run(cache, {}, (err, results) => { + expect(results.length).to.equal(1); + expect(results[0].status).to.equal(2); + expect(results[0].message).to.include('The PHP version (5.5) is not the latest version'); + expect(results[0].region).to.equal('eastus'); + done(); + }); + }); + }); +}); \ No newline at end of file diff --git a/plugins/azure/appservice/pythonVersion.spec.js b/plugins/azure/appservice/pythonVersion.spec.js new file mode 100644 index 0000000000..56b10225e8 --- /dev/null +++ b/plugins/azure/appservice/pythonVersion.spec.js @@ -0,0 +1,129 @@ +var expect = require('chai').expect; +var pythonVersion = require('./pythonVersion'); + +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', + 'linuxFxVersion': '' + }, + { + 'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Web/sites/app1/config/web', + 'linuxFxVersion': 'PYTHON|3.6' + }, + { + 'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Web/sites/app1/config/web', + 'linuxFxVersion': 'PYTHON|2.7' + } +]; + +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('pythonVersion', function() { + describe('run', function() { + it('should give passing result if no web apps', function(done) { + const cache = createCache([], []); + pythonVersion.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 passing result if no Python app found', function(done) { + const cache = createCache([webApps[0]], [configurations[0]]); + pythonVersion.run(cache, {}, (err, results) => { + expect(results.length).to.equal(1); + expect(results[0].status).to.equal(0); + expect(results[0].message).to.include('No App Services with Python 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'); + pythonVersion.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 passing result if app has latest Python version', function(done) { + const cache = createCache([webApps[0]], [configurations[1]]); + pythonVersion.run(cache, {}, (err, results) => { + expect(results.length).to.equal(1); + expect(results[0].status).to.equal(0); + expect(results[0].message).to.include('The Python version (3.6) is the latest version'); + expect(results[0].region).to.equal('eastus'); + done(); + }); + }); + + it('should give failing result if app service does not have latest Python version', function(done) { + const cache = createCache([webApps[0]], [configurations[2]]); + pythonVersion.run(cache, {}, (err, results) => { + expect(results.length).to.equal(1); + expect(results[0].status).to.equal(2); + expect(results[0].message).to.include('The Python version (2.7) is not the latest version'); + expect(results[0].region).to.equal('eastus'); + done(); + }); + }); + }); +}); \ No newline at end of file diff --git a/plugins/azure/appservice/tlsVersionCheck.spec.js b/plugins/azure/appservice/tlsVersionCheck.spec.js new file mode 100644 index 0000000000..a91ddb2aa8 --- /dev/null +++ b/plugins/azure/appservice/tlsVersionCheck.spec.js @@ -0,0 +1,125 @@ +var expect = require('chai').expect; +var tlsVersionCheck = require('./tlsVersionCheck'); + +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', + 'minTlsVersion': '1.2' + }, + { + 'id': '/subscriptions/123/resourceGroups/aqua-resource-group/providers/Microsoft.Web/sites/app1/config/web', + 'minTlsVersion': '1.1' + } +]; + +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('tlsVersionCheck', function() { + describe('run', function() { + it('should give passing result if no web apps', function(done) { + const cache = createCache([], []); + tlsVersionCheck.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'); + tlsVersionCheck.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 app has no configs', function(done) { + const cache = createErrorCache('configs'); + tlsVersionCheck.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 satisfies Minimum TLS version criteria', function(done) { + const cache = createCache([webApps[0]], [configurations[0]]); + tlsVersionCheck.run(cache, {}, (err, results) => { + expect(results.length).to.equal(1); + expect(results[0].status).to.equal(0); + expect(results[0].message).to.include('Minimum TLS version criteria is satisfied'); + expect(results[0].region).to.equal('eastus'); + done(); + }); + }); + + it('should give failing result if app service does not satisfy Minimum TLS version criteria', function(done) { + const cache = createCache([webApps[0]], [configurations[1]]); + tlsVersionCheck.run(cache, {}, (err, results) => { + expect(results.length).to.equal(1); + expect(results[0].status).to.equal(2); + expect(results[0].message).to.include('Minimum TLS version is not 1.2'); + expect(results[0].region).to.equal('eastus'); + done(); + }); + }); + }); +}); \ No newline at end of file