UNPKG

@bugcrowd/briareus

Version:

Briareus assists with Feature Branch deploys to ECS

95 lines (86 loc) 2.46 kB
'use strict' const expect = require('expect.js'); const httpMocks = require('node-mocks-http'); const helpers = require('../../helpers'); const mw = require('../../../lib/service/middleware'); const errors = require('../../../lib/service/errors'); describe('Middleware:ValidateDeploymentScopes', function () { it('Should fail validation when duplicate envs / secrets are listed', function (done) { const validateDeploymentScopes = mw.validateDeploymentScopes(); const req = httpMocks.createRequest(); const res = httpMocks.createResponse(); req.body = { scopes: { app: { containers: ['web', 'worker'], secrets: { API_KEY: 'encrypted blob' }, envs: { API_KEY: 'duplicate key' } } } }; validateDeploymentScopes(req, res, (err) => { expect(err instanceof errors.InputValidationError).to.equal(true); let resErrors = err.responseBody.errors; expect(resErrors.length).to.equal(2); done() }); }); it('Should set envs and secrets on request body when no validation errors', function (done) { const validateDeploymentScopes = mw.validateDeploymentScopes(); const req = httpMocks.createRequest(); const res = httpMocks.createResponse(); req.body = { scopes: { app: { containers: ['web', 'worker'], secrets: { API_KEY: 'encrypted blob' }, envs: { HOST: 'host.bugcrowd.engineering' } } } }; validateDeploymentScopes(req, res, (err) => { expect(err).to.equal(undefined); expect(req.body.envs).to.eql([ { id: 'web/HOST', scope: 'app', container: 'web', name: 'HOST', value: 'host.bugcrowd.engineering' }, { id: 'worker/HOST', scope: 'app', container: 'worker', name: 'HOST', value: 'host.bugcrowd.engineering' } ]); expect(req.body.secrets).to.eql([ { id: 'web/API_KEY', scope: 'app', container: 'web', name: 'API_KEY', value: 'encrypted blob' }, { id: 'worker/API_KEY', scope: 'app', container: 'worker', name: 'API_KEY', value: 'encrypted blob' } ]) done() }); }); });