Skip to content

Commit

Permalink
[8.1] [Cases] Revert preconfigured connectors support for Cases (#130372
Browse files Browse the repository at this point in the history
) (#131043)

* [Cases] Revert preconfigured connectors support for Cases (#130372)

* Fix bug with deprecated connectors

* Add integration test

* Improve integration tests

* Fix grammar

* Fix CI

Co-authored-by: Kibana Machine <[email protected]>
(cherry picked from commit 12fdfd6)

# Conflicts:
#	x-pack/plugins/cases/server/client/configure/client.test.ts

* Fix linting
  • Loading branch information
cnasikas authored Apr 27, 2022
1 parent 2e64711 commit c96cd10
Show file tree
Hide file tree
Showing 16 changed files with 287 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,25 @@ describe('ServiceNowITSM Fields', () => {
expect(screen.queryByTestId('deprecated-connector-warning-callout')).not.toBeInTheDocument();
});

it('does not show the deprecated callout when the connector is preconfigured', async () => {
render(
<Fields
fields={fields}
onChange={onChange}
connector={{ ...connector, isPreconfigured: true }}
/>
);
expect(screen.queryByTestId('deprecated-connector-warning-callout')).not.toBeInTheDocument();
});

it('does not show the deprecated callout when the config of the connector is undefined', async () => {
render(
// @ts-expect-error
<Fields fields={fields} onChange={onChange} connector={{ ...connector, config: undefined }} />
);
expect(screen.queryByTestId('deprecated-connector-warning-callout')).not.toBeInTheDocument();
});

it('should hide subcategory if selecting a category without subcategories', async () => {
// Failed Login doesn't have defined subcategories
const customFields = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,25 @@ describe('ServiceNowSIR Fields', () => {
expect(screen.queryByTestId('deprecated-connector-warning-callout')).not.toBeInTheDocument();
});

it('does not show the deprecated callout when the connector is preconfigured', async () => {
render(
<Fields
fields={fields}
onChange={onChange}
connector={{ ...connector, isPreconfigured: true }}
/>
);
expect(screen.queryByTestId('deprecated-connector-warning-callout')).not.toBeInTheDocument();
});

it('does not show the deprecated callout when the config of the connector is undefined', async () => {
render(
// @ts-expect-error
<Fields fields={fields} onChange={onChange} connector={{ ...connector, config: undefined }} />
);
expect(screen.queryByTestId('deprecated-connector-warning-callout')).not.toBeInTheDocument();
});

test('it should hide subcategory if selecting a category without subcategories', async () => {
// Failed Login doesn't have defined subcategories
const customFields = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('ServiceNow validator', () => {
expect(connectorValidator(invalidConnector)).toEqual({ message: 'Deprecated connector' });
});

test('it does not returns an error message if the connector does not uses the table API', () => {
test('it does not return an error message if the connector does not uses the table API', () => {
const invalidConnector = {
...connector,
config: {
Expand All @@ -33,5 +33,16 @@ describe('ServiceNow validator', () => {

expect(connectorValidator(invalidConnector)).toBeFalsy();
});

test('it does not return an error message if the config of the connector is undefined', () => {
const { config, ...invalidConnector } = connector;

// @ts-expect-error
expect(connectorValidator(invalidConnector)).toBeFalsy();
});

test('it does not return an error message if the config of the connector is preconfigured', () => {
expect(connectorValidator({ ...connector, isPreconfigured: true })).toBeFalsy();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@ import { CaseActionConnector } from '../../types';
export const connectorValidator = (
connector: CaseActionConnector
): ReturnType<ValidationConfig['validator']> => {
const {
config: { usesTableApi },
} = connector;
if (usesTableApi) {
/**
* It is not possible to know if a preconfigured connector
* is deprecated or not as the config property of a
* preconfigured connector is not returned by the
* actions framework
*/

if (connector.isPreconfigured || connector.config == null) {
return;
}

if (connector.config?.usesTableApi) {
return {
message: 'Deprecated connector',
};
Expand Down
11 changes: 11 additions & 0 deletions x-pack/plugins/cases/public/components/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,16 @@ describe('Utils', () => {
})
).toBe(true);
});

it('returns false if the connector preconfigured', () => {
expect(isDeprecatedConnector({ ...connector, isPreconfigured: true })).toBe(false);
});

it('returns false if the config is undefined', () => {
expect(
// @ts-expect-error
isDeprecatedConnector({ ...connector, config: undefined })
).toBe(false);
});
});
});
8 changes: 7 additions & 1 deletion x-pack/plugins/cases/public/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ export const getConnectorIcon = (

// TODO: Remove when the applications are certified
export const isDeprecatedConnector = (connector?: CaseActionConnector): boolean => {
if (connector == null) {
/**
* It is not possible to know if a preconfigured connector
* is deprecated or not as the config property of a
* preconfigured connector is not returned by the
* actions framework
*/
if (connector == null || connector.config == null || connector.isPreconfigured) {
return false;
}

Expand Down
150 changes: 116 additions & 34 deletions x-pack/plugins/cases/server/client/configure/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { CasesClientArgs } from '../types';
import { loggingSystemMock } from '../../../../../../src/core/server/mocks';
import { getConnectors } from './client';
import { actionsClientMock } from '../../../../actions/server/mocks';
import { ActionType } from '../../../../actions/common/types';

describe('client', () => {
describe('getConnectors', () => {
Expand All @@ -18,66 +17,153 @@ describe('client', () => {

const args = { actionsClient, logger } as unknown as CasesClientArgs;

const jiraType: ActionType = {
id: '.jira',
name: '1',
enabled: true,
enabledInConfig: true,
enabledInLicense: true,
minimumLicenseRequired: 'basic',
};
const actionTypes = [
{
id: '.jira',
name: '1',
enabled: true,
enabledInConfig: true,
enabledInLicense: true,
minimumLicenseRequired: 'basic' as const,
},
{
id: '.servicenow',
name: '2',
enabled: true,
enabledInConfig: true,
enabledInLicense: true,
minimumLicenseRequired: 'basic' as const,
},
{
id: '.unsupported',
name: '3',
enabled: true,
enabledInConfig: true,
enabledInLicense: true,
minimumLicenseRequired: 'basic' as const,
},
{
id: '.swimlane',
name: 'swimlane',
enabled: true,
enabledInConfig: true,
enabledInLicense: false,
minimumLicenseRequired: 'basic' as const,
},
];

const connectors = [
{
id: '1',
actionTypeId: '.jira',
name: '1',
config: {},
isPreconfigured: false,
referencedByCount: 1,
},
{
id: '2',
actionTypeId: '.servicenow',
name: '2',
config: {},
isPreconfigured: false,
referencedByCount: 1,
},
{
id: '3',
actionTypeId: '.unsupported',
name: '3',
config: {},
isPreconfigured: false,
referencedByCount: 1,
},
];

beforeEach(() => {
jest.clearAllMocks();
});

it('removes connectors without a config field defined', async () => {
actionsClient.listTypes.mockImplementation(async () => [jiraType]);
it('remove unsupported connectors', async () => {
actionsClient.listTypes.mockImplementation(async () => actionTypes);
actionsClient.getAll.mockImplementation(async () => connectors);

actionsClient.getAll.mockImplementation(async () => [
expect(await getConnectors(args)).toEqual([
{
id: '1',
actionTypeId: '.jira',
name: '1',
config: {},
isPreconfigured: false,
referencedByCount: 1,
},
{
id: '2',
actionTypeId: '.servicenow',
name: '2',
config: {},
isPreconfigured: false,
referencedByCount: 1,
},
]);

expect(await getConnectors(args)).toEqual([]);
});

it('removes connectors that are pre configured', async () => {
actionsClient.listTypes.mockImplementation(async () => [jiraType]);

it('returns preconfigured connectors', async () => {
actionsClient.listTypes.mockImplementation(async () => actionTypes);
actionsClient.getAll.mockImplementation(async () => [
...connectors,
{
id: '4',
actionTypeId: '.servicenow',
name: 'sn-preconfigured',
config: {},
isPreconfigured: true,
referencedByCount: 1,
},
]);

expect(await getConnectors(args)).toEqual([
{
id: '1',
actionTypeId: '.jira',
name: '1',
config: {},
isPreconfigured: false,
referencedByCount: 1,
},
{
id: '2',
actionTypeId: '.servicenow',
name: '2',
config: {},
isPreconfigured: false,
referencedByCount: 1,
},
{
id: '4',
actionTypeId: '.servicenow',
name: 'sn-preconfigured',
config: {},
isPreconfigured: true,
referencedByCount: 1,
},
]);

expect(await getConnectors(args)).toEqual([]);
});

it('includes connectors that have a config and are not pre configured', async () => {
actionsClient.listTypes.mockImplementation(async () => [
jiraType,
it('filter out connectors that are unsupported by the current license', async () => {
actionsClient.listTypes.mockImplementation(async () => actionTypes);
actionsClient.getAll.mockImplementation(async () => [
...connectors,
{
id: '.servicenow',
name: '2',
enabled: true,
enabledInConfig: true,
enabledInLicense: true,
minimumLicenseRequired: 'basic',
id: '4',
actionTypeId: '.swimlane',
name: 'swimlane',
config: {},
isPreconfigured: false,
referencedByCount: 1,
},
]);

const connectors = [
expect(await getConnectors(args)).toEqual([
{
id: '1',
actionTypeId: '.jira',
Expand All @@ -94,11 +180,7 @@ describe('client', () => {
isPreconfigured: false,
referencedByCount: 1,
},
];

actionsClient.getAll.mockImplementation(async () => connectors);

expect(await getConnectors(args)).toEqual(connectors);
]);
});
});
});
4 changes: 1 addition & 3 deletions x-pack/plugins/cases/server/client/configure/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,7 @@ function isConnectorSupported(
): boolean {
return (
SUPPORTED_CONNECTORS.includes(action.actionTypeId) &&
actionTypes[action.actionTypeId]?.enabledInLicense &&
action.config != null &&
!action.isPreconfigured
actionTypes[action.actionTypeId]?.enabledInLicense
);
}

Expand Down
14 changes: 13 additions & 1 deletion x-pack/test/cases_api_integration/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ interface CreateTestConfigOptions {
testFiles?: string[];
}

// test.not-enabled is specifically not enabled
const enabledActionTypes = [
'.email',
'.index',
Expand Down Expand Up @@ -139,6 +138,19 @@ export function createTestConfig(name: string, options: CreateTestConfigOptions)
(pluginDir) =>
`--plugin-path=${path.resolve(__dirname, 'fixtures', 'plugins', pluginDir)}`
),
`--xpack.actions.preconfigured=${JSON.stringify({
'preconfigured-servicenow': {
name: 'preconfigured-servicenow',
actionTypeId: '.servicenow',
config: {
apiUrl: 'https://example.com',
},
secrets: {
username: 'elastic',
password: 'elastic',
},
},
})}`,
`--server.xsrf.allowlist=${JSON.stringify(getAllExternalServiceSimulatorPaths())}`,
...(ssl
? [
Expand Down
13 changes: 13 additions & 0 deletions x-pack/test/cases_api_integration/common/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,19 @@ export const getWebhookConnector = () => ({
},
});

export const getEmailConnector = () => ({
name: 'An email action',
connector_type_id: '.email',
config: {
service: '__json',
from: '[email protected]',
},
secrets: {
user: 'bob',
password: 'supersecret',
},
});

interface CommonSavedObjectAttributes {
id?: string | null;
created_at?: string | null;
Expand Down
Loading

0 comments on commit c96cd10

Please sign in to comment.