Skip to content

Commit

Permalink
fix: subscriber initialization when using Cluster (#792)
Browse files Browse the repository at this point in the history
Close: #791
  • Loading branch information
r3b-fish authored and luin committed Feb 2, 2019
1 parent f46490d commit 32c48ef
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/cluster/ClusterSubscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ export default class ClusterSubscriber {
password: options.password,
enableReadyCheck: true,
connectionName: SUBSCRIBER_CONNECTION_NAME,
lazyConnect: true
lazyConnect: true,
tls: options.tls
})

// Ignore the errors since they're handled in the connection pool.
Expand Down
50 changes: 50 additions & 0 deletions test/functional/cluster/tls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use strict'

import * as tls from 'tls'
import * as net from 'net'

describe('cluster:tls option', () => {
it('supports tls', (done) => {
var slotTable = [
[0, 5460, ['127.0.0.1', 30001]],
[5461, 10922, ['127.0.0.1', 30002]],
[10923, 16383, ['127.0.0.1', 30003]]
];
var argvHandler = function (argv) {
if (argv[0] === 'cluster' && argv[1] === 'slots') {
return slotTable;
}
};

new MockServer(30001, argvHandler)
new MockServer(30002, argvHandler)
new MockServer(30003, argvHandler)

stub(tls, 'connect', (op) => {
expect(op.ca).to.eql('123')
expect(op.port).to.be.oneOf([30001, 30003, 30003])
const stream = net.createConnection(op)
stream.on('connect', data => {
stream.emit('secureConnect', data)
})
return stream
})

var cluster = new Redis.Cluster([
{ host: '127.0.0.1', port: '30001' },
{ host: '127.0.0.1', port: '30002' },
{ host: '127.0.0.1', port: '30003' }
], {
redisOptions: { tls: { ca: '123' } }
})

cluster.on('ready', () => {
expect(cluster.subscriber.subscriber.options.tls)
.to.deep.equal({ ca: '123' })

cluster.disconnect()
tls.connect.restore()
cluster.on('end', () => done())
})
})
})

0 comments on commit 32c48ef

Please sign in to comment.