after(function (done) { this.timeout(5000); helpers.isVaultReady(myVault).then(function () { done(); }).catch(function onError(err) { debuglog('Vault NOT Ready: ', err); done(err); }); });
describe('#getAuthMounts', function () { it('should reject with an Error if not initialized or unsealed', function () { return newVault.getAuthMounts().should.be.rejectedWith(/Vault has not been initialized/); }); it('should update internal state with list of auth mounts', function () { return myVault.getAuthMounts().then(function (auths) { debuglog(auths); auths.should.not.be.empty; auths.should.contain.keys('token/'); }); }); });
it('should reject with an Error if the provided ciphertext has a valid prefix but is invalid', function () { return myVault.rewrapTransitCipherText({ id: 'rewrappingkey', body: { ciphertext: 'vault:v1:foobarbaz' } }).catch(function (err) { debuglog(err); return testVaultErrors(err, /invalid ciphertext: could not decode base64/); }); });
rp(options).then(function (data) { return data.ID; }).catch(function (err) { debuglog('createConsulToken failed: ', err); return null; })
function logError (error) { const isServiceError = error instanceof ChatServiceError if (!isServiceError) { debuglog(error) } return Promise.reject(error) }
Promise.delay(500).then(function () { return vault.checkHealth().then(function (status) { debuglog('Vault Ready: ', status); }).catch(function (err) { if (err.statusCode === 429) { debuglog('Vault was not ready after first check so try again!'); return Promise.delay(500).then(function () { vault.checkHealth(); }); } }); })
callMethod(method, params) { return new Promise((resolve, reject) => { if (!this._socket) { reject(new Error('Use `run` to start the app again.')); return; } const data = { id: ++this._lastId, method, params }; this._pending[data.id] = (error, result) => { if (error) reject(unpackError(error)); else resolve(isEmpty(result) ? undefined : result); }; const json = JSON.stringify(data); debuglog('> %s', json); this._socket.write(encodeFrameHybi17(Buffer.from(json))); }); }
function debugEval(input, context, filename, callback) { debuglog('eval:', input); function returnToCallback(error, result) { debuglog('end-eval:', input, error); callback(error, result); } try { const result = evalInCurrentContext(input); if (result && typeof result.then === 'function') { toCallback(result, returnToCallback); return; } returnToCallback(null, result); } catch (e) { returnToCallback(e); } }
describe('#getCertCa', function () { it('should reject with an Error if not initialized or unsealed', function () { return newVault.getCertCa().should.be.rejectedWith(/Vault has not been initialized/); }); it('should resolve when all required and valid inputs provided', function () { return myVault.getCertCa().then(function (cert) { debuglog(cert); expect(cert).not.to.be.undefined; expect(cert).not.to.be.null; cert.should.have.property('data'); expect(cert.data).not.to.be.undefined; expect(cert.data).not.to.be.null; cert.data.should.have.property('certificate'); expect(cert.data.certificate).not.to.be.undefined; expect(cert.data.certificate).not.to.be.null; }); }); });
after(function () { return myVault.deleteMount({ id: 'pki' }).catch(function (err) { debuglog('deleteMount pki failed:', err); }); });
function controlEval(input, context, filename, callback) { debuglog('eval:', input); function returnToCallback(error, result) { debuglog('end-eval:', input, error); callback(error, result); } try { const code = prepareControlCode(input); const result = vm.runInContext(code, context, filename); if (result && typeof result.then === 'function') { toCallback(result, returnToCallback); return; } returnToCallback(null, result); } catch (e) { returnToCallback(e); } }
describe('#getPolicies', function () { it('should reject with an Error if not initialized or unsealed', function () { return newVault.getPolicies().should.be.rejectedWith(/Vault has not been initialized/); }); it('should resolve to updated list of policies', function () { return myVault.getPolicies().then(function (data) { debuglog(data); data.policies.should.not.be.empty; data.policies.should.contain('root'); }); }); });
describe('#getMounts', function () { it('should reject with an Error if not initialized or unsealed', function () { return newVault.getMounts().should.be.rejectedWith(/Vault has not been initialized/); }); it('should update internal state with list of mounts', function () { return myVault.getMounts().then(function (mounts) { debuglog(mounts); mounts.should.not.be.empty; mounts.should.contain.keys('sys/'); }); }); });
it('should reject with an Error if the provided ciphertext is invalid', function () { return myVault.rewrapTransitCipherText({ id: 'rewrappingkey', body: { ciphertext: 'foobarbaz' } }).catch(function (err) { debuglog(err); return testVaultErrors(err, /invalid ciphertext: no prefix/); }); });