Skip to content

Commit

Permalink
[Cases] Revert preconfigured connectors support for Cases (elastic#13…
Browse files Browse the repository at this point in the history
…0372)

* 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/public/components/connectors/servicenow/servicenow_itsm_case_fields.test.tsx
#	x-pack/plugins/cases/public/components/connectors/servicenow/servicenow_sir_case_fields.test.tsx
#	x-pack/plugins/cases/server/client/configure/client.test.ts
#	x-pack/test/case_api_integration/security_and_spaces/tests/basic/configure/create_connector.ts
#	x-pack/test/case_api_integration/security_and_spaces/tests/basic/configure/get_connectors.ts
#	x-pack/test/case_api_integration/security_and_spaces/tests/common/configure/get_connectors.ts
#	x-pack/test/cases_api_integration/common/config.ts
#	x-pack/test/cases_api_integration/common/lib/utils.ts
#	x-pack/test/cases_api_integration/security_and_spaces/tests/common/configure/get_connectors.ts
#	x-pack/test/cases_api_integration/security_and_spaces/tests/common/index.ts
#	x-pack/test/cases_api_integration/security_and_spaces/tests/trial/configure/get_connectors.ts
#	x-pack/test/cases_api_integration/spaces_only/tests/trial/configure/get_connectors.ts
  • Loading branch information
cnasikas committed Apr 27, 2022
1 parent 97b1465 commit 219a29d
Show file tree
Hide file tree
Showing 16 changed files with 289 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,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();
});

describe('onChange calls', () => {
const wrapper = mount(<Fields fields={fields} onChange={onChange} connector={connector} />);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,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();
});

describe('onChange calls', () => {
const wrapper = mount(<Fields fields={fields} onChange={onChange} connector={connector} />);

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
149 changes: 116 additions & 33 deletions x-pack/plugins/cases/server/client/configure/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,66 +18,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 +181,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
13 changes: 13 additions & 0 deletions x-pack/test/case_api_integration/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,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/case_api_integration/common/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,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

This file was deleted.

Loading

0 comments on commit 219a29d

Please sign in to comment.