Skip to content

Commit c644ecd

Browse files
authored
Implemented trusted app name truncation. (#79976) (#79983)
1 parent 8c93f15 commit c644ecd

File tree

12 files changed

+173
-135
lines changed

12 files changed

+173
-135
lines changed

x-pack/plugins/security_solution/common/endpoint/schema/trusted_apps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const GetTrustedAppsRequestSchema = {
3535

3636
export const PostTrustedAppCreateRequestSchema = {
3737
body: schema.object({
38-
name: schema.string({ minLength: 1 }),
38+
name: schema.string({ minLength: 1, maxLength: 256 }),
3939
description: schema.maybe(schema.string({ minLength: 0, maxLength: 256, defaultValue: '' })),
4040
os: schema.oneOf([schema.literal('linux'), schema.literal('macos'), schema.literal('windows')]),
4141
entries: schema.arrayOf(

x-pack/plugins/security_solution/public/management/pages/trusted_apps/test_utils/index.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,39 @@ import { TrustedAppsListResourceStateChanged } from '../store/action';
3333

3434
const OS_LIST: Array<TrustedApp['os']> = ['windows', 'macos', 'linux'];
3535

36-
export const createSampleTrustedApp = (i: number): TrustedApp => {
36+
const generate = <T>(count: number, generator: (i: number) => T) =>
37+
[...new Array(count).keys()].map(generator);
38+
39+
export const createSampleTrustedApp = (i: number, longTexts?: boolean): TrustedApp => {
3740
return {
3841
id: String(i),
39-
name: `trusted app ${i}`,
40-
description: `Trusted App ${i}`,
42+
name: generate(longTexts ? 10 : 1, () => `trusted app ${i}`).join(' '),
43+
description: generate(longTexts ? 10 : 1, () => `Trusted App ${i}`).join(' '),
4144
created_at: '1 minute ago',
4245
created_by: 'someone',
4346
os: OS_LIST[i % 3],
4447
entries: [],
4548
};
4649
};
4750

48-
export const createSampleTrustedApps = (pagination: Partial<Pagination>): TrustedApp[] => {
51+
export const createSampleTrustedApps = (
52+
pagination: Partial<Pagination>,
53+
longTexts?: boolean
54+
): TrustedApp[] => {
4955
const fullPagination = { ...createDefaultPagination(), ...pagination };
5056

51-
return [...new Array(fullPagination.pageSize).keys()].map(createSampleTrustedApp);
57+
return generate(fullPagination.pageSize, (i: number) => createSampleTrustedApp(i, longTexts));
5258
};
5359

54-
export const createTrustedAppsListData = (pagination: Partial<Pagination>, timestamp: number) => {
60+
export const createTrustedAppsListData = (
61+
pagination: Partial<Pagination>,
62+
timestamp: number,
63+
longTexts?: boolean
64+
) => {
5565
const fullPagination = { ...createDefaultPagination(), ...pagination };
5666

5767
return {
58-
items: createSampleTrustedApps(fullPagination),
68+
items: createSampleTrustedApps(fullPagination, longTexts),
5969
pageSize: fullPagination.pageSize,
6070
pageIndex: fullPagination.pageIndex,
6171
totalItemsCount: fullPagination.totalItemCount,
@@ -75,10 +85,11 @@ export const createUninitialisedResourceState = (): UninitialisedResourceState =
7585

7686
export const createListLoadedResourceState = (
7787
pagination: Partial<Pagination>,
78-
timestamp: number
88+
timestamp: number,
89+
longTexts?: boolean
7990
): LoadedResourceState<TrustedAppsListData> => ({
8091
type: 'LoadedResourceState',
81-
data: createTrustedAppsListData(pagination, timestamp),
92+
data: createTrustedAppsListData(pagination, timestamp, longTexts),
8293
});
8394

8495
export const createListFailedResourceState = (

x-pack/plugins/security_solution/public/management/pages/trusted_apps/view/components/create_trusted_app_form.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ export const CreateTrustedAppForm = memo<CreateTrustedAppFormProps>(
361361
onBlur={handleDomBlurEvents}
362362
fullWidth
363363
required
364+
maxLength={256}
364365
data-test-subj={getTestId('nameTextField')}
365366
/>
366367
</EuiFormRow>

x-pack/plugins/security_solution/public/management/pages/trusted_apps/view/components/trusted_app_card/__snapshots__/index.test.tsx.snap

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugins/security_solution/public/management/pages/trusted_apps/view/components/trusted_app_card/index.stories.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,10 @@ storiesOf('TrustedApps/TrustedAppCard', module)
5353

5454
return <TrustedAppCard trustedApp={trustedApp} onDelete={action('onClick')} />;
5555
})
56-
.add('trim description', () => {
57-
const trustedApp: TrustedApp = createSampleTrustedApp(5);
56+
.add('longs texts', () => {
57+
const trustedApp: TrustedApp = createSampleTrustedApp(5, true);
5858
trustedApp.created_at = '2020-09-17T14:52:33.899Z';
5959
trustedApp.entries = [PATH_CONDITION, SIGNER_CONDITION];
60-
trustedApp.description = [...new Array(40).keys()].map((index) => `item${index}`).join(' ');
6160

6261
return <TrustedAppCard trustedApp={trustedApp} onDelete={action('onClick')} />;
6362
});

x-pack/plugins/security_solution/public/management/pages/trusted_apps/view/components/trusted_app_card/index.test.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ describe('trusted_app_card', () => {
1919
expect(element).toMatchSnapshot();
2020
});
2121

22-
it('should trim long descriptions', () => {
23-
const trustedApp = {
24-
...createSampleTrustedApp(4),
25-
description: [...new Array(40).keys()].map((index) => `item${index}`).join(' '),
26-
};
27-
const element = shallow(<TrustedAppCard trustedApp={trustedApp} onDelete={() => {}} />);
22+
it('should trim long texts', () => {
23+
const element = shallow(
24+
<TrustedAppCard trustedApp={createSampleTrustedApp(4, true)} onDelete={() => {}} />
25+
);
2826

2927
expect(element).toMatchSnapshot();
3028
});

x-pack/plugins/security_solution/public/management/pages/trusted_apps/view/components/trusted_app_card/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ export const TrustedAppCard = memo(({ trustedApp, onDelete }: TrustedAppCardProp
8484

8585
return (
8686
<ItemDetailsCard>
87-
<ItemDetailsPropertySummary name={PROPERTY_TITLES.name} value={trustedApp.name} />
87+
<ItemDetailsPropertySummary
88+
name={PROPERTY_TITLES.name}
89+
value={useMemo(() => trimTextOverflow(trustedApp.name || '', 100), [trustedApp.name])}
90+
title={trustedApp.name}
91+
/>
8892
<ItemDetailsPropertySummary name={PROPERTY_TITLES.os} value={OS_TITLES[trustedApp.os]} />
8993
<ItemDetailsPropertySummary
9094
name={PROPERTY_TITLES.created_at}

0 commit comments

Comments
 (0)