Skip to content

Commit

Permalink
[Cases] Revert preconfigured connectors support for Cases (#130372)
Browse files Browse the repository at this point in the history
* Fix bug with deprecated connectors

* Add integration test

* Improve integration tests

* Fix grammar

* Fix CI

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
cnasikas and kibanamachine authored Apr 27, 2022
1 parent f62530b commit 12fdfd6
Show file tree
Hide file tree
Showing 16 changed files with 300 additions and 138 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
162 changes: 126 additions & 36 deletions x-pack/plugins/cases/server/client/configure/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
* 2.0.
*/

import { CasesClientArgs } from '../types';
import { loggingSystemMock } from '@kbn/core/server/mocks';
import { getConnectors } from './client';
import { actionsClientMock } from '@kbn/actions-plugin/server/mocks';
import { ActionType } from '@kbn/actions-plugin/common/types';
import { CasesClientArgs } from '../types';
import { getConnectors } from './client';

describe('client', () => {
describe('getConnectors', () => {
Expand All @@ -18,68 +17,163 @@ 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,
isDeprecated: false,
referencedByCount: 1,
},
{
id: '2',
actionTypeId: '.servicenow',
name: '2',
config: {},
isPreconfigured: false,
isDeprecated: false,
referencedByCount: 1,
},
{
id: '3',
actionTypeId: '.unsupported',
name: '3',
config: {},
isPreconfigured: false,
isDeprecated: 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,
isDeprecated: false,
referencedByCount: 1,
},
{
id: '2',
actionTypeId: '.servicenow',
name: '2',
config: {},
isPreconfigured: false,
isDeprecated: 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,
isDeprecated: false,
referencedByCount: 1,
},
]);

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

const connectors = [
expect(await getConnectors(args)).toEqual([
{
id: '1',
actionTypeId: '.jira',
Expand All @@ -98,11 +192,7 @@ describe('client', () => {
isDeprecated: 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 @@ -223,9 +223,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
Loading

0 comments on commit 12fdfd6

Please sign in to comment.