Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/url_decode' into url_decode
Browse files Browse the repository at this point in the history
  • Loading branch information
yuliacech committed Oct 27, 2020
2 parents f4fa3f5 + bdec175 commit ec73aec
Show file tree
Hide file tree
Showing 20 changed files with 184 additions and 344 deletions.
13 changes: 3 additions & 10 deletions x-pack/plugins/actions/server/builtin_action_types/webhook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@ describe('config validation', () => {
};

test('config validation passes when only required fields are provided', () => {
const config: Record<string, string | boolean> = {
const config: Record<string, string> = {
url: 'http://mylisteningserver:9200/endpoint',
hasAuth: true,
};
expect(validateConfig(actionType, config)).toEqual({
...defaultValues,
Expand All @@ -102,10 +101,9 @@ describe('config validation', () => {

test('config validation passes when valid methods are provided', () => {
['post', 'put'].forEach((method) => {
const config: Record<string, string | boolean> = {
const config: Record<string, string> = {
url: 'http://mylisteningserver:9200/endpoint',
method,
hasAuth: true,
};
expect(validateConfig(actionType, config)).toEqual({
...defaultValues,
Expand All @@ -129,9 +127,8 @@ describe('config validation', () => {
});

test('config validation passes when a url is specified', () => {
const config: Record<string, string | boolean> = {
const config: Record<string, string> = {
url: 'http://mylisteningserver:9200/endpoint',
hasAuth: true,
};
expect(validateConfig(actionType, config)).toEqual({
...defaultValues,
Expand All @@ -158,7 +155,6 @@ describe('config validation', () => {
headers: {
'Content-Type': 'application/json',
},
hasAuth: true,
};
expect(validateConfig(actionType, config)).toEqual({
...defaultValues,
Expand Down Expand Up @@ -188,7 +184,6 @@ describe('config validation', () => {
headers: {
'Content-Type': 'application/json',
},
hasAuth: true,
};

expect(validateConfig(actionType, config)).toEqual({
Expand Down Expand Up @@ -268,7 +263,6 @@ describe('execute()', () => {
headers: {
aheader: 'a value',
},
hasAuth: true,
};
await actionType.executor({
actionId: 'some-id',
Expand Down Expand Up @@ -326,7 +320,6 @@ describe('execute()', () => {
headers: {
aheader: 'a value',
},
hasAuth: false,
};
const secrets: ActionTypeSecretsType = { user: null, password: null };
await actionType.executor({
Expand Down
5 changes: 2 additions & 3 deletions x-pack/plugins/actions/server/builtin_action_types/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const configSchemaProps = {
defaultValue: WebhookMethods.POST,
}),
headers: nullableType(HeadersSchema),
hasAuth: schema.boolean({ defaultValue: true }),
};
const ConfigSchema = schema.object(configSchemaProps);
export type ActionTypeConfigType = TypeOf<typeof ConfigSchema>;
Expand Down Expand Up @@ -129,12 +128,12 @@ export async function executor(
execOptions: WebhookActionTypeExecutorOptions
): Promise<ActionTypeExecutorResult<unknown>> {
const actionId = execOptions.actionId;
const { method, url, headers = {}, hasAuth } = execOptions.config;
const { method, url, headers = {} } = execOptions.config;
const { body: data } = execOptions.params;

const secrets: ActionTypeSecretsType = execOptions.secrets;
const basicAuth =
hasAuth && isString(secrets.user) && isString(secrets.password)
isString(secrets.user) && isString(secrets.password)
? { auth: { username: secrets.user, password: secrets.password } }
: {};

Expand Down
57 changes: 0 additions & 57 deletions x-pack/plugins/actions/server/saved_objects/migrations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,63 +58,6 @@ describe('7.10.0', () => {
});
});

describe('7.11.0', () => {
beforeEach(() => {
jest.resetAllMocks();
encryptedSavedObjectsSetup.createMigration.mockImplementation(
(shouldMigrateWhenPredicate, migration) => migration
);
});

test('add hasAuth = true for .webhook actions with user and password', () => {
const migration711 = getMigrations(encryptedSavedObjectsSetup)['7.11.0'];
const action = getMockDataForWebhook({}, true);
expect(migration711(action, context)).toMatchObject({
...action,
attributes: {
...action.attributes,
config: {
hasAuth: true,
},
},
});
});

test('add hasAuth = false for .webhook actions without user and password', () => {
const migration711 = getMigrations(encryptedSavedObjectsSetup)['7.11.0'];
const action = getMockDataForWebhook({}, false);
expect(migration711(action, context)).toMatchObject({
...action,
attributes: {
...action.attributes,
config: {
hasAuth: false,
},
},
});
});
});

function getMockDataForWebhook(
overwrites: Record<string, unknown> = {},
hasUserAndPassword: boolean
): SavedObjectUnsanitizedDoc<RawAction> {
const secrets = hasUserAndPassword
? { user: 'test', password: '123' }
: { user: '', password: '' };
return {
attributes: {
name: 'abc',
actionTypeId: '.webhook',
config: {},
secrets,
...overwrites,
},
id: uuid.v4(),
type: 'action',
};
}

function getMockDataForEmail(
overwrites: Record<string, unknown> = {}
): SavedObjectUnsanitizedDoc<RawAction> {
Expand Down
10 changes: 0 additions & 10 deletions x-pack/plugins/actions/server/saved_objects/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,8 @@ export function getMigrations(
pipeMigrations(renameCasesConfigurationObject, addHasAuthConfigurationObject)
);

const migrationWebhookConnectorHasAuth = encryptedSavedObjects.createMigration<
RawAction,
RawAction
>(
(doc): doc is SavedObjectUnsanitizedDoc<RawAction> =>
doc.attributes.actionTypeId === '.webhook',
pipeMigrations(addHasAuthConfigurationObject)
);

return {
'7.10.0': executeMigrationWithErrorHandling(migrationActions, '7.10.0'),
'7.11.0': executeMigrationWithErrorHandling(migrationWebhookConnectorHasAuth, '7.11.0'),
};
}

Expand Down
24 changes: 17 additions & 7 deletions x-pack/plugins/maps/server/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,28 @@ export function initRoutes(router, licenseUid, mapConfig, kbnVersion, logger) {
return badRequest('map.proxyElasticMapsServiceInMaps disabled');
}

const file = await emsClient.getDefaultFileManifest();
const layers = file.layers.map((layer) => {
const newLayer = { ...layer };
const id = encodeURIComponent(layer.layer_id);
const file = await emsClient.getDefaultFileManifest(); //need raw manifest
const fileLayers = await emsClient.getFileLayers();

const layers = file.layers.map((layerJson) => {
const newLayerJson = { ...layerJson };
const id = encodeURIComponent(layerJson.layer_id);

const fileLayer = fileLayers.find((fileLayer) => fileLayer.getId() === layerJson.layer_id);
const defaultFormat = layerJson.formats.find(
(format) => format.type === fileLayer.getDefaultFormatType()
);

const newUrl = `${EMS_FILES_DEFAULT_JSON_PATH}?id=${id}`;
newLayer.formats = [

//Only proxy default-format. Others are unused in Maps-app
newLayerJson.formats = [
{
...layer.formats[0],
...defaultFormat,
url: newUrl,
},
];
return newLayer;
return newLayerJson;
});
//rewrite
return ok({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
EuiRadio,
EuiSwitch,
EuiTitle,
EuiText,
EuiSpacer,
htmlIdGenerator,
EuiCallOut,
Expand All @@ -28,6 +29,7 @@ import { policyConfig } from '../../../store/policy_details/selectors';
import { usePolicyDetailsSelector } from '../../policy_hooks';
import { clone } from '../../../models/policy_details_config';
import { LinkToApp } from '../../../../../../common/components/endpoint/link_to_app';
import { popupVersionsMap } from './popup_options_to_versions';

const ProtectionRadioGroup = styled.div`
display: flex;
Expand Down Expand Up @@ -83,6 +85,25 @@ const ProtectionRadio = React.memo(({ id, label }: { id: ProtectionModes; label:

ProtectionRadio.displayName = 'ProtectionRadio';

const SupportedVersionNotice = ({ optionName }: { optionName: string }) => {
const version = popupVersionsMap.get(optionName);
if (!version) {
return null;
}

return (
<EuiText color="subdued" size="xs">
<i>
<FormattedMessage
id="xpack.securitySolution.endpoint.policyDetails.supportedVersion"
defaultMessage="Agent version {version}"
values={{ version }}
/>
</i>
</EuiText>
);
};

/** The Malware Protections form for policy details
* which will configure for all relevant OSes.
*/
Expand Down Expand Up @@ -189,14 +210,15 @@ export const MalwareProtections = React.memo(() => {
/>
</h6>
</EuiTitle>
<SupportedVersionNotice optionName="malware" />
<EuiSpacer size="s" />
<EuiCheckbox
id="xpack.securitySolution.endpoint.policyDetail.malware.userNotification"
onChange={handleUserNotificationCheckbox}
checked={userNotificationSelected}
label={i18n.translate(
'xpack.securitySolution.endpoint.policyDetail.malware.userNotification',
{ defaultMessage: 'User Notification' }
)}
label={i18n.translate('xpack.securitySolution.endpoint.policyDetail.malware.notifyUser', {
defaultMessage: 'Notify User',
})}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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.
*/

const popupVersions: Array<[string, string]> = [['malware', '7.11+']];

export const popupVersionsMap: ReadonlyMap<string, string> = new Map<string, string>(popupVersions);
1 change: 1 addition & 0 deletions x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -20244,6 +20244,7 @@
"xpack.triggersActionsUI.sections.actionsConnectorsList.unableToLoadActionTypesMessage": "アクションタイプを読み込めません",
"xpack.triggersActionsUI.sections.addAction.webhookAction.error.requiredHeaderKeyText": "キーが必要です。",
"xpack.triggersActionsUI.sections.addAction.webhookAction.error.requiredHeaderValueText": "値が必要です。",
"xpack.triggersActionsUI.sections.addAction.webhookAction.error.requiredHostText": "ユーザー名が必要です。",
"xpack.triggersActionsUI.sections.addAction.webhookAction.error.requiredMethodText": "メソッドが必要です",
"xpack.triggersActionsUI.sections.addAction.webhookAction.error.requiredPasswordText": "パスワードが必要です。",
"xpack.triggersActionsUI.sections.addAlert.error.greaterThenThreshold0Text": "しきい値 1 はしきい値 0 よりも大きい値にしてください。",
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -20264,6 +20264,7 @@
"xpack.triggersActionsUI.sections.actionsConnectorsList.unableToLoadActionTypesMessage": "无法加载操作类型",
"xpack.triggersActionsUI.sections.addAction.webhookAction.error.requiredHeaderKeyText": "“键”必填。",
"xpack.triggersActionsUI.sections.addAction.webhookAction.error.requiredHeaderValueText": "“值”必填。",
"xpack.triggersActionsUI.sections.addAction.webhookAction.error.requiredHostText": "“用户名”必填。",
"xpack.triggersActionsUI.sections.addAction.webhookAction.error.requiredMethodText": "“方法”必填",
"xpack.triggersActionsUI.sections.addAction.webhookAction.error.requiredPasswordText": "“密码”必填。",
"xpack.triggersActionsUI.sections.addAlert.error.greaterThenThreshold0Text": "阈值 1 应 > 阈值 0。",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ export interface WebhookConfig {
method: string;
url: string;
headers: Record<string, string>;
hasAuth: boolean;
}

export interface WebhookSecrets {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('actionTypeRegistry.get() works', () => {
});

describe('webhook connector validation', () => {
test('connector validation succeeds when hasAuth is true and connector config is valid', () => {
test('connector validation succeeds when connector config is valid', () => {
const actionConnector = {
secrets: {
user: 'user',
Expand All @@ -42,35 +42,6 @@ describe('webhook connector validation', () => {
method: 'PUT',
url: 'http://test.com',
headers: { 'content-type': 'text' },
hasAuth: true,
},
} as WebhookActionConnector;

expect(actionTypeModel.validateConnector(actionConnector)).toEqual({
errors: {
url: [],
method: [],
user: [],
password: [],
},
});
});

test('connector validation succeeds when hasAuth is false and connector config is valid', () => {
const actionConnector = {
secrets: {
user: '',
password: '',
},
id: 'test',
actionTypeId: '.webhook',
name: 'webhook',
isPreconfigured: false,
config: {
method: 'PUT',
url: 'http://test.com',
headers: { 'content-type': 'text' },
hasAuth: false,
},
} as WebhookActionConnector;

Expand All @@ -94,7 +65,6 @@ describe('webhook connector validation', () => {
name: 'webhook',
config: {
method: 'PUT',
hasAuth: true,
},
} as WebhookActionConnector;

Expand All @@ -103,7 +73,7 @@ describe('webhook connector validation', () => {
url: ['URL is required.'],
method: [],
user: [],
password: ['Password is required when username is used.'],
password: ['Password is required.'],
},
});
});
Expand All @@ -120,7 +90,6 @@ describe('webhook connector validation', () => {
config: {
method: 'PUT',
url: 'invalid.url',
hasAuth: true,
},
} as WebhookActionConnector;

Expand Down
Loading

0 comments on commit ec73aec

Please sign in to comment.