Skip to content

Commit

Permalink
refactor: 💡 use "blocked" instead of "denied" terminology
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Sep 14, 2020
1 parent 7c4fdcf commit 752910b
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions x-pack/plugins/reporting/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const ALLOWED_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_DENY_LIST = [
export const KBN_SCREENSHOT_HEADER_BLOCK_LIST = [
'accept-encoding',
'connection',
'content-length',
Expand All @@ -51,7 +51,7 @@ export const KBN_SCREENSHOT_HEADER_DENY_LIST = [
'keep-alive',
];

export const KBN_SCREENSHOT_HEADER_DENY_LIST_STARTS_WITH_PATTERN = ['proxy-'];
export const KBN_SCREENSHOT_HEADER_BLOCK_LIST_STARTS_WITH_PATTERN = ['proxy-'];

export const UI_SETTINGS_CUSTOM_PDF_LOGO = 'xpackReporting:customPdfLogo';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ describe('Network Policy', () => {
expect(allowRequest(url, rules)).toEqual(true);
});

it('denies requests when hosts are from banned 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 banned', () => {
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 }];

Expand All @@ -150,7 +150,7 @@ describe('Network Policy', () => {
expect(allowRequest('http://bad.com/some/route', rules)).toEqual(false);
});

it('allows banning 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 { omitBannedHeaders } from './omit_banned_headers';
export { omitBlockedHeaders } from './omit_blocked_headers';
export { validateUrls } from './validate_urls';
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { omitBannedHeaders } from './index';
import { omitBlockedHeaders } from './index';

test(`omits banned headers`, async () => {
test(`omits blocked headers`, async () => {
const permittedHeaders = {
foo: 'bar',
baz: 'quix',
};

const bannedHeaders = {
const blockedHeaders = {
'accept-encoding': '',
connection: 'upgrade',
'content-length': '',
Expand All @@ -24,7 +24,7 @@ test(`omits banned headers`, async () => {
trailer: 's are for trucks',
};

const filteredHeaders = await omitBannedHeaders({
const filteredHeaders = await omitBlockedHeaders({
job: {
title: 'cool-job-bro',
type: 'csv',
Expand All @@ -36,7 +36,7 @@ test(`omits banned headers`, async () => {
},
decryptedHeaders: {
...permittedHeaders,
...bannedHeaders,
...blockedHeaders,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
*/
import { omitBy } from 'lodash';
import {
KBN_SCREENSHOT_HEADER_DENY_LIST,
KBN_SCREENSHOT_HEADER_DENY_LIST_STARTS_WITH_PATTERN,
KBN_SCREENSHOT_HEADER_BLOCK_LIST,
KBN_SCREENSHOT_HEADER_BLOCK_LIST_STARTS_WITH_PATTERN,
} from '../../../common/constants';

export const omitBannedHeaders = <TaskPayloadType>({
export const omitBlockedHeaders = <TaskPayloadType>({
job,
decryptedHeaders,
}: {
Expand All @@ -20,8 +20,8 @@ export const omitBannedHeaders = <TaskPayloadType>({
decryptedHeaders,
(_value, header: string) =>
header &&
(KBN_SCREENSHOT_HEADER_DENY_LIST.includes(header) ||
KBN_SCREENSHOT_HEADER_DENY_LIST_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)
))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
decryptJobHeaders,
getConditionalHeaders,
getFullUrls,
omitBannedHeaders,
omitBlockedHeaders,
} from '../../common';
import { generatePngObservableFactory } from '../lib/generate_png';
import { TaskPayloadPNG } from '../types';
Expand All @@ -37,7 +37,7 @@ export const runTaskFnFactory: QueuedPngExecutorFactory = function executeJobFac
const jobLogger = logger.clone([jobId]);
const process$: Rx.Observable<TaskRunResult> = Rx.of(1).pipe(
mergeMap(() => decryptJobHeaders({ encryptionKey, job, logger })),
map((decryptedHeaders) => omitBannedHeaders({ job, decryptedHeaders })),
map((decryptedHeaders) => omitBlockedHeaders({ job, decryptedHeaders })),
map((filteredHeaders) => getConditionalHeaders({ config, job, filteredHeaders })),
mergeMap((conditionalHeaders) => {
const urls = getFullUrls({ config, job });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
getConditionalHeaders,
getCustomLogo,
getFullUrls,
omitBannedHeaders,
omitBlockedHeaders,
} from '../../common';
import { generatePdfObservableFactory } from '../lib/generate_pdf';
import { TaskPayloadPDF } from '../types';
Expand All @@ -40,7 +40,7 @@ export const runTaskFnFactory: QueuedPdfExecutorFactory = function executeJobFac
const jobLogger = logger.clone([jobId]);
const process$: Rx.Observable<TaskRunResult> = Rx.of(1).pipe(
mergeMap(() => decryptJobHeaders({ encryptionKey, job, logger })),
map((decryptedHeaders) => omitBannedHeaders({ job, decryptedHeaders })),
map((decryptedHeaders) => omitBlockedHeaders({ job, decryptedHeaders })),
map((filteredHeaders) => getConditionalHeaders({ config, job, filteredHeaders })),
mergeMap((conditionalHeaders) =>
getCustomLogo({ reporting, config, job, conditionalHeaders })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { i18n } from '@kbn/i18n';
import { ReportingCore } from '../..';
import { API_DIAGNOSE_URL } from '../../../common/constants';
import { omitBannedHeaders } 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';
Expand Down Expand Up @@ -65,7 +65,7 @@ export const registerDiagnoseScreenshot = (reporting: ReportingCore, logger: Log
};

const headers = {
headers: omitBannedHeaders({
headers: omitBlockedHeaders({
job: null,
decryptedHeaders,
}),
Expand Down

0 comments on commit 752910b

Please sign in to comment.