From e97f19b647b09e84c1fff17f008c7dd2ba1c6e57 Mon Sep 17 00:00:00 2001 From: Wes Novack Date: Tue, 5 Jan 2021 15:43:03 -0700 Subject: [PATCH] Fix #175, handle trailing slash on endpoint Co-authored-by: Jason Nguyen Co-authored-by: Bret Hubbard { 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;