mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[ResponseOps][Actions] Getting error about secrets not being saved when import a SO (Connector Saved Object) (#138019)
* Adding transform function to add secrets if needed * Adding functional tests and updating transform * Removing duplicate validation * Adding secrets to everything Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
9452be575e
commit
3ef3614197
3 changed files with 81 additions and 16 deletions
|
@ -240,7 +240,13 @@ describe('transform connector for export', () => {
|
|||
|
||||
it('should not change connectors without secrets', () => {
|
||||
expect(transformConnectorsForExport(connectorsWithNoSecrets, actionTypeRegistry)).toEqual(
|
||||
connectorsWithNoSecrets
|
||||
connectorsWithNoSecrets.map((connector) => ({
|
||||
...connector,
|
||||
attributes: {
|
||||
...connector.attributes,
|
||||
secrets: {},
|
||||
},
|
||||
}))
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -250,6 +256,7 @@ describe('transform connector for export', () => {
|
|||
...connector,
|
||||
attributes: {
|
||||
...connector.attributes,
|
||||
secrets: {},
|
||||
isMissingSecrets: true,
|
||||
},
|
||||
}))
|
||||
|
|
|
@ -28,6 +28,7 @@ function transformConnectorForExport(
|
|||
actionType: ActionType
|
||||
): SavedObject<RawAction> {
|
||||
let isMissingSecrets = false;
|
||||
|
||||
try {
|
||||
// If connector requires secrets, this will throw an error
|
||||
validateSecrets(actionType, {});
|
||||
|
@ -39,11 +40,11 @@ function transformConnectorForExport(
|
|||
isMissingSecrets = true;
|
||||
}
|
||||
|
||||
// Skip connectors
|
||||
return {
|
||||
...connector,
|
||||
attributes: {
|
||||
...connector.attributes,
|
||||
secrets: {},
|
||||
isMissingSecrets,
|
||||
},
|
||||
};
|
||||
|
|
|
@ -89,6 +89,33 @@ export default function emailTest({ getService }: FtrProviderContext) {
|
|||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('export, import, then execute email connector', () => {
|
||||
afterEach(() => objectRemover.removeAll());
|
||||
|
||||
it('successfully executes with no auth', async () => {
|
||||
const from = `bob@${EmailDomainAllowed}`;
|
||||
const conn = await createConnector(from, false);
|
||||
expect(conn.status).to.be(200);
|
||||
const { id } = conn.body;
|
||||
|
||||
const text = await exportConnector(id);
|
||||
|
||||
const { body } = await importConnector(text);
|
||||
const importId = body.successResults[0].id;
|
||||
|
||||
const to = EmailDomainsAllowed.map((domain) => `jeb@${domain}`).sort();
|
||||
const cc = EmailDomainsAllowed.map((domain) => `jim@${domain}`).sort();
|
||||
const bcc = EmailDomainsAllowed.map((domain) => `joe@${domain}`).sort();
|
||||
const ccNames = cc.map((email) => `Jimmy Jack <${email}>`);
|
||||
const run = await runConnector(importId, to, ccNames, bcc);
|
||||
|
||||
expect(run.status).to.be(200);
|
||||
|
||||
const { status } = run.body || {};
|
||||
expect(status).to.be('ok');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/* returns the following `body`, for the special email __json service:
|
||||
|
@ -111,23 +138,29 @@ export default function emailTest({ getService }: FtrProviderContext) {
|
|||
...
|
||||
}
|
||||
*/
|
||||
async function createConnector(from: string): Promise<{ status: number; body: any }> {
|
||||
async function createConnector(
|
||||
from: string,
|
||||
hasAuth: boolean = true
|
||||
): Promise<{ status: number; body: any }> {
|
||||
const connector: any = {
|
||||
name: `An email connector from ${__filename}`,
|
||||
connector_type_id: '.email',
|
||||
config: {
|
||||
service: '__json',
|
||||
from,
|
||||
hasAuth,
|
||||
},
|
||||
};
|
||||
if (hasAuth) {
|
||||
connector.secrets = {
|
||||
user: 'bob',
|
||||
password: 'changeme',
|
||||
};
|
||||
}
|
||||
const { status, body } = await supertest
|
||||
.post('/api/actions/connector')
|
||||
.set('kbn-xsrf', 'foo')
|
||||
.send({
|
||||
name: `An email connector from ${__filename}`,
|
||||
connector_type_id: '.email',
|
||||
config: {
|
||||
service: '__json',
|
||||
from,
|
||||
hasAuth: true,
|
||||
},
|
||||
secrets: {
|
||||
user: 'bob',
|
||||
password: 'changeme',
|
||||
},
|
||||
});
|
||||
.send(connector);
|
||||
|
||||
if (status === 200) {
|
||||
objectRemover.add('default', body.id, 'connector', 'actions');
|
||||
|
@ -151,6 +184,30 @@ export default function emailTest({ getService }: FtrProviderContext) {
|
|||
|
||||
return { status, body };
|
||||
}
|
||||
|
||||
async function exportConnector(id: string) {
|
||||
const { text } = await supertest
|
||||
.post(`/api/saved_objects/_export`)
|
||||
.send({
|
||||
objects: [
|
||||
{
|
||||
id,
|
||||
type: 'action',
|
||||
},
|
||||
],
|
||||
includeReferencesDeep: true,
|
||||
})
|
||||
.set('kbn-xsrf', 'true');
|
||||
return text;
|
||||
}
|
||||
|
||||
async function importConnector(text: any) {
|
||||
return await supertest
|
||||
.post('/api/saved_objects/_import')
|
||||
.query({ overwrite: true })
|
||||
.attach('file', Buffer.from(text), 'actions.ndjson')
|
||||
.set('kbn-xsrf', 'true');
|
||||
}
|
||||
}
|
||||
|
||||
function addressesFromMessage(message: any, which: 'to' | 'cc' | 'bcc'): string[] {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue