Skip to content

Commit 7e814cf

Browse files
committed
Strip Heroku-style usernames from config url
1 parent 7eb606b commit 7e814cf

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

lib/redis.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = CoreObject.extend({
88
var redisLib = lib;
99

1010
if (options.url) {
11-
redisOptions = options.url;
11+
redisOptions = this._stripUsernameFromConfigUrl(options.url);
1212
} else {
1313
redisOptions = {
1414
host: options.host,
@@ -211,5 +211,16 @@ module.exports = CoreObject.extend({
211211
}
212212
});
213213
});
214+
},
215+
216+
_stripUsernameFromConfigUrl: function(configUrl) {
217+
var regex = /redis:\/\/(\w+):(\w+)(.*)/;
218+
var matches = configUrl.match(regex);
219+
220+
if (matches) {
221+
configUrl = 'redis://:' + matches[2] + matches[3];
222+
}
223+
224+
return configUrl;
214225
}
215226
});

tests/unit/index-nodetest.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,58 @@ describe('redis plugin', function() {
9595
assert.equal(redisLib.createdClient.options.database, 4);
9696
});
9797

98+
describe('handles redis urls appropriately', function() {
99+
it('handles pre-stripped urls without a username', function () {
100+
101+
var plugin = subject.createDeployPlugin({
102+
name: 'redis'
103+
});
104+
105+
var redisLib = new FakeRedis();
106+
107+
var context = {
108+
ui: mockUi,
109+
project: stubProject,
110+
config: {
111+
redis: {
112+
url: 'redis://:password@host.amazonaws.com:6379/4'
113+
}
114+
},
115+
_redisLib: redisLib
116+
};
117+
plugin.beforeHook(context);
118+
plugin.configure(context);
119+
plugin.readConfig('redisDeployClient');
120+
121+
assert.equal(redisLib.createdClient.options, 'redis://:password@host.amazonaws.com:6379/4');
122+
});
123+
124+
it('strips Redis username from a Heroku url to work with our upstream redis library', function () {
125+
126+
var plugin = subject.createDeployPlugin({
127+
name: 'redis'
128+
});
129+
130+
var redisLib = new FakeRedis();
131+
132+
var context = {
133+
ui: mockUi,
134+
project: stubProject,
135+
config: {
136+
redis: {
137+
url: 'redis://username:password@host.amazonaws.com:6379/4'
138+
}
139+
},
140+
_redisLib: redisLib
141+
};
142+
plugin.beforeHook(context);
143+
plugin.configure(context);
144+
plugin.readConfig('redisDeployClient');
145+
146+
assert.equal(redisLib.createdClient.options, 'redis://:password@host.amazonaws.com:6379/4');
147+
});
148+
});
149+
98150
describe('resolving port from the pipeline', function() {
99151
it('uses the config data if it already exists', function() {
100152
var plugin = subject.createDeployPlugin({

0 commit comments

Comments
 (0)