mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Use the getBasicAuthHeader util function for xMatter
This commit is contained in:
parent
104f881251
commit
ea7be2bbee
2 changed files with 36 additions and 19 deletions
|
@ -5,11 +5,7 @@
|
||||||
* 2.0.
|
* 2.0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
jest.mock('./post_xmatters', () => ({
|
import axios from 'axios';
|
||||||
postXmatters: jest.fn(),
|
|
||||||
}));
|
|
||||||
import { postXmatters } from './post_xmatters';
|
|
||||||
|
|
||||||
import { Logger } from '@kbn/core/server';
|
import { Logger } from '@kbn/core/server';
|
||||||
import {
|
import {
|
||||||
ConnectorTypeConfigType,
|
ConnectorTypeConfigType,
|
||||||
|
@ -28,8 +24,22 @@ import {
|
||||||
import { actionsConfigMock } from '@kbn/actions-plugin/server/actions_config.mock';
|
import { actionsConfigMock } from '@kbn/actions-plugin/server/actions_config.mock';
|
||||||
import { ActionsConfigurationUtilities } from '@kbn/actions-plugin/server/actions_config';
|
import { ActionsConfigurationUtilities } from '@kbn/actions-plugin/server/actions_config';
|
||||||
import { loggerMock } from '@kbn/logging-mocks';
|
import { loggerMock } from '@kbn/logging-mocks';
|
||||||
|
import * as utils from '@kbn/actions-plugin/server/lib/axios_utils';
|
||||||
|
|
||||||
|
jest.mock('axios');
|
||||||
|
jest.mock('@kbn/actions-plugin/server/lib/axios_utils', () => {
|
||||||
|
const originalUtils = jest.requireActual('@kbn/actions-plugin/server/lib/axios_utils');
|
||||||
|
return {
|
||||||
|
...originalUtils,
|
||||||
|
request: jest.fn(),
|
||||||
|
patch: jest.fn(),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
axios.create = jest.fn(() => axios);
|
||||||
|
const requestMock = utils.request as jest.Mock;
|
||||||
|
axios.create = jest.fn(() => axios);
|
||||||
|
|
||||||
const postxMattersMock = postXmatters as jest.Mock;
|
|
||||||
const services: Services = actionsMock.createServices();
|
const services: Services = actionsMock.createServices();
|
||||||
const mockedLogger: jest.Mocked<Logger> = loggerMock.create();
|
const mockedLogger: jest.Mocked<Logger> = loggerMock.create();
|
||||||
|
|
||||||
|
@ -383,8 +393,8 @@ describe('connector validation', () => {
|
||||||
|
|
||||||
describe('execute()', () => {
|
describe('execute()', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
postxMattersMock.mockReset();
|
requestMock.mockReset();
|
||||||
postxMattersMock.mockResolvedValue({
|
requestMock.mockResolvedValue({
|
||||||
status: 200,
|
status: 200,
|
||||||
statusText: '',
|
statusText: '',
|
||||||
data: '',
|
data: '',
|
||||||
|
@ -415,14 +425,10 @@ describe('execute()', () => {
|
||||||
logger: mockedLogger,
|
logger: mockedLogger,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(postxMattersMock.mock.calls[0][0]).toMatchInlineSnapshot(`
|
const { method, url, headers, data } = requestMock.mock.calls[0][0];
|
||||||
|
|
||||||
|
expect({ method, url, headers, data }).toMatchInlineSnapshot(`
|
||||||
Object {
|
Object {
|
||||||
"basicAuth": Object {
|
|
||||||
"auth": Object {
|
|
||||||
"password": "123",
|
|
||||||
"username": "abc",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"data": Object {
|
"data": Object {
|
||||||
"alertActionGroupName": "Small t-shirt",
|
"alertActionGroupName": "Small t-shirt",
|
||||||
"date": "2022-01-18T19:01:08.818Z",
|
"date": "2022-01-18T19:01:08.818Z",
|
||||||
|
@ -432,6 +438,10 @@ describe('execute()', () => {
|
||||||
"spaceId": "default",
|
"spaceId": "default",
|
||||||
"tags": "test1, test2",
|
"tags": "test1, test2",
|
||||||
},
|
},
|
||||||
|
"headers": Object {
|
||||||
|
"Authorization": "Basic YWJjOjEyMw==",
|
||||||
|
},
|
||||||
|
"method": "post",
|
||||||
"url": "https://abc.def/my-xmatters",
|
"url": "https://abc.def/my-xmatters",
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
|
@ -442,7 +452,7 @@ describe('execute()', () => {
|
||||||
configUrl: 'https://abc.def/my-xmatters',
|
configUrl: 'https://abc.def/my-xmatters',
|
||||||
usesBasic: true,
|
usesBasic: true,
|
||||||
};
|
};
|
||||||
postxMattersMock.mockRejectedValueOnce({
|
requestMock.mockRejectedValueOnce({
|
||||||
tag: 'err',
|
tag: 'err',
|
||||||
message: 'maxContentLength size of 1000000 exceeded',
|
message: 'maxContentLength size of 1000000 exceeded',
|
||||||
});
|
});
|
||||||
|
@ -496,9 +506,10 @@ describe('execute()', () => {
|
||||||
logger: mockedLogger,
|
logger: mockedLogger,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(postxMattersMock.mock.calls[0][0]).toMatchInlineSnapshot(`
|
const { method, url, headers, data } = requestMock.mock.calls[0][0];
|
||||||
|
|
||||||
|
expect({ method, url, headers, data }).toMatchInlineSnapshot(`
|
||||||
Object {
|
Object {
|
||||||
"basicAuth": undefined,
|
|
||||||
"data": Object {
|
"data": Object {
|
||||||
"alertActionGroupName": "Small t-shirt",
|
"alertActionGroupName": "Small t-shirt",
|
||||||
"date": "2022-01-18T19:01:08.818Z",
|
"date": "2022-01-18T19:01:08.818Z",
|
||||||
|
@ -508,6 +519,8 @@ describe('execute()', () => {
|
||||||
"spaceId": "default",
|
"spaceId": "default",
|
||||||
"tags": "test1, test2",
|
"tags": "test1, test2",
|
||||||
},
|
},
|
||||||
|
"headers": undefined,
|
||||||
|
"method": "post",
|
||||||
"url": "https://abc.def/my-xmatters?apiKey=someKey",
|
"url": "https://abc.def/my-xmatters?apiKey=someKey",
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
|
|
|
@ -9,6 +9,7 @@ import axios, { AxiosResponse } from 'axios';
|
||||||
import { Logger } from '@kbn/core/server';
|
import { Logger } from '@kbn/core/server';
|
||||||
import { ActionsConfigurationUtilities } from '@kbn/actions-plugin/server/actions_config';
|
import { ActionsConfigurationUtilities } from '@kbn/actions-plugin/server/actions_config';
|
||||||
import { request } from '@kbn/actions-plugin/server/lib/axios_utils';
|
import { request } from '@kbn/actions-plugin/server/lib/axios_utils';
|
||||||
|
import { combineHeadersWithBasicAuthHeader } from '@kbn/actions-plugin/server/lib';
|
||||||
|
|
||||||
interface PostXmattersOptions {
|
interface PostXmattersOptions {
|
||||||
url: string;
|
url: string;
|
||||||
|
@ -42,7 +43,10 @@ export async function postXmatters(
|
||||||
method: 'post',
|
method: 'post',
|
||||||
url,
|
url,
|
||||||
logger,
|
logger,
|
||||||
...basicAuth,
|
headers: combineHeadersWithBasicAuthHeader({
|
||||||
|
username: basicAuth?.auth.username,
|
||||||
|
password: basicAuth?.auth.password,
|
||||||
|
}),
|
||||||
data,
|
data,
|
||||||
configurationUtilities,
|
configurationUtilities,
|
||||||
validateStatus: () => true,
|
validateStatus: () => true,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue