FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: pass kubernetesPath into the mustache path context by emmayusufu · Pull Request #302 · nodevault/node-vault · GitHub

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
5 changes: 3 additions & 2 deletions src/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,9 @@ module.exports = (config = {}) => {
client[name] = (args = {}) => {
const options = { ...config.requestOptions, ...args.requestOptions };
options.method = conf.method;
// replace args in path.
options.path = mustache.render(conf.path, args);
// replace args in path. kubernetesPath lives on the client (not in
// args), so inject it into the template context; args still win.
options.path = mustache.render(conf.path, { kubernetesPath: client.kubernetesPath, ...args });
// no schema object -> no validation
if (!conf.schema) {
if (options.method === 'POST' || options.method === 'PUT') {
Expand Down
66 changes: 66 additions & 0 deletions test/unit.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,72 @@ describe('node-vault', () => {
})
.catch(done);
});

it('should default the kubernetes mount point in kubernetesLogin path', (done) => {
const request = sinon.stub();
const response = sinon.stub();
response.statusCode = 200;
response.body = { auth: { client_token: 'test-token' } };
request.returns({
then(fn) {
return fn(response);
},
catch(fn) {
return fn();
},
});

const vault = index({
endpoint: 'http://localhost:8200',
token: '123',
'request-promise': {
defaults: () => request,
},
});

vault.kubernetesLogin({ role: 'my-role', jwt: 'my-jwt' })
.then(() => {
request.should.have.calledOnce();
const uri = request.firstCall.args[0].uri;
uri.should.equal('http://localhost:8200/v1/auth/kubernetes/login');
uri.should.not.contain('/auth//login');
done();
})
.catch(done);
});

it('should use a custom kubernetesPath in kubernetesLogin path', (done) => {
const request = sinon.stub();
const response = sinon.stub();
response.statusCode = 200;
response.body = { auth: { client_token: 'test-token' } };
request.returns({
then(fn) {
return fn(response);
},
catch(fn) {
return fn();
},
});

const vault = index({
endpoint: 'http://localhost:8200',
token: '123',
kubernetesPath: 'k8s-prod',
'request-promise': {
defaults: () => request,
},
});

vault.kubernetesLogin({ role: 'my-role', jwt: 'my-jwt' })
.then(() => {
request.should.have.calledOnce();
const uri = request.firstCall.args[0].uri;
uri.should.equal('http://localhost:8200/v1/auth/k8s-prod/login');
done();
})
.catch(done);
});
});

describe('client', () => {
Expand Down

Back | FazBrowse Home | New Git URL