var expect = require('chai').expect; var workspacePublicAccess = require('./workspacePublicAccess.js'); const workspaces = [ { "managedResourceGroupId": "/subscriptions/1234/resourceGroups/test", "publicNetworkAccess": "Enabled", "id": "/subscriptions/1234/resourceGroups/test/providers/Microsoft.Databricks/workspaces/test-workspace", "name": "test-workspace", "type": "Microsoft.Databricks/workspaces", "sku": { "name": "premium" }, "location": "eastus", "tags": {} }, { "managedResourceGroupId": "/subscriptions/1234/resourceGroups/test", "publicNetworkAccess": "Disabled", "id": "/subscriptions/1234/resourceGroups/test/providers/Microsoft.Databricks/workspaces/test-workspace", "name": "test-workspace", "type": "Microsoft.Databricks/workspaces", "sku": { "name": "premium" }, "location": "eastus", "tags": {} }, ]; const createCache = (workspaces, err) => { return { databricks: { listWorkspaces: { 'eastus': { data: workspaces, err: err } } } }; }; describe('workspacePublicAccess', function () { describe('run', function () { it('should give a passing result if no Databricks workspaces are found', function (done) { const cache = createCache([], null); workspacePublicAccess.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 Databricks Workspaces found'); expect(results[0].region).to.equal('eastus'); done(); }); }); it('should give unknown result if unable to query for Databricks workspaces', function (done) { const cache = createCache(null, ['error']); workspacePublicAccess.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 Databricks Workspaces'); expect(results[0].region).to.equal('eastus'); done(); }); }); it('should give passing result if Databricks workspace has public network access disabled', function (done) { const cache = createCache([workspaces[1]], null); workspacePublicAccess.run(cache, {}, (err, results) => { expect(results.length).to.equal(1); expect(results[0].status).to.equal(0); expect(results[0].message).to.include('Databricks workspace has public network access disabled'); expect(results[0].region).to.equal('eastus'); done(); }); }); it('should give failing result if Databricks workspace has public network access enabled', function (done) { const cache = createCache([workspaces[0]], null); workspacePublicAccess.run(cache, {}, (err, results) => { expect(results.length).to.equal(1); expect(results[0].status).to.equal(2); expect(results[0].message).to.include('Databricks workspace has public network access enabled'); expect(results[0].region).to.equal('eastus'); done(); }); }); }); });