Skip to content
This repository was archived by the owner on Mar 11, 2022. It is now read-only.

Commit 0218c86

Browse files
authored
allow basic-auth url in vcap_services - fixes issue #327 (#328)
* allow basic-auth url in vcap_services - fixes issue #327 * updated CHANGES.md * construct URL from username/password/host from VCAP instead of using url * encode the host too
1 parent 6062647 commit 0218c86

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# UNRELEASED
22
- [FIXED] Case where `username` and `password` options were not used if a `url` was supplied.
3+
- [FIXED] Case where vcapServices was supplied with a basic-auth url
34

45
# 2.3.0 (2018-06-08)
56
- [FIXED] Removed addition of `statusCode` to response objects returned by promises.

lib/reconfigure.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ module.exports = function(config) {
9494
outUrl = 'https://' + encodeURIComponent(credentials.host);
9595
if (credentials.apikey) {
9696
outCreds.iamApiKey = credentials.apikey;
97+
} else if (credentials.username && credentials.password) {
98+
outUrl = 'https://' + encodeURIComponent(credentials.username) + ':' +
99+
encodeURIComponent(credentials.password) + '@' + encodeURIComponent(credentials.host);
97100
}
98101
break;
99102
} else {

test/legacy/reconfigure.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,15 @@ describe('Reconfigure', function() {
246246
done();
247247
});
248248

249+
// Issue cloudant/nodejs-cloudant#327
250+
it('allows a vcap_services basic-auth url', function(done) {
251+
var credentials = { vcapServices: {"cloudantNoSQLDB":[{"credentials":{"username":"x","password":"y","host":"z.cloudant.com","port":443,"url":"https://x:[email protected]"},"syslog_drain_url":null,"volume_mounts":[],"label":"cloudantNoSQLDB","provider":null,"plan":"Shared","name":"iot-cloudantNoSQLDB","tags":["data_management","ibm_created","lite","ibm_dedicated_public"]}]} };
252+
var outCreds = reconfigure(credentials);
253+
outCreds.outUrl.should.be.a.String;
254+
outCreds.outUrl.should.equal('https://x:[email protected]');
255+
done();
256+
});
257+
249258
it('errors for empty vcap', function(done) {
250259
var config = {vcapServices: {}};
251260
should(function() { reconfigure(config); }).throw('Missing Cloudant service in vcapServices');

0 commit comments

Comments
 (0)