Skip to content

Commit 7e03e25

Browse files
Copilotaviadhahami
andcommitted
Fix #175: strip trailing slash from endpoint to prevent double slashes in URIs
Co-authored-by: aviadhahami <7353632+aviadhahami@users.noreply.github.com> Agent-Logs-Url: https://github.com/nodevault/node-vault/sessions/18acbdc1-2e5a-4a10-8209-9c26eefda931
1 parent 2fbea1c commit 7e03e25

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ module.exports = (config = {}) => {
198198
client.namespace = config.namespace || process.env.VAULT_NAMESPACE;
199199
client.kubernetesPath = config.kubernetesPath || 'kubernetes';
200200

201+
client.endpoint = client.endpoint.replace(/\/$/, '');
202+
201203
const requestSchema = {
202204
type: 'object',
203205
properties: {

test/unit.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,32 @@ 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+
});
115+
90116
describe('client', () => {
91117
let request = null;
92118
let response = null;

0 commit comments

Comments
 (0)