-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix bug: opts.rejectUnauthorized for SSL option (#171)
* fix bug: opts.rejectUnauthorized for SSL option * fix bug: opts.rejectUnauthorized for SSL option * add initial test for cli * refactored for unit testing
- Loading branch information
1 parent
8d4b0d9
commit 93bb4c2
Showing
3 changed files
with
174 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
'use strict' | ||
const test = require('tap').test | ||
const proxyquire = require('proxyquire') | ||
|
||
test('CLI: arg node should passed to client constructor', async (t) => { | ||
const cli = proxyquire('../cli.js', { | ||
pump: () => { }, | ||
'./lib.js': (opts) => { | ||
t.same(opts, { node: 'https://custom-node-url:9999' }) | ||
return { | ||
on: () => { } | ||
} | ||
} | ||
}) | ||
|
||
cli({ node: 'https://custom-node-url:9999' }) | ||
}) | ||
|
||
test('CLI: arg rejectUnauthorized, if set to \'true\', should passed as true (bool) to client constructor', async (t) => { | ||
const cli = proxyquire('../cli.js', { | ||
pump: () => { }, | ||
'./lib.js': (opts) => { | ||
t.same(opts, { | ||
node: 'https://custom-node-url:9999', | ||
rejectUnauthorized: true | ||
}) | ||
return { | ||
on: () => { } | ||
} | ||
} | ||
}) | ||
|
||
cli({ | ||
node: 'https://custom-node-url:9999', | ||
rejectUnauthorized: 'true' | ||
}) | ||
}) | ||
|
||
test('CLI: arg rejectUnauthorized, if set to \'false\', should passed as false (bool) to client constructor', async (t) => { | ||
const cli = proxyquire('../cli.js', { | ||
pump: () => { }, | ||
'./lib.js': (opts) => { | ||
t.same(opts, { | ||
node: 'https://custom-node-url:9999', | ||
rejectUnauthorized: false | ||
}) | ||
return { | ||
on: () => { } | ||
} | ||
} | ||
}) | ||
|
||
cli({ | ||
node: 'https://custom-node-url:9999', | ||
rejectUnauthorized: 'false' | ||
}) | ||
}) | ||
|
||
test('CLI: arg rejectUnauthorized, if set to anything instead of true or false, should passed as true (bool) to client constructor', async (t) => { | ||
const cli = proxyquire('../cli.js', { | ||
pump: () => { }, | ||
'./lib.js': (opts) => { | ||
t.same(opts, { | ||
node: 'https://custom-node-url:9999', | ||
rejectUnauthorized: true | ||
}) | ||
return { | ||
on: () => { } | ||
} | ||
} | ||
}) | ||
|
||
cli({ | ||
node: 'https://custom-node-url:9999', | ||
rejectUnauthorized: 'anything' | ||
}) | ||
}) | ||
|
||
test('CLI: if arg.read-config is set, should read the config file and passed the value (only allowed values)', async (t) => { | ||
const cli = proxyquire('../cli.js', { | ||
pump: () => { }, | ||
'./lib.js': (opts) => { | ||
t.same(opts, { | ||
index: 'custom-index', | ||
node: 'https://localhost:9200', | ||
rejectUnauthorized: false, | ||
auth: { | ||
username: 'elastic', | ||
password: 'pass' | ||
}, | ||
// some keys are redundant, it is intended as it is. | ||
// (see function start() in cli.js) | ||
'read-config': 'test/exampleConfig.js', | ||
username: 'elastic', | ||
password: 'pass' | ||
}) | ||
return { | ||
on: () => { } | ||
} | ||
} | ||
}) | ||
|
||
cli({ | ||
node: 'https://custom-node-url:9999', | ||
'read-config': 'test/exampleConfig.js' | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
index: 'custom-index', | ||
node: 'https://localhost:9200', | ||
rejectUnauthorized: false, | ||
username: 'elastic', | ||
password: 'pass' | ||
} |