Skip to content

Commit 92744e8

Browse files
committedDec 27, 2015
Make sure SSL options are passed through
1 parent d78ed09 commit 92744e8

File tree

4 files changed

+22
-33
lines changed

4 files changed

+22
-33
lines changed
 

‎package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
"coffee-script": "^1.9.1",
4141
"mocha": "^2.1.0",
4242
"nock": "^2.17.0",
43-
"should": "^5.0.1"
43+
"should": "^5.0.1",
44+
"simple-mock": "^0.5.0"
4445
},
4546
"keywords": [
4647
"etcd",

‎src/client.coffee

+5-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class Client
9393
headers: headers
9494
callback = syncRespHandler if options.synchronous is true
9595

96-
req = request options, reqRespHandler
96+
req = @_doRequest options, reqRespHandler
9797
token.setRequest req
9898

9999
if options.synchronous is true and options.syncdone is undefined
@@ -105,6 +105,10 @@ class Client
105105
return req
106106

107107

108+
_doRequest: (options, reqRespHandler) ->
109+
request options, reqRespHandler
110+
111+
108112
_retry: (token, options, callback) =>
109113
doRetry = () =>
110114
@_multiserverHelper token.servers, options, token, callback

‎src/index.coffee

+1-14
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,7 @@ class Etcd
99

1010
# Constructor, set etcd host and port.
1111
# For https: provide {ca, crt, key} as sslopts.
12-
# constructor: (host = '127.0.0.1', port = null, sslopts = null, client = null) ->
13-
14-
# if _.isArray(host)
15-
# @hosts = host
16-
# @sslopts = port
17-
# @client = sslopts
18-
# else
19-
# port ?= 4001
20-
# @hosts = ["#{host}:#{port}"]
21-
# @sslopts = sslopts
22-
# @client = client
23-
24-
# @client ?= new Client(@hosts, @sslopts)
25-
12+
# constructor: (hosts = ["http://127.0.0.1:4001"], options = {}) ->
2613
constructor: (hosts = "127.0.0.1:4001", options = {}) ->
2714
@hosts = @_cleanHostList hosts
2815
@client = new Client(@hosts, options, null)

‎test/index.coffee

+14-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
should = require 'should'
22
nock = require 'nock'
3+
simple = require 'simple-mock'
34
Etcd = require '../src/index.coffee'
45

6+
7+
58
# Set env var to skip timeouts
69
process.env.RUNNING_UNIT_TESTS = true
710

@@ -330,25 +333,19 @@ describe 'Basic functions', ->
330333

331334
describe 'SSL support', ->
332335

333-
it 'should use https url if sslopts is given', ->
334-
etcdssl = new Etcd 'localhost', '4001', {}
335-
opt = etcdssl._prepareOpts 'path'
336-
opt.serverprotocol.should.equal "https"
337-
338-
it 'should set ca if ca is given', ->
339-
etcdsslca = new Etcd 'localhost', '4001', {ca: ['ca']}
340-
opt = etcdsslca._prepareOpts 'path'
341-
should.exist opt.agentOptions
342-
should.exist opt.agentOptions.ca
343-
opt.agentOptions.ca.should.eql ['ca']
336+
beforeEach () ->
337+
nock.cleanAll()
344338

345-
it 'should connect to https if sslopts is given', (done) ->
346-
getNock('https://localhost:4001')
347-
.get('/v2/keys/key')
348-
.reply(200, '{"action":"GET","key":"/key","value":"value","index":1}')
339+
it 'passes ssl options to request lib', (done) ->
340+
etcdssl = new Etcd 'https://localhost:4009', {ca: 'myca', cert: 'mycert', key: 'mykey'}
341+
simple.mock(etcdssl.client, "_doRequest").callFn (options) ->
342+
options.should.containEql
343+
ca: 'myca'
344+
cert: 'mycert'
345+
key: 'mykey'
346+
done()
349347

350-
etcdssl = new Etcd ['localhost:4001'], {ca: ['ca']}
351-
etcdssl.get 'key', done
348+
etcdssl.get 'key'
352349

353350

354351
describe 'Cancellation Token', ->

0 commit comments

Comments
 (0)
Please sign in to comment.