Skip to content

Commit e97f19b

Browse files
Fix #175, handle trailing slash on endpoint
Co-authored-by: Jason Nguyen <jason-nguyen@pluralsight.com> Co-authored-by: Bret Hubbard <bret-hubbard@pluralsight.com
1 parent 7009726 commit e97f19b

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ module.exports = (config = {}) => {
7171
client.noCustomHTTPVerbs = config.noCustomHTTPVerbs || false;
7272
client.namespace = config.namespace || process.env.VAULT_NAMESPACE;
7373

74+
client.endpoint = client.endpoint.replace(/\/$/, '');
75+
7476
const requestSchema = {
7577
type: 'object',
7678
properties: {

test/unit.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,31 @@ describe('node-vault', () => {
8787
});
8888
});
8989

90+
describe('client initialization', () => {
91+
it('should not trim endpoint if no trailing slash', () => {
92+
const defaultsStub = sinon.stub();
93+
const vaultConfig = {
94+
endpoint: 'http://localhost:8200',
95+
'request-promise': {
96+
defaults: defaultsStub,
97+
},
98+
};
99+
const vault = index(vaultConfig);
100+
vault.endpoint.should.equal('http://localhost:8200');
101+
});
102+
103+
it('should trim endpoint if trailing slash', () => {
104+
const defaultsStub = sinon.stub();
105+
const vaultConfig = {
106+
endpoint: 'http://localhost:8200/',
107+
'request-promise': {
108+
defaults: defaultsStub,
109+
},
110+
};
111+
const vault = index(vaultConfig);
112+
vault.endpoint.should.equal('http://localhost:8200');
113+
});
114+
});
90115

91116
describe('client', () => {
92117
let request = null;

0 commit comments

Comments
 (0)