[SIEM] Change deprecated Buffer method for non-deprecated Buffer method (#38634)

## Summary
  * Added linter rule to prevent us from accidentally adding deprecated node methods
  * Added the new package linter plugin for NodeJS
  * Added unit test for the base 64 encoding for sanity check

Note:
Only the one line of code will be back-ported for the NodeJS fix for 7.2.0. The linter rule will not be back-ported. 

### Checklist

Use ~~strikethroughs~~ to remove checklist items you don't feel are applicable to this PR.

~~- [ ] This was checked for cross-browser compatibility, [including a check against IE11](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility)~~
~~- [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/master/packages/kbn-i18n/README.md)~~
~~- [ ] [Documentation](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#writing-documentation) was added for features that require explanation or tutorials~~

- [x] [Unit or functional tests](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility) were updated or added to match the most common scenarios

~~- [ ] This was checked for [keyboard-only and screenreader accessibility](https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/Accessibility#Accessibility_testing_checklist)~~

### For maintainers

~~- [ ] This was checked for breaking API changes and was [labeled appropriately](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#release-notes-process)~~
~~- [ ] This includes a feature addition or change that requires a release note and was [labeled appropriately](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#release-notes-process)~~
This commit is contained in:
Frank Hassanabad 2019-06-10 22:15:11 -06:00 committed by GitHub
parent faf0f2d770
commit 131e3bf1a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 3 deletions

View file

@ -456,7 +456,7 @@ module.exports = {
{
// typescript and javascript for front and back end
files: ['x-pack/plugins/siem/**/*.{js,ts,tsx}'],
plugins: ['react'],
plugins: ['eslint-plugin-node', 'react'],
rules: {
'accessor-pairs': 'error',
'array-callback-return': 'error',
@ -479,6 +479,7 @@ module.exports = {
},
],
*/
'node/no-deprecated-api': 'error',
'no-bitwise': 'error',
'no-continue': 'error',
'no-dupe-keys': 'error',

View file

@ -365,6 +365,7 @@
"eslint-plugin-jest": "22.6.4",
"eslint-plugin-jsx-a11y": "6.2.1",
"eslint-plugin-mocha": "5.3.0",
"eslint-plugin-node": "9.1.0",
"eslint-plugin-no-unsanitized": "3.0.2",
"eslint-plugin-prefer-object-spread": "1.2.1",
"eslint-plugin-prettier": "3.1.0",

View file

@ -0,0 +1,25 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { convertStringToBase64 } from './saved_object';
describe('saved_object', () => {
describe('convertStringToBase64', () => {
test('it should base 64 encode a string such as the word "Frank"', () => {
expect(convertStringToBase64('Frank')).toBe('RnJhbms=');
});
test('it should base 64 encode a large string such as the "Some very long string for you"', () => {
expect(convertStringToBase64('Some very long string for you')).toBe(
'U29tZSB2ZXJ5IGxvbmcgc3RyaW5nIGZvciB5b3U='
);
});
test('it should base 64 encode a empty string as an empty string', () => {
expect(convertStringToBase64('')).toBe('');
});
});
});

View file

@ -266,7 +266,7 @@ export class Timeline {
}
}
const convertStringToBase64 = (text: string): string => new Buffer(text).toString('base64');
export const convertStringToBase64 = (text: string): string => Buffer.from(text).toString('base64');
// we have to use any here because the SavedObjectAttributes interface is like below
// export interface SavedObjectAttributes {

View file

@ -11146,6 +11146,14 @@ eslint-plugin-ban@1.2.0:
dependencies:
requireindex "~1.2.0"
eslint-plugin-es@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-es/-/eslint-plugin-es-1.4.0.tgz#475f65bb20c993fc10e8c8fe77d1d60068072da6"
integrity sha512-XfFmgFdIUDgvaRAlaXUkxrRg5JSADoRC8IkKLc/cISeR3yHVMefFHQZpcyXXEUUPHfy5DwviBcrfqlyqEwlQVw==
dependencies:
eslint-utils "^1.3.0"
regexpp "^2.0.1"
eslint-plugin-import@2.17.3:
version "2.17.3"
resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.17.3.tgz#00548b4434c18faebaba04b24ae6198f280de189"
@ -11194,6 +11202,18 @@ eslint-plugin-no-unsanitized@3.0.2:
resolved "https://registry.yarnpkg.com/eslint-plugin-no-unsanitized/-/eslint-plugin-no-unsanitized-3.0.2.tgz#83c6fcf8e34715112757e03dd4ee436dce29ed45"
integrity sha512-JnwpoH8Sv4QOjrTDutENBHzSnyYtspdjtglYtqUtAHe6f6LLKqykJle+UwFPg23GGwt5hI3amS9CRDezW8GAww==
eslint-plugin-node@9.1.0:
version "9.1.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-node/-/eslint-plugin-node-9.1.0.tgz#f2fd88509a31ec69db6e9606d76dabc5adc1b91a"
integrity sha512-ZwQYGm6EoV2cfLpE1wxJWsfnKUIXfM/KM09/TlorkukgCAwmkgajEJnPCmyzoFPQQkmvo5DrW/nyKutNIw36Mw==
dependencies:
eslint-plugin-es "^1.4.0"
eslint-utils "^1.3.1"
ignore "^5.1.1"
minimatch "^3.0.4"
resolve "^1.10.1"
semver "^6.1.0"
eslint-plugin-prefer-object-spread@1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-prefer-object-spread/-/eslint-plugin-prefer-object-spread-1.2.1.tgz#27fb91853690cceb3ae6101d9c8aecc6a67a402c"
@ -11253,7 +11273,7 @@ eslint-scope@^4.0.3:
esrecurse "^4.1.0"
estraverse "^4.1.1"
eslint-utils@^1.3.1:
eslint-utils@^1.3.0, eslint-utils@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-1.3.1.tgz#9a851ba89ee7c460346f97cf8939c7298827e512"
integrity sha512-Z7YjnIldX+2XMcjr7ZkgEsOj/bREONV60qYeB/bjMAqqqZ4zxKyWX+BOUkdmRmA9riiIPVvo5x86m5elviOk0Q==
@ -14702,6 +14722,11 @@ ignore@^4.0.6:
resolved "https://registry.yarnpkg.com/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc"
integrity sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==
ignore@^5.1.1:
version "5.1.2"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.1.2.tgz#e28e584d43ad7e92f96995019cc43b9e1ac49558"
integrity sha512-vdqWBp7MyzdmHkkRWV5nY+PfGRbYbahfuvsBCh277tq+w9zyNi7h5CYJCK0kmzti9kU+O/cB7sE8HvKv6aXAKQ==
image-diff@1.6.3:
version "1.6.3"
resolved "https://registry.yarnpkg.com/image-diff/-/image-diff-1.6.3.tgz#818a0e656ae89480e802e7ef14db460826f730fc"