Skip to content
This repository was archived by the owner on Mar 9, 2025. It is now read-only.

Commit 079bde1

Browse files
handle trailing slash on endpoint
based on nodevault#176 fixes nodevault#175 Co-authored-by: Jason Nguyen <jason-nguyen@pluralsight.com> Co-authored-by: Bret Hubbard <bret-hubbard@pluralsight.com
1 parent 9b2432c commit 079bde1

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ function NodeVault(config = {}) {
8989
client.noCustomHTTPVerbs = config.noCustomHTTPVerbs || false;
9090
client.namespace = config.namespace || process.env.VAULT_NAMESPACE;
9191

92+
client.endpoint = client.endpoint.replace(/\/$/, '');
93+
9294
const requestSchema = {
9395
type: 'object',
9496
properties: {

test/unit.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,31 @@ describe('vaultaire', () => {
8080
});
8181
});
8282

83+
describe('client initialization', () => {
84+
it('should not trim endpoint if no trailing slash', () => {
85+
const defaultsStub = sinon.stub();
86+
const vaultConfig = {
87+
endpoint: 'http://localhost:8200',
88+
'request-promise': {
89+
defaults: defaultsStub,
90+
},
91+
};
92+
const vault = NodeVault(vaultConfig);
93+
vault.endpoint.should.equal('http://localhost:8200');
94+
});
95+
96+
it('should trim endpoint if trailing slash', () => {
97+
const defaultsStub = sinon.stub();
98+
const vaultConfig = {
99+
endpoint: 'http://localhost:8200/',
100+
'request-promise': {
101+
defaults: defaultsStub,
102+
},
103+
};
104+
const vault = NodeVault(vaultConfig);
105+
vault.endpoint.should.equal('http://localhost:8200');
106+
});
107+
});
83108

84109
describe('client', () => {
85110
let request = null;

0 commit comments

Comments
 (0)