diff --git a/src/index.js b/src/index.js index 6d18116c..22bd84c9 100644 --- a/src/index.js +++ b/src/index.js @@ -71,6 +71,8 @@ module.exports = (config = {}) => { client.noCustomHTTPVerbs = config.noCustomHTTPVerbs || false; client.namespace = config.namespace || process.env.VAULT_NAMESPACE; + client.endpoint = client.endpoint.replace(/\/$/, ''); + const requestSchema = { type: 'object', properties: { diff --git a/test/unit.js b/test/unit.js index aa28d082..805e5b60 100644 --- a/test/unit.js +++ b/test/unit.js @@ -87,6 +87,31 @@ describe('node-vault', () => { }); }); + describe('client initialization', () => { + it('should not trim endpoint if no trailing slash', () => { + const defaultsStub = sinon.stub(); + const vaultConfig = { + endpoint: 'http://localhost:8200', + 'request-promise': { + defaults: defaultsStub, + }, + }; + const vault = index(vaultConfig); + vault.endpoint.should.equal('http://localhost:8200'); + }); + + it('should trim endpoint if trailing slash', () => { + const defaultsStub = sinon.stub(); + const vaultConfig = { + endpoint: 'http://localhost:8200/', + 'request-promise': { + defaults: defaultsStub, + }, + }; + const vault = index(vaultConfig); + vault.endpoint.should.equal('http://localhost:8200'); + }); + }); describe('client', () => { let request = null;