Skip to content

Commit

Permalink
Limit supported connectors to 1000.
Browse files Browse the repository at this point in the history
Tests.
  • Loading branch information
adcoelho committed Jul 6, 2023
1 parent 29ac919 commit 07ce011
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions x-pack/plugins/cases/common/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const MAX_CATEGORY_FILTER_LENGTH = 100 as const;
export const MAX_TAGS_FILTER_LENGTH = 100 as const;
export const MAX_ASSIGNEES_FILTER_LENGTH = 100 as const;
export const MAX_REPORTERS_FILTER_LENGTH = 100 as const;
export const MAX_SUPPORTED_CONNECTORS_RETURNED = 1000 as const;

/**
* Validation
Expand Down
10 changes: 10 additions & 0 deletions x-pack/plugins/cases/server/client/configure/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { actionsClientMock } from '@kbn/actions-plugin/server/mocks';
import type { CasesClientArgs } from '../types';
import { getConnectors, get, update } from './client';
import { createCasesClientInternalMock, createCasesClientMockArgs } from '../mocks';
import { MAX_SUPPORTED_CONNECTORS_RETURNED } from '../../../common/constants';

describe('client', () => {
const clientArgs = createCasesClientMockArgs();
Expand Down Expand Up @@ -219,6 +220,15 @@ describe('client', () => {
},
]);
});

it('limits connectors returned to 1000', async () => {
actionsClient.listTypes.mockImplementation(async () => actionTypes.slice(0, 1));
actionsClient.getAll.mockImplementation(async () =>
Array(MAX_SUPPORTED_CONNECTORS_RETURNED + 1).fill(connectors[0])
);

expect((await getConnectors(args)).length).toEqual(MAX_SUPPORTED_CONNECTORS_RETURNED);
});
});

describe('get', () => {
Expand Down
11 changes: 7 additions & 4 deletions x-pack/plugins/cases/server/client/configure/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ import {
} from '../../../common/types/api';
import type { ConnectorMappings, ConnectorMappingResponse } from '../../../common/api';
import { FindActionConnectorResponseRt, decodeWithExcessOrThrow } from '../../../common/api';
import { MAX_CONCURRENT_SEARCHES } from '../../../common/constants';
import {
MAX_CONCURRENT_SEARCHES,
MAX_SUPPORTED_CONNECTORS_RETURNED,
} from '../../../common/constants';
import { createCaseError } from '../../common/error';
import type { CasesClientInternal } from '../client_internal';
import type { CasesClientArgs } from '../types';
Expand Down Expand Up @@ -207,9 +210,9 @@ export async function getConnectors({
return types;
}, {} as Record<string, ActionType>);

const res = (await actionsClient.getAll()).filter((action) =>
isConnectorSupported(action, actionTypes)
);
const res = (await actionsClient.getAll())
.filter((action) => isConnectorSupported(action, actionTypes))
.slice(0, MAX_SUPPORTED_CONNECTORS_RETURNED);

return decodeOrThrow(FindActionConnectorResponseRt)(res);
} catch (error) {
Expand Down

0 comments on commit 07ce011

Please sign in to comment.