Merge pull request #7 from zeit/reject-authorized

Add rejectUnauthorized option
This commit is contained in:
Naoyuki Kanezawa 2019-10-08 21:32:14 +09:00 committed by GitHub
commit 58365cc98c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -94,6 +94,7 @@ type SyslogOptions = {
leef?: LEEF | LEEFOptions;
port?: number;
protocol?: string;
rejectUnauthorized?: boolean;
rfc3164?: RFC3164 | RFC3164Options;
rfc5424?: RFC5424 | RFC5424Options;
target?: string;
@ -120,6 +121,7 @@ export class Syslog {
leef: any;
port: number;
protocol: string;
rejectUnauthorized: boolean;
rfc3164: any;
rfc5424: any;
target: string;
@ -155,6 +157,8 @@ export class Syslog {
* @param {string} [options.tlsClientKey] - Client TLS key file
* location that this client should use, this option if set will take
* presidents over any certificates set in a formatting object
* @param {string} [options.rejectUnauthorized] - If not false, the server
* certificate is verified against the list of supplied CAs.
* >>>Syslog Format Settings
* @param {string} [options.format='none'] - Valid syslog format options for
* this module are 'none', 'rfc3164', 'rfc5424', 'leef', 'cef'
@ -197,6 +201,7 @@ export class Syslog {
/** @type {string} */
this.tlsClientKey = options.tlsClientKey;
}
this.rejectUnauthorized = options.rejectUnauthorized !== false;
// Syslog Format
if (typeof options.format === 'string') {
/** @type {string} */
@ -385,8 +390,8 @@ export class Syslog {
tlsOptionsCerts.push(cert);
}
tlsOptions.ca = tlsOptionsCerts;
tlsOptions.rejectUnauthorized = true;
}
tlsOptions.rejectUnauthorized = this.rejectUnauthorized;
const client = tls.connect(tlsOptions, () => {
// Turn msg in to a UTF8 buffer
let msgBuffer = Buffer.from(msg, 'utf8');

View File

@ -852,6 +852,15 @@ describe('Base Syslog Class tests', () => {
const result = await syslog.send('test');
expect(result).toBe('test');
});
test('Syslog Send TLS without rejectUnauthorized', async () => {
let syslog = new SyslogPro.Syslog({
protocol: 'tls',
port: global.tlsBasicServerPort,
rejectUnauthorized: false
});
const result = await syslog.send('test');
expect(result).toBe('test');
});
test('Syslog Send TCP with DNS Error', async () => {
let syslog = new SyslogPro.Syslog({
target: 'noteareal.dns',