Skip to content

Commit

Permalink
Merge branch 'main' into build/docker-cross-platform
Browse files Browse the repository at this point in the history
  • Loading branch information
jbudz committed Mar 23, 2022
2 parents bcfd87d + 7aa89aa commit cfddf02
Show file tree
Hide file tree
Showing 167 changed files with 4,798 additions and 1,260 deletions.
2 changes: 1 addition & 1 deletion dev_docs/contributing/standards.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Every team should be collecting telemetry metrics on it’s public API usage. Th

### APM

Kibana server and client are instrumented with APM node and APM RUM clients respectively, tracking serveral types of transactions by default, such as `page-load`, `request`, etc.
Kibana server and client are instrumented with APM node and APM RUM clients respectively, tracking several types of transactions by default, such as `page-load`, `request`, etc.
You may introduce custom transactions. Please refer to the [APM documentation](https://www.elastic.co/guide/en/apm/get-started/current/index.html) and follow these guidelines when doing so:

- Use dashed syntax for transaction types and names: `my-transaction-type` and `my-transaction-name`
Expand Down
2 changes: 1 addition & 1 deletion dev_docs/key_concepts/kibana_platform_plugin_intro.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ plugins to customize the Kibana experience. Examples of extension points are:
- core.overlays.showModal
- embeddables.registerEmbeddableFactory
- uiActions.registerAction
- core.saedObjects.registerType
- core.savedObjects.registerType

## Follow up material

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,31 @@ describe('validateFilePathInput', () => {
describe('windows', () => {
const os = OperatingSystem.WINDOWS;

it('does not warn on valid filenames', () => {
expect(
validateFilePathInput({
os,
value: 'C:\\Windows\\*\\FILENAME.EXE-1231205124.gz',
})
).not.toBeDefined();
expect(
validateFilePathInput({
os,
value: "C:\\Windows\\*\\test$ as2@13---12!@#A,DS.#$^&$!#~ 'as'd.华语.txt",
})
).toEqual(undefined);
});

it('warns on wildcard in file name at the end of the path', () => {
expect(validateFilePathInput({ os, value: 'c:\\path*.exe' })).toEqual(
FILENAME_WILDCARD_WARNING
);
expect(
validateFilePathInput({
os,
value: 'C:\\Windows\\*\\FILENAME.EXE-*.gz',
})
).toEqual(FILENAME_WILDCARD_WARNING);
});

it('warns on unix paths or non-windows paths', () => {
Expand All @@ -34,6 +55,7 @@ describe('validateFilePathInput', () => {
expect(validateFilePathInput({ os, value: 'c:\\path/opt' })).toEqual(FILEPATH_WARNING);
expect(validateFilePathInput({ os, value: '1242' })).toEqual(FILEPATH_WARNING);
expect(validateFilePathInput({ os, value: 'w12efdfa' })).toEqual(FILEPATH_WARNING);
expect(validateFilePathInput({ os, value: 'c:\\folder\\' })).toEqual(FILEPATH_WARNING);
});
});
describe('unix paths', () => {
Expand All @@ -42,8 +64,22 @@ describe('validateFilePathInput', () => {
? OperatingSystem.MAC
: OperatingSystem.LINUX;

it('does not warn on valid filenames', () => {
expect(validateFilePathInput({ os, value: '/opt/*/FILENAME.EXE-1231205124.gz' })).not.toEqual(
FILENAME_WILDCARD_WARNING
);
expect(
validateFilePathInput({
os,
value: "/opt/*/test$ as2@13---12!@#A,DS.#$^&$!#~ 'as'd.华语.txt",
})
).not.toEqual(FILENAME_WILDCARD_WARNING);
});
it('warns on wildcard in file name at the end of the path', () => {
expect(validateFilePathInput({ os, value: '/opt/bin*' })).toEqual(FILENAME_WILDCARD_WARNING);
expect(validateFilePathInput({ os, value: '/opt/FILENAME.EXE-*.gz' })).toEqual(
FILENAME_WILDCARD_WARNING
);
});

it('warns on windows paths', () => {
Expand All @@ -54,6 +90,7 @@ describe('validateFilePathInput', () => {
expect(validateFilePathInput({ os, value: 'opt/bin\\file.exe' })).toEqual(FILEPATH_WARNING);
expect(validateFilePathInput({ os, value: '1242' })).toEqual(FILEPATH_WARNING);
expect(validateFilePathInput({ os, value: 'w12efdfa' })).toEqual(FILEPATH_WARNING);
expect(validateFilePathInput({ os, value: '/folder/' })).toEqual(FILEPATH_WARNING);
});
});
});
Expand Down Expand Up @@ -577,50 +614,82 @@ describe('Unacceptable Mac/Linux exact paths', () => {
});
});

describe('Executable filenames with wildcard PATHS', () => {
describe('hasSimpleExecutableName', () => {
it('should return TRUE when MAC/LINUX wildcard paths have an executable name', () => {
const os =
parseInt((Math.random() * 2).toString(), 10) === 1
? OperatingSystem.MAC
: OperatingSystem.LINUX;

expect(
hasSimpleExecutableName({
os: OperatingSystem.LINUX,
os,
type: 'wildcard',
value: '/opt/*/app',
})
).toEqual(true);
expect(
hasSimpleExecutableName({
os: OperatingSystem.MAC,
os,
type: 'wildcard',
value: '/op*/**/app.dmg',
})
).toEqual(true);
});

it('should return TRUE when WINDOWS wildcards paths have a executable name', () => {
expect(
hasSimpleExecutableName({
os: OperatingSystem.WINDOWS,
os,
type: 'wildcard',
value: 'c:\\**\\path.exe',
value: "/sy*/test$ as2@13---12!@#A,DS.#$^&$!#~ 'as'd.华语.txt",
})
).toEqual(true);
});

it('should return FALSE when MAC/LINUX wildcard paths have a wildcard in executable name', () => {
const os =
parseInt((Math.random() * 2).toString(), 10) === 1
? OperatingSystem.MAC
: OperatingSystem.LINUX;

expect(
hasSimpleExecutableName({
os: OperatingSystem.LINUX,
os,
type: 'wildcard',
value: '/op/*/*pp',
})
).toEqual(false);
expect(
hasSimpleExecutableName({
os: OperatingSystem.MAC,
os,
type: 'wildcard',
value: '/op*/b**/ap.m**',
})
).toEqual(false);
});

it('should return TRUE when WINDOWS wildcards paths have a executable name', () => {
expect(
hasSimpleExecutableName({
os: OperatingSystem.WINDOWS,
type: 'wildcard',
value: 'c:\\**\\path.exe',
})
).toEqual(true);
expect(
hasSimpleExecutableName({
os: OperatingSystem.WINDOWS,
type: 'wildcard',
value: 'C:\\*\\file-name.path华语 1234.txt',
})
).toEqual(true);
expect(
hasSimpleExecutableName({
os: OperatingSystem.WINDOWS,
type: 'wildcard',
value: "C:\\*\\test$ as2@13---12!@#A,DS.#$^&$!#~ 'as'd.华语.txt",
})
).toEqual(true);
});

it('should return FALSE when WINDOWS wildcards paths have a wildcard in executable name', () => {
expect(
hasSimpleExecutableName({
Expand Down
25 changes: 8 additions & 17 deletions packages/kbn-securitysolution-utils/src/path_validations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,6 @@ export const enum OperatingSystem {
export type EntryTypes = 'match' | 'wildcard' | 'match_any';
export type TrustedAppEntryTypes = Extract<EntryTypes, 'match' | 'wildcard'>;

/*
* regex to match executable names
* starts matching from the eol of the path
* file names with a single or multiple spaces (for spaced names)
* and hyphens and combinations of these that produce complex names
* such as:
* c:\home\lib\dmp.dmp
* c:\home\lib\my-binary-app-+/ some/ x/ dmp.dmp
* /home/lib/dmp.dmp
* /home/lib/my-binary-app+-\ some\ x\ dmp.dmp
*/
export const WIN_EXEC_PATH = /(\\[-\w]+|\\[-\w]+[\.]+[\w]+)$/i;
export const UNIX_EXEC_PATH = /(\/[-\w]+|\/[-\w]+[\.]+[\w]+)$/i;

export const validateFilePathInput = ({
os,
value = '',
Expand All @@ -70,7 +56,7 @@ export const validateFilePathInput = ({
}

if (isValidFilePath) {
if (!hasSimpleFileName) {
if (hasSimpleFileName !== undefined && !hasSimpleFileName) {
return FILENAME_WILDCARD_WARNING;
}
} else {
Expand All @@ -86,9 +72,14 @@ export const hasSimpleExecutableName = ({
os: OperatingSystem;
type: EntryTypes;
value: string;
}): boolean => {
}): boolean | undefined => {
const separator = os === OperatingSystem.WINDOWS ? '\\' : '/';
const lastString = value.split(separator).pop();
if (!lastString) {
return;
}
if (type === 'wildcard') {
return os === OperatingSystem.WINDOWS ? WIN_EXEC_PATH.test(value) : UNIX_EXEC_PATH.test(value);
return (lastString.split('*').length || lastString.split('?').length) === 1;
}
return true;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import { Schema } from '../../../../shared/schema/types';

import { Fields } from './types';

export const buildSearchUIConfig = (apiConnector: object, schema: Schema, fields: Fields) => {
export const buildSearchUIConfig = (
apiConnector: object,
schema: Schema,
fields: Fields,
initialState = { sortDirection: 'desc', sortField: 'id' }
) => {
const facets = fields.filterFields.reduce(
(facetsConfig, fieldName) => ({
...facetsConfig,
Expand All @@ -22,10 +27,7 @@ export const buildSearchUIConfig = (apiConnector: object, schema: Schema, fields
alwaysSearchOnInitialLoad: true,
apiConnector,
trackUrlState: false,
initialState: {
sortDirection: 'desc',
sortField: 'id',
},
initialState,
searchQuery: {
disjunctiveFacets: fields.filterFields,
facets,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,39 @@ import { SearchExperienceContent } from './search_experience_content';
import { Fields, SortOption } from './types';
import { SearchBoxView, SortingView, MultiCheckboxFacetsView } from './views';

const RECENTLY_UPLOADED = i18n.translate(
'xpack.enterpriseSearch.appSearch.documents.search.sortBy.option.recentlyUploaded',
const DOCUMENT_ID = i18n.translate(
'xpack.enterpriseSearch.appSearch.documents.search.sortBy.option.documentId',
{
defaultMessage: 'Recently Uploaded',
defaultMessage: 'Document ID',
}
);

const RELEVANCE = i18n.translate(
'xpack.enterpriseSearch.appSearch.documents.search.sortBy.option.relevance',
{ defaultMessage: 'Relevance' }
);

const DEFAULT_SORT_OPTIONS: SortOption[] = [
{
name: DESCENDING(RECENTLY_UPLOADED),
name: DESCENDING(DOCUMENT_ID),
value: 'id',
direction: 'desc',
},
{
name: ASCENDING(RECENTLY_UPLOADED),
name: ASCENDING(DOCUMENT_ID),
value: 'id',
direction: 'asc',
},
];

const RELEVANCE_SORT_OPTIONS: SortOption[] = [
{
name: RELEVANCE,
value: '_score',
direction: 'desc',
},
];

export const SearchExperience: React.FC = () => {
const { engine } = useValues(EngineLogic);
const { http } = useValues(HttpLogic);
Expand All @@ -66,8 +80,10 @@ export const SearchExperience: React.FC = () => {
sortFields: [],
}
);
const sortOptions =
engine.type === 'elasticsearch' ? RELEVANCE_SORT_OPTIONS : DEFAULT_SORT_OPTIONS;

const sortingOptions = buildSortOptions(fields, DEFAULT_SORT_OPTIONS);
const sortingOptions = buildSortOptions(fields, sortOptions);

const connector = new AppSearchAPIConnector({
cacheResponses: false,
Expand All @@ -78,7 +94,17 @@ export const SearchExperience: React.FC = () => {
},
});

const searchProviderConfig = buildSearchUIConfig(connector, engine.schema || {}, fields);
const initialState = {
sortField: engine.type === 'elasticsearch' ? '_score' : 'id',
sortDirection: 'desc',
};

const searchProviderConfig = buildSearchUIConfig(
connector,
engine.schema || {},
fields,
initialState
);

return (
<div className="documentsSearchExperience">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export enum EngineTypes {
default = 'default',
indexed = 'indexed',
meta = 'meta',
elasticsearch = 'elasticsearch',
}
export interface Engine {
name: string;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cfddf02

Please sign in to comment.