Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
Fix nodevault#175, handle trailing slash on endpoint
Browse files Browse the repository at this point in the history
Co-authored-by: Jason Nguyen <[email protected]>
Co-authored-by: Bret Hubbard <[email protected]
  • Loading branch information
wes-novack and GoFightNguyen committed Jan 5, 2021
1 parent 7009726 commit e97f19b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
25 changes: 25 additions & 0 deletions test/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e97f19b

Please sign in to comment.