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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/index.js
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
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