Skip to content

Commit

Permalink
Fixing connector tests that only work in trial license
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-buttner committed Apr 27, 2021
1 parent 3d4726d commit 518db99
Show file tree
Hide file tree
Showing 11 changed files with 407 additions and 326 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { createConnector, getServiceNowConnector } from '../../../../common/lib/utils';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';

// eslint-disable-next-line import/no-default-export
export default function serviceNow({ getService }: FtrProviderContext) {
const supertest = getService('supertest');

describe('create service now action', () => {
it('should return 403 when creating a service now action', async () => {
await createConnector(supertest, getServiceNowConnector(), 403);
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,13 @@
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';

import { ObjectRemover as ActionsRemover } from '../../../../../alerting_api_integration/common/lib';
import {
ExternalServiceSimulator,
getExternalServiceSimulatorPath,
} from '../../../../../alerting_api_integration/common/fixtures/plugins/actions_simulators/server/plugin';
import { ConnectorTypes } from '../../../../../../plugins/cases/common/api';
import {
removeServerGeneratedPropertiesFromSavedObject,
getConfigurationOutput,
deleteConfiguration,
getConfiguration,
createConfiguration,
getConfigurationRequest,
createConnector,
getServiceNowConnector,
ensureSavedObjectIsAuthorized,
} from '../../../../common/lib/utils';
import {
Expand All @@ -42,21 +34,10 @@ export default ({ getService }: FtrProviderContext): void => {
const supertest = getService('supertest');
const supertestWithoutAuth = getService('supertestWithoutAuth');
const es = getService('es');
const kibanaServer = getService('kibanaServer');

describe('get_configure', () => {
const actionsRemover = new ActionsRemover(supertest);
let servicenowSimulatorURL: string = '<could not determine kibana url>';

before(() => {
servicenowSimulatorURL = kibanaServer.resolveUrl(
getExternalServiceSimulatorPath(ExternalServiceSimulator.SERVICENOW)
);
});

afterEach(async () => {
await deleteConfiguration(es);
await actionsRemover.removeAll();
});

it('should return an empty find body correctly if no configuration is loaded', async () => {
Expand Down Expand Up @@ -91,54 +72,6 @@ export default ({ getService }: FtrProviderContext): void => {
expect(data).to.eql(getConfigurationOutput());
});

it('should return a configuration with mapping', async () => {
const connector = await createConnector(supertest, {
...getServiceNowConnector(),
config: { apiUrl: servicenowSimulatorURL },
});

actionsRemover.add('default', connector.id, 'action', 'actions');

await createConfiguration(
supertest,
getConfigurationRequest({
id: connector.id,
name: connector.name,
type: connector.connector_type_id as ConnectorTypes,
})
);

const configuration = await getConfiguration({ supertest });
const data = removeServerGeneratedPropertiesFromSavedObject(configuration[0]);
expect(data).to.eql(
getConfigurationOutput(false, {
mappings: [
{
action_type: 'overwrite',
source: 'title',
target: 'short_description',
},
{
action_type: 'overwrite',
source: 'description',
target: 'description',
},
{
action_type: 'append',
source: 'comments',
target: 'work_notes',
},
],
connector: {
id: connector.id,
name: connector.name,
type: connector.connector_type_id,
fields: null,
},
})
);
});

describe('rbac', () => {
it('should return the correct configuration', async () => {
await createConfiguration(supertestWithoutAuth, getConfigurationRequest(), 200, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,86 +8,18 @@
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../../../common/ftr_provider_context';

import { ObjectRemover as ActionsRemover } from '../../../../../alerting_api_integration/common/lib';
import {
getCaseConnectors,
createConnector,
getServiceNowConnector,
getJiraConnector,
getResilientConnector,
getServiceNowSIRConnector,
getWebhookConnector,
} from '../../../../common/lib/utils';
import { getCaseConnectors } from '../../../../common/lib/utils';

// eslint-disable-next-line import/no-default-export
export default ({ getService }: FtrProviderContext): void => {
const supertest = getService('supertest');
const actionsRemover = new ActionsRemover(supertest);

describe('get_connectors', () => {
afterEach(async () => {
await actionsRemover.removeAll();
});

it('should return an empty find body correctly if no connectors are loaded', async () => {
const connectors = await getCaseConnectors(supertest);
expect(connectors).to.eql([]);
});

it('should return case owned connectors', async () => {
const sn = await createConnector(supertest, getServiceNowConnector());
actionsRemover.add('default', sn.id, 'action', 'actions');

const jira = await createConnector(supertest, getJiraConnector());
actionsRemover.add('default', jira.id, 'action', 'actions');

const resilient = await createConnector(supertest, getResilientConnector());
actionsRemover.add('default', resilient.id, 'action', 'actions');

const sir = await createConnector(supertest, getServiceNowSIRConnector());
actionsRemover.add('default', sir.id, 'action', 'actions');

// Should not be returned when getting the connectors
const webhook = await createConnector(supertest, getWebhookConnector());
actionsRemover.add('default', webhook.id, 'action', 'actions');

const connectors = await getCaseConnectors(supertest);
expect(connectors).to.eql([
{
id: jira.id,
actionTypeId: '.jira',
name: 'Jira Connector',
config: { apiUrl: 'http://some.non.existent.com', projectKey: 'pkey' },
isPreconfigured: false,
referencedByCount: 0,
},
{
id: resilient.id,
actionTypeId: '.resilient',
name: 'Resilient Connector',
config: { apiUrl: 'http://some.non.existent.com', orgId: 'pkey' },
isPreconfigured: false,
referencedByCount: 0,
},
{
id: sn.id,
actionTypeId: '.servicenow',
name: 'ServiceNow Connector',
config: { apiUrl: 'http://some.non.existent.com' },
isPreconfigured: false,
referencedByCount: 0,
},
{
id: sir.id,
actionTypeId: '.servicenow-sir',
name: 'ServiceNow Connector',
config: { apiUrl: 'http://some.non.existent.com' },
isPreconfigured: false,
referencedByCount: 0,
},
]);
});

it.skip('filters out connectors that are not enabled in license', async () => {
// TODO: Should find a way to downgrade license to gold and upgrade back to trial
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../../common/ftr_provider_context';
import { ObjectRemover as ActionsRemover } from '../../../../../alerting_api_integration/common/lib';
import {
ExternalServiceSimulator,
getExternalServiceSimulatorPath,
} from '../../../../../alerting_api_integration/common/fixtures/plugins/actions_simulators/server/plugin';

import {
getConfigurationRequest,
Expand All @@ -20,10 +16,7 @@ import {
deleteConfiguration,
createConfiguration,
updateConfiguration,
getServiceNowConnector,
createConnector,
} from '../../../../common/lib/utils';
import { ConnectorTypes } from '../../../../../../plugins/cases/common/api';
import {
secOnly,
obsOnlyRead,
Expand All @@ -39,17 +32,9 @@ export default ({ getService }: FtrProviderContext): void => {
const supertest = getService('supertest');
const supertestWithoutAuth = getService('supertestWithoutAuth');
const es = getService('es');
const kibanaServer = getService('kibanaServer');

describe('patch_configure', () => {
const actionsRemover = new ActionsRemover(supertest);
let servicenowSimulatorURL: string = '<could not determine kibana url>';

before(() => {
servicenowSimulatorURL = kibanaServer.resolveUrl(
getExternalServiceSimulatorPath(ExternalServiceSimulator.SERVICENOW)
);
});

afterEach(async () => {
await deleteConfiguration(es);
Expand All @@ -67,119 +52,6 @@ export default ({ getService }: FtrProviderContext): void => {
expect(data).to.eql({ ...getConfigurationOutput(true), closure_type: 'close-by-pushing' });
});

it('should patch a configuration connector and create mappings', async () => {
const connector = await createConnector(supertest, {
...getServiceNowConnector(),
config: { apiUrl: servicenowSimulatorURL },
});

actionsRemover.add('default', connector.id, 'action', 'actions');

// Configuration is created with no connector so the mappings are empty
const configuration = await createConfiguration(supertest);

// the update request doesn't accept the owner field
const { owner, ...reqWithoutOwner } = getConfigurationRequest({
id: connector.id,
name: connector.name,
type: connector.connector_type_id as ConnectorTypes,
fields: null,
});

const newConfiguration = await updateConfiguration(supertest, configuration.id, {
...reqWithoutOwner,
version: configuration.version,
});

const data = removeServerGeneratedPropertiesFromSavedObject(newConfiguration);
expect(data).to.eql({
...getConfigurationOutput(true),
connector: {
id: connector.id,
name: connector.name,
type: connector.connector_type_id as ConnectorTypes,
fields: null,
},
mappings: [
{
action_type: 'overwrite',
source: 'title',
target: 'short_description',
},
{
action_type: 'overwrite',
source: 'description',
target: 'description',
},
{
action_type: 'append',
source: 'comments',
target: 'work_notes',
},
],
});
});

it('should mappings when updating the connector', async () => {
const connector = await createConnector(supertest, {
...getServiceNowConnector(),
config: { apiUrl: servicenowSimulatorURL },
});

actionsRemover.add('default', connector.id, 'action', 'actions');

// Configuration is created with connector so the mappings are created
const configuration = await createConfiguration(
supertest,
getConfigurationRequest({
id: connector.id,
name: connector.name,
type: connector.connector_type_id as ConnectorTypes,
})
);

// the update request doesn't accept the owner field
const { owner, ...rest } = getConfigurationRequest({
id: connector.id,
name: 'New name',
type: connector.connector_type_id as ConnectorTypes,
fields: null,
});

const newConfiguration = await updateConfiguration(supertest, configuration.id, {
...rest,
version: configuration.version,
});

const data = removeServerGeneratedPropertiesFromSavedObject(newConfiguration);
expect(data).to.eql({
...getConfigurationOutput(true),
connector: {
id: connector.id,
name: 'New name',
type: connector.connector_type_id as ConnectorTypes,
fields: null,
},
mappings: [
{
action_type: 'overwrite',
source: 'title',
target: 'short_description',
},
{
action_type: 'overwrite',
source: 'description',
target: 'description',
},
{
action_type: 'append',
source: 'comments',
target: 'work_notes',
},
],
});
});

it('should not patch a configuration with unsupported connector type', async () => {
const configuration = await createConfiguration(supertest);
await updateConfiguration(
Expand Down
Loading

0 comments on commit 518db99

Please sign in to comment.