From 4d4dd7952c72aa926d4b23d25e6c1e102e34ef86 Mon Sep 17 00:00:00 2001 From: Vadim Dalecky Date: Tue, 15 Sep 2020 10:49:20 +0200 Subject: [PATCH] Neutral-naming in reporting plugin (#77371) (#77406) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: 💡 remove "blacklist" reference in reporting plugin * refactor: 💡 remove "whitelist" in reporting plugin * fix: 🐛 correctly import function after refactor * refactor: 💡 use "blocked" instead of "denied" terminology --- x-pack/plugins/reporting/common/constants.ts | 6 +++--- .../server/browsers/network_policy.test.ts | 20 +++++++++---------- .../server/export_types/common/index.ts | 2 +- ...s.test.ts => omit_blocked_headers.test.ts} | 10 +++++----- ...ted_headers.ts => omit_blocked_headers.ts} | 10 +++++----- .../export_types/png/execute_job/index.ts | 4 ++-- .../printable_pdf/execute_job/index.ts | 4 ++-- .../server/routes/diagnostic/screenshot.ts | 4 ++-- .../server/routes/lib/job_response_handler.ts | 4 ++-- 9 files changed, 32 insertions(+), 32 deletions(-) rename x-pack/plugins/reporting/server/export_types/common/{omit_blacklisted_headers.test.ts => omit_blocked_headers.test.ts} (80%) rename x-pack/plugins/reporting/server/export_types/common/{omit_blacklisted_headers.ts => omit_blocked_headers.ts} (69%) diff --git a/x-pack/plugins/reporting/common/constants.ts b/x-pack/plugins/reporting/common/constants.ts index e5bca43cef562..79449e5d229b8 100644 --- a/x-pack/plugins/reporting/common/constants.ts +++ b/x-pack/plugins/reporting/common/constants.ts @@ -23,7 +23,7 @@ export const CSV_REPORTING_ACTION = 'downloadCsvReport'; export const CSV_BOM_CHARS = '\ufeff'; export const CSV_FORMULA_CHARS = ['=', '+', '-', '@']; -export const WHITELISTED_JOB_CONTENT_TYPES = [ +export const ALLOWED_JOB_CONTENT_TYPES = [ 'application/json', 'application/pdf', CONTENT_TYPE_CSV, @@ -34,7 +34,7 @@ export const WHITELISTED_JOB_CONTENT_TYPES = [ // See: // https://github.com/chromium/chromium/blob/3611052c055897e5ebbc5b73ea295092e0c20141/services/network/public/cpp/header_util_unittest.cc#L50 // For a list of headers that chromium doesn't like -export const KBN_SCREENSHOT_HEADER_BLACKLIST = [ +export const KBN_SCREENSHOT_HEADER_BLOCK_LIST = [ 'accept-encoding', 'connection', 'content-length', @@ -51,7 +51,7 @@ export const KBN_SCREENSHOT_HEADER_BLACKLIST = [ 'keep-alive', ]; -export const KBN_SCREENSHOT_HEADER_BLACKLIST_STARTS_WITH_PATTERN = ['proxy-']; +export const KBN_SCREENSHOT_HEADER_BLOCK_LIST_STARTS_WITH_PATTERN = ['proxy-']; export const UI_SETTINGS_CUSTOM_PDF_LOGO = 'xpackReporting:customPdfLogo'; diff --git a/x-pack/plugins/reporting/server/browsers/network_policy.test.ts b/x-pack/plugins/reporting/server/browsers/network_policy.test.ts index 5c7c74807162c..b2fb6af41b01c 100644 --- a/x-pack/plugins/reporting/server/browsers/network_policy.test.ts +++ b/x-pack/plugins/reporting/server/browsers/network_policy.test.ts @@ -109,28 +109,28 @@ describe('Network Policy', () => { expect(allowRequest(url, rules)).toEqual(false); }); - it('allows requests when hosts are whitelisted IP addresses', () => { + it('allows requests when hosts are allowed IP addresses', () => { const url = 'http://192.168.1.1/cool/route/bro'; const rules = [{ allow: true, host: '192.168.1.1' }, { allow: false }]; expect(allowRequest(url, rules)).toEqual(true); }); - it('denies requests when hosts are blacklisted IP addresses', () => { + it('denies requests when hosts are from blocked IP addresses', () => { const url = 'http://192.168.1.1/cool/route/bro'; const rules = [{ allow: false, host: '192.168.1.1' }, { allow: true }]; expect(allowRequest(url, rules)).toEqual(false); }); - it('allows requests when hosts are IP addresses not blacklisted', () => { + it('allows requests when hosts are IP addresses that are not blocked', () => { const url = 'http://192.168.2.1/cool/route/bro'; const rules = [{ allow: false, host: '192.168.1.1' }, { allow: true }]; expect(allowRequest(url, rules)).toEqual(true); }); - it('denies requests when hosts are IP addresses not whitelisted', () => { + it('denies requests when hosts are IP addresses not explicitly allowed', () => { const url = 'http://192.168.2.1/cool/route/bro'; const rules = [{ allow: true, host: '192.168.1.1' }, { allow: false }]; @@ -138,7 +138,7 @@ describe('Network Policy', () => { }); describe('Common cases', () => { - it('allows whitelisting of certain routes based upon protocol', () => { + it('allows certain routes based upon protocol', () => { const rules = [ { allow: true, host: 'kibana.com', protocol: 'http:' }, { allow: true, protocol: 'https:' }, @@ -150,7 +150,7 @@ describe('Network Policy', () => { expect(allowRequest('http://bad.com/some/route', rules)).toEqual(false); }); - it('allows blacklisting of certain IPs', () => { + it('allows blocking of certain IPs', () => { const rules = [{ allow: false, host: '169.254.0.0' }, { allow: true }]; expect(allowRequest('http://kibana.com/some/route', rules)).toEqual(true); @@ -158,7 +158,7 @@ describe('Network Policy', () => { expect(allowRequest('https://169.254.0.0/some/route', rules)).toEqual(false); }); - it('allows whitelisting a single host on https', () => { + it('allows single host on https', () => { const rules = [{ allow: true, host: 'kibana.com', protocol: 'https:' }, { allow: false }]; expect(allowRequest('http://kibana.com/some/route', rules)).toEqual(false); @@ -166,7 +166,7 @@ describe('Network Policy', () => { expect(allowRequest('https://kibana.com/some/route', rules)).toEqual(true); }); - it('allows whitelisting a single protocol to http', () => { + it('allows single protocol to http', () => { const rules = [{ allow: true, protocol: 'https:' }, { allow: false }]; expect(allowRequest('http://kibana.com/some/route', rules)).toEqual(false); @@ -174,7 +174,7 @@ describe('Network Policy', () => { expect(allowRequest('https://good.com/some/route', rules)).toEqual(true); }); - it('allows whitelisting a single domain', () => { + it('allows single domain', () => { const rules = [{ allow: true, host: 'kibana.com' }, { allow: false }]; expect(allowRequest('http://kibana.com/some/route', rules)).toEqual(true); @@ -182,7 +182,7 @@ describe('Network Policy', () => { expect(allowRequest('https://www-kibana.com/some/route', rules)).toEqual(false); }); - it('can blacklist bad protocols', () => { + it('can ban bad protocols', () => { const rules = [ { allow: true, protocol: 'http:' }, { allow: true, protocol: 'https:' }, diff --git a/x-pack/plugins/reporting/server/export_types/common/index.ts b/x-pack/plugins/reporting/server/export_types/common/index.ts index a4e114d6b2f2e..e0d03eb4864ca 100644 --- a/x-pack/plugins/reporting/server/export_types/common/index.ts +++ b/x-pack/plugins/reporting/server/export_types/common/index.ts @@ -8,5 +8,5 @@ export { decryptJobHeaders } from './decrypt_job_headers'; export { getConditionalHeaders } from './get_conditional_headers'; export { getCustomLogo } from './get_custom_logo'; export { getFullUrls } from './get_full_urls'; -export { omitBlacklistedHeaders } from './omit_blacklisted_headers'; +export { omitBlockedHeaders } from './omit_blocked_headers'; export { validateUrls } from './validate_urls'; diff --git a/x-pack/plugins/reporting/server/export_types/common/omit_blacklisted_headers.test.ts b/x-pack/plugins/reporting/server/export_types/common/omit_blocked_headers.test.ts similarity index 80% rename from x-pack/plugins/reporting/server/export_types/common/omit_blacklisted_headers.test.ts rename to x-pack/plugins/reporting/server/export_types/common/omit_blocked_headers.test.ts index abf5784dacff9..f40651603db8f 100644 --- a/x-pack/plugins/reporting/server/export_types/common/omit_blacklisted_headers.test.ts +++ b/x-pack/plugins/reporting/server/export_types/common/omit_blocked_headers.test.ts @@ -4,15 +4,15 @@ * you may not use this file except in compliance with the Elastic License. */ -import { omitBlacklistedHeaders } from './index'; +import { omitBlockedHeaders } from './index'; -test(`omits blacklisted headers`, async () => { +test(`omits blocked headers`, async () => { const permittedHeaders = { foo: 'bar', baz: 'quix', }; - const blacklistedHeaders = { + const blockedHeaders = { 'accept-encoding': '', connection: 'upgrade', 'content-length': '', @@ -24,7 +24,7 @@ test(`omits blacklisted headers`, async () => { trailer: 's are for trucks', }; - const filteredHeaders = await omitBlacklistedHeaders({ + const filteredHeaders = await omitBlockedHeaders({ job: { title: 'cool-job-bro', type: 'csv', @@ -36,7 +36,7 @@ test(`omits blacklisted headers`, async () => { }, decryptedHeaders: { ...permittedHeaders, - ...blacklistedHeaders, + ...blockedHeaders, }, }); diff --git a/x-pack/plugins/reporting/server/export_types/common/omit_blacklisted_headers.ts b/x-pack/plugins/reporting/server/export_types/common/omit_blocked_headers.ts similarity index 69% rename from x-pack/plugins/reporting/server/export_types/common/omit_blacklisted_headers.ts rename to x-pack/plugins/reporting/server/export_types/common/omit_blocked_headers.ts index b2e0ce23aa3a5..946f033b4b481 100644 --- a/x-pack/plugins/reporting/server/export_types/common/omit_blacklisted_headers.ts +++ b/x-pack/plugins/reporting/server/export_types/common/omit_blocked_headers.ts @@ -5,11 +5,11 @@ */ import { omitBy } from 'lodash'; import { - KBN_SCREENSHOT_HEADER_BLACKLIST, - KBN_SCREENSHOT_HEADER_BLACKLIST_STARTS_WITH_PATTERN, + KBN_SCREENSHOT_HEADER_BLOCK_LIST, + KBN_SCREENSHOT_HEADER_BLOCK_LIST_STARTS_WITH_PATTERN, } from '../../../common/constants'; -export const omitBlacklistedHeaders = ({ +export const omitBlockedHeaders = ({ job, decryptedHeaders, }: { @@ -20,8 +20,8 @@ export const omitBlacklistedHeaders = ({ decryptedHeaders, (_value, header: string) => header && - (KBN_SCREENSHOT_HEADER_BLACKLIST.includes(header) || - KBN_SCREENSHOT_HEADER_BLACKLIST_STARTS_WITH_PATTERN.some((pattern) => + (KBN_SCREENSHOT_HEADER_BLOCK_LIST.includes(header) || + KBN_SCREENSHOT_HEADER_BLOCK_LIST_STARTS_WITH_PATTERN.some((pattern) => header?.startsWith(pattern) )) ); diff --git a/x-pack/plugins/reporting/server/export_types/png/execute_job/index.ts b/x-pack/plugins/reporting/server/export_types/png/execute_job/index.ts index 96b896b938962..67fc51bbfc352 100644 --- a/x-pack/plugins/reporting/server/export_types/png/execute_job/index.ts +++ b/x-pack/plugins/reporting/server/export_types/png/execute_job/index.ts @@ -13,7 +13,7 @@ import { decryptJobHeaders, getConditionalHeaders, getFullUrls, - omitBlacklistedHeaders, + omitBlockedHeaders, } from '../../common'; import { generatePngObservableFactory } from '../lib/generate_png'; import { TaskPayloadPNG } from '../types'; @@ -37,7 +37,7 @@ export const runTaskFnFactory: QueuedPngExecutorFactory = function executeJobFac const jobLogger = logger.clone([jobId]); const process$: Rx.Observable = Rx.of(1).pipe( mergeMap(() => decryptJobHeaders({ encryptionKey, job, logger })), - map((decryptedHeaders) => omitBlacklistedHeaders({ job, decryptedHeaders })), + map((decryptedHeaders) => omitBlockedHeaders({ job, decryptedHeaders })), map((filteredHeaders) => getConditionalHeaders({ config, job, filteredHeaders })), mergeMap((conditionalHeaders) => { const urls = getFullUrls({ config, job }); diff --git a/x-pack/plugins/reporting/server/export_types/printable_pdf/execute_job/index.ts b/x-pack/plugins/reporting/server/export_types/printable_pdf/execute_job/index.ts index 78808400c9c9a..7d1bb109f508b 100644 --- a/x-pack/plugins/reporting/server/export_types/printable_pdf/execute_job/index.ts +++ b/x-pack/plugins/reporting/server/export_types/printable_pdf/execute_job/index.ts @@ -14,7 +14,7 @@ import { getConditionalHeaders, getCustomLogo, getFullUrls, - omitBlacklistedHeaders, + omitBlockedHeaders, } from '../../common'; import { generatePdfObservableFactory } from '../lib/generate_pdf'; import { TaskPayloadPDF } from '../types'; @@ -40,7 +40,7 @@ export const runTaskFnFactory: QueuedPdfExecutorFactory = function executeJobFac const jobLogger = logger.clone([jobId]); const process$: Rx.Observable = Rx.of(1).pipe( mergeMap(() => decryptJobHeaders({ encryptionKey, job, logger })), - map((decryptedHeaders) => omitBlacklistedHeaders({ job, decryptedHeaders })), + map((decryptedHeaders) => omitBlockedHeaders({ job, decryptedHeaders })), map((filteredHeaders) => getConditionalHeaders({ config, job, filteredHeaders })), mergeMap((conditionalHeaders) => getCustomLogo({ reporting, config, job, conditionalHeaders }) diff --git a/x-pack/plugins/reporting/server/routes/diagnostic/screenshot.ts b/x-pack/plugins/reporting/server/routes/diagnostic/screenshot.ts index 7e07779b5fd37..979283f9f037c 100644 --- a/x-pack/plugins/reporting/server/routes/diagnostic/screenshot.ts +++ b/x-pack/plugins/reporting/server/routes/diagnostic/screenshot.ts @@ -7,7 +7,7 @@ import { i18n } from '@kbn/i18n'; import { ReportingCore } from '../..'; import { API_DIAGNOSE_URL } from '../../../common/constants'; -import { omitBlacklistedHeaders } from '../../export_types/common'; +import { omitBlockedHeaders } from '../../export_types/common'; import { getAbsoluteUrlFactory } from '../../export_types/common/get_absolute_url'; import { generatePngObservableFactory } from '../../export_types/png/lib/generate_png'; import { LevelLogger as Logger } from '../../lib'; @@ -65,7 +65,7 @@ export const registerDiagnoseScreenshot = (reporting: ReportingCore, logger: Log }; const headers = { - headers: omitBlacklistedHeaders({ + headers: omitBlockedHeaders({ job: null, decryptedHeaders, }), diff --git a/x-pack/plugins/reporting/server/routes/lib/job_response_handler.ts b/x-pack/plugins/reporting/server/routes/lib/job_response_handler.ts index aec1eee0eee14..6905146a6d3c1 100644 --- a/x-pack/plugins/reporting/server/routes/lib/job_response_handler.ts +++ b/x-pack/plugins/reporting/server/routes/lib/job_response_handler.ts @@ -6,7 +6,7 @@ import { kibanaResponseFactory } from 'kibana/server'; import { ReportingCore } from '../../'; -import { WHITELISTED_JOB_CONTENT_TYPES } from '../../../common/constants'; +import { ALLOWED_JOB_CONTENT_TYPES } from '../../../common/constants'; import { ReportingUser } from '../../types'; import { getDocumentPayloadFactory } from './get_document_payload'; import { jobsQueryFactory } from './jobs_query'; @@ -48,7 +48,7 @@ export function downloadJobResponseHandlerFactory(reporting: ReportingCore) { const payload = getDocumentPayload(doc); - if (!payload.contentType || !WHITELISTED_JOB_CONTENT_TYPES.includes(payload.contentType)) { + if (!payload.contentType || !ALLOWED_JOB_CONTENT_TYPES.includes(payload.contentType)) { return res.badRequest({ body: `Unsupported content-type of ${payload.contentType} specified by job output`, });