Skip to content

Commit

Permalink
handle trailing slash on endpoint
Browse files Browse the repository at this point in the history
based on nodevault#176

fixes nodevault#175

Co-authored-by: Jason Nguyen <[email protected]>
Co-authored-by: Bret Hubbard <[email protected]
  • Loading branch information
MichaelSp and GoFightNguyen committed Apr 24, 2022
1 parent 9b2432c commit 079bde1
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 @@ -89,6 +89,8 @@ function NodeVault(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 @@ -80,6 +80,31 @@ describe('vaultaire', () => {
});
});

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 = NodeVault(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 = NodeVault(vaultConfig);
vault.endpoint.should.equal('http://localhost:8200');
});
});

describe('client', () => {
let request = null;
Expand Down

0 comments on commit 079bde1

Please sign in to comment.