From 06f609cff0f6153ef6324bf1732f9d6cae8a73dd Mon Sep 17 00:00:00 2001 From: YulNaumenko Date: Mon, 25 Oct 2021 12:42:06 -0700 Subject: [PATCH] added tests --- .../server/builtin_action_types/email.test.ts | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/x-pack/plugins/actions/server/builtin_action_types/email.test.ts b/x-pack/plugins/actions/server/builtin_action_types/email.test.ts index 31b68eff7ff62..429cebcc67e6d 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/email.test.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/email.test.ts @@ -303,6 +303,76 @@ describe('secrets validation', () => { }); }); +describe('connector validation: secrets with config', () => { + test('connector validation succeeds when username/password was populated for hasAuth true', () => { + const secrets: Record = { + user: 'bob', + password: 'supersecret', + }; + const config: Record = { + hasAuth: true, + }; + expect(validateConnector(actionType, { config, secrets })).toEqual({ ...secrets, clientSecret: null }); + }); + + test('connector validation succeeds when username/password not filled for hasAuth false', () => { + const secrets: Record = { + user: null, + password: null, + clientSecret: null, + }; + const config: Record = { + hasAuth: false, + }; + expect(validateConnector(actionType, { config: {}, secrets: {} })).toEqual(secrets); + expect(validateConnector(actionType, { config: {}, secrets: { user: null }})).toEqual(secrets); + expect(validateConnector(actionType, { config: {}, secrets:{ password: null }})).toEqual(secrets); + }); + + test('connector validation fails when username/password was populated for hasAuth true', () => { + const secrets: Record = { + password: null, + user: null, + }; + const config: Record = { + hasAuth: true, + }; + expect(validateConnector(actionType, { config, secrets })).toEqual({ + ...secrets, + user: null, + password: null, + }); + }); + + test('connector validation succeeds when service is exchange_server and clientSecret is populated', () => { + const secrets: Record = { + clientSecret: '12345678', + }; + const config: Record = { + service: 'exchange_server', + }; + expect(validateConnector(actionType, { config, secrets })).toEqual({ + ...secrets, + user: null, + password: null, + }); + }); + + test('connector validation fails when service is exchange_server and clientSecret is not populated', () => { + const secrets: Record = { + clientSecret: '12345678', + }; + const config: Record = { + service: 'exchange_server', + }; + expect(validateConnector(actionType, { config, secrets })).toEqual({ + ...secrets, + user: null, + password: null, + }); + }); +}); + describe('params validation', () => { test('params validation succeeds when params is valid', () => { const params: Record = {