Use the getBasicAuthHeader util function for Webhook

This commit is contained in:
Christos Nasikas 2024-05-10 22:25:07 +03:00
parent b10d103bd9
commit 1a62c77d46
2 changed files with 10 additions and 6 deletions

View file

@ -348,13 +348,10 @@ describe('execute()', () => {
delete requestMock.mock.calls[0][0].configurationUtilities;
expect(requestMock.mock.calls[0][0]).toMatchInlineSnapshot(`
Object {
"auth": Object {
"password": "123",
"username": "abc",
},
"axios": undefined,
"data": "some data",
"headers": Object {
"Authorization": "Basic YWJjOjEyMw==",
"aheader": "a value",
},
"logger": Object {

View file

@ -25,6 +25,7 @@ import {
SecurityConnectorFeatureId,
} from '@kbn/actions-plugin/common/types';
import { renderMustacheString } from '@kbn/actions-plugin/server/lib/mustache_renderer';
import { combineHeadersWithBasicAuthHeader } from '@kbn/actions-plugin/server/lib';
import { SSLCertType, WebhookAuthType } from '../../../common/webhook/constants';
import { getRetryAfterIntervalFromHeaders } from '../lib/http_response_retry_header';
import { nullableType } from '../lib/nullable';
@ -210,6 +211,7 @@ export async function executor(
isString(secrets.password)
? { auth: { username: secrets.user, password: secrets.password } }
: {};
const sslCertificate =
authType === WebhookAuthType.SSL &&
((isString(secrets.crt) && isString(secrets.key)) || isString(secrets.pfx))
@ -233,14 +235,19 @@ export async function executor(
...(ca ? { ca: Buffer.from(ca, 'base64') } : {}),
};
const headersWithBasicAuth = combineHeadersWithBasicAuthHeader({
username: basicAuth.auth?.username,
password: basicAuth.auth?.password,
headers,
});
const result: Result<AxiosResponse, AxiosError<{ message: string }>> = await promiseResult(
request({
axios: axiosInstance,
method,
url,
logger,
...basicAuth,
headers: headers ? headers : {},
headers: headersWithBasicAuth,
data,
configurationUtilities,
sslOverrides,