Skip to content

Commit

Permalink
[7.17] Upgrade axios dependency (0.21.10.27.2). (#111655) (#…
Browse files Browse the repository at this point in the history
…132110)

* Upgrade `axios` dependency (`0.21.1` → `0.27.2`). (#111655)

Co-authored-by: Aleh Zasypkin <aleh.zasypkin@elastic.co>
(cherry picked from commit b191f14)

# Conflicts:
#	packages/kbn-pm/dist/index.js
#	x-pack/plugins/actions/server/builtin_action_types/servicenow/utils.test.ts
#	x-pack/plugins/actions/server/builtin_action_types/servicenow/utils.ts
#	x-pack/plugins/fleet/server/telemetry/sender.ts
#	x-pack/plugins/osquery/server/lib/telemetry/sender.ts
#	x-pack/plugins/security_solution/scripts/endpoint/blocklists/index.ts
#	x-pack/plugins/security_solution/server/lib/telemetry/sender.ts
#	x-pack/plugins/synthetics/server/lib/telemetry/sender.ts
#	x-pack/test/performance/services/auth.ts
#	x-pack/test/ui_capabilities/common/services/ui_capabilities.ts
#	yarn.lock

* Update yarn.lock

Co-authored-by: Jonathan Budzenski <jon@elastic.co>
  • Loading branch information
azasypkin and jbudz authored May 12, 2022
1 parent 0d58f36 commit 52746c3
Show file tree
Hide file tree
Showing 13 changed files with 4,316 additions and 2,071 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
"abortcontroller-polyfill": "^1.7.3",
"antlr4ts": "^0.5.0-alpha.3",
"archiver": "^5.2.0",
"axios": "^0.21.1",
"axios": "^0.27.2",
"base64-js": "^1.3.1",
"bluebird": "3.5.5",
"brace": "0.11.1",
Expand Down Expand Up @@ -830,7 +830,6 @@
"url-loader": "^2.2.0",
"val-loader": "^1.1.1",
"vinyl-fs": "^3.0.3",
"wait-on": "^5.2.1",
"watchpack": "^1.6.0",
"webpack": "^4.41.5",
"webpack-cli": "^3.3.12",
Expand Down
6,300 changes: 4,271 additions & 2,029 deletions packages/kbn-pm/dist/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/dev/build/lib/integration_tests/download.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ describe('downloadToDisk', () => {
retryDelaySecMultiplier: 0.1,
});
await expect(promise).rejects.toMatchInlineSnapshot(
`[Error: Request failed with status code 500]`
`[AxiosError: Request failed with status code 500]`
);
expect(logWritter.messages).toMatchInlineSnapshot(`
Array [
Expand Down Expand Up @@ -263,7 +263,7 @@ describe('downloadToString', () => {
maxAttempts: 1,
});
await expect(promise).rejects.toMatchInlineSnapshot(
`[Error: Request failed with status code 200]`
`[AxiosError: Request failed with status code 200]`
);
expect(logWritter.messages).toMatchInlineSnapshot(`
Array [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const request = async <T = unknown>({
method = 'get',
data,
configurationUtilities,
headers,
...rest
}: {
axios: AxiosInstance;
Expand All @@ -37,6 +38,8 @@ export const request = async <T = unknown>({
return await axios(url, {
...rest,
method,
// Axios doesn't support `null` value for `headers` property.
headers: headers ?? undefined,
data: data ?? {},
// use httpAgent and httpsAgent and set axios proxy: false, to be able to handle fail on invalid certs
httpAgent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* 2.0.
*/

import { AxiosError } from 'axios';

import { Logger } from '../../../../../../src/core/server';
import { loggingSystemMock } from '../../../../../../src/core/server/mocks';
import {
Expand All @@ -15,6 +13,7 @@ import {
getPushedDate,
throwIfSubActionIsNotSupported,
} from './utils';
import type { ResponseError } from './types';

const logger = loggingSystemMock.create().get() as jest.Mocked<Logger>;

Expand Down Expand Up @@ -53,7 +52,7 @@ describe('utils', () => {
const axiosError = {
message: 'An error occurred',
response: { data: { error: { message: 'Denied', detail: 'no access' } } },
} as AxiosError;
} as ResponseError;

expect(createServiceError(axiosError, 'Unable to do action').message).toBe(
'[Action][ServiceNow]: Unable to do action. Error: An error occurred Reason: Denied: no access'
Expand All @@ -64,7 +63,7 @@ describe('utils', () => {
const axiosError = {
message: 'An error occurred',
response: { data: { error: null } },
} as AxiosError;
} as ResponseError;

expect(createServiceError(axiosError, 'Unable to do action').message).toBe(
'[Action][ServiceNow]: Unable to do action. Error: An error occurred Reason: unknown: no error in error response'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export async function executor(

const axiosInstance = axios.create();

const result: Result<AxiosResponse, AxiosError> = await promiseResult(
const result: Result<AxiosResponse, AxiosError<{ message: string }>> = await promiseResult(
request({
axios: axiosInstance,
method,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const getBaseUrl = once(async (kibanaHostname: string) => {
await axios.request({ url: kibanaHostname, maxRedirects: 0 });
} catch (e) {
if (isAxiosError(e)) {
const location = e.response?.headers?.location;
const location = e.response?.headers?.location ?? '';
const hasBasePath = RegExp(/^\/\w{3}$/).test(location);
const basePath = hasBasePath ? location : '';
return `${kibanaHostname}${basePath}`;
Expand Down
17 changes: 11 additions & 6 deletions x-pack/plugins/canvas/common/lib/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@
*/

import { fetch, arrayBufferFetch } from './fetch';
import { AxiosInstance, HeadersDefaults } from 'axios';

describe('fetch', () => {
// WORKAROUND: wrong Axios types, should be fixed in https://github.com/axios/axios/pull/4475
const getDefaultHeader = (axiosInstance: AxiosInstance, headerName: string) =>
(axiosInstance.defaults.headers as HeadersDefaults & Record<string, string>)[headerName];

it('test fetch headers', () => {
expect(fetch.defaults.headers.Accept).toBe('application/json');
expect(fetch.defaults.headers['Content-Type']).toBe('application/json');
expect(fetch.defaults.headers['kbn-xsrf']).toBe('professionally-crafted-string-of-text');
expect(getDefaultHeader(fetch, 'Accept')).toBe('application/json');
expect(getDefaultHeader(fetch, 'Content-Type')).toBe('application/json');
expect(getDefaultHeader(fetch, 'kbn-xsrf')).toBe('professionally-crafted-string-of-text');
});

it('test arrayBufferFetch headers', () => {
expect(arrayBufferFetch.defaults.headers.Accept).toBe('application/json');
expect(arrayBufferFetch.defaults.headers['Content-Type']).toBe('application/json');
expect(arrayBufferFetch.defaults.headers['kbn-xsrf']).toBe(
expect(getDefaultHeader(arrayBufferFetch, 'Accept')).toBe('application/json');
expect(getDefaultHeader(arrayBufferFetch, 'Content-Type')).toBe('application/json');
expect(getDefaultHeader(arrayBufferFetch, 'kbn-xsrf')).toBe(
'professionally-crafted-string-of-text'
);
expect(arrayBufferFetch.defaults.responseType).toBe('arraybuffer');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class EventFilterDataLoaderError extends Error {
}
}

const handleThrowAxiosHttpError = (err: AxiosError): never => {
const handleThrowAxiosHttpError = (err: AxiosError<{ message?: string }>): never => {
let message = err.message;

if (err.response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class EventFilterDataLoaderError extends Error {
}
}

const handleThrowAxiosHttpError = (err: AxiosError): never => {
const handleThrowAxiosHttpError = (err: AxiosError<{ message?: string }>): never => {
let message = err.message;

if (err.response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ export class TelemetryEventsSender {
const resp = await axios.post(telemetryUrl, ndjson, {
headers: {
'Content-Type': 'application/x-ndjson',
'X-Elastic-Cluster-ID': clusterUuid,
'X-Elastic-Cluster-Name': clusterName,
...(clusterUuid ? { 'X-Elastic-Cluster-ID': clusterUuid } : undefined),
...(clusterName ? { 'X-Elastic-Cluster-Name': clusterName } : undefined),
'X-Elastic-Stack-Version': clusterVersionNumber ? clusterVersionNumber : '7.10.0',
...(licenseId ? { 'X-Elastic-License-ID': licenseId } : {}),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import axios, { AxiosInstance } from 'axios';
import axios, { AxiosInstance, AxiosRequestHeaders } from 'axios';
import type { Capabilities as UICapabilities } from 'src/core/types';
import { format as formatUrl } from 'url';
import util from 'util';
Expand Down Expand Up @@ -61,7 +61,7 @@ export class UICapabilitiesService {
this.log.debug(
`requesting ${spaceUrlPrefix}/api/core/capabilities to parse the uiCapabilities`
);
const requestHeaders = credentials
const requestHeaders: AxiosRequestHeaders = credentials
? {
Authorization: `Basic ${Buffer.from(
`${credentials.username}:${credentials.password}`
Expand Down
37 changes: 17 additions & 20 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8032,11 +8032,11 @@ axe-core@^4.2.0:
integrity sha512-WKTW1+xAzhMS5dJsxWkliixlO/PqC4VhmO9T4juNYcaTg9jzWiJsou6m5pxWYGfigWbwzJWeFY6z47a+4neRXA==

axios@^0.21.1:
version "0.21.1"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8"
integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==
version "0.21.4"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.4.tgz#c67b90dc0568e5c1cf2b0b858c43ba28e2eda575"
integrity sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==
dependencies:
follow-redirects "^1.10.0"
follow-redirects "^1.14.0"

axios@^0.24.0:
version "0.24.0"
Expand All @@ -8045,6 +8045,14 @@ axios@^0.24.0:
dependencies:
follow-redirects "^1.14.4"

axios@^0.27.2:
version "0.27.2"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972"
integrity sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==
dependencies:
follow-redirects "^1.14.9"
form-data "^4.0.0"

axobject-query@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-2.2.0.tgz#943d47e10c0b704aa42275e20edf3722648989be"
Expand Down Expand Up @@ -14170,10 +14178,10 @@ follow-redirects@1.12.1:
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.12.1.tgz#de54a6205311b93d60398ebc01cf7015682312b6"
integrity sha512-tmRv0AVuR7ZyouUHLeNSiO6pqulF7dYa3s19c6t+wz9LD69/uSzdMxJ2S91nTI9U3rt/IldxpzMOFejp6f0hjg==

follow-redirects@^1.0.0, follow-redirects@^1.10.0, follow-redirects@^1.14.4:
version "1.14.9"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.9.tgz#dd4ea157de7bfaf9ea9b3fbd85aa16951f78d8d7"
integrity sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==
follow-redirects@^1.0.0, follow-redirects@^1.14.0, follow-redirects@^1.14.4, follow-redirects@^1.14.9:
version "1.15.0"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.0.tgz#06441868281c86d0dda4ad8bdaead2d02dca89d4"
integrity sha512-aExlJShTV4qOUOL7yF1U5tvLCB0xQuudbf6toyYA0E/acBNw71mvjFTnLaRp50aQaYocMR0a/RMMBIHeZnGyjQ==

font-awesome@4.7.0:
version "4.7.0"
Expand Down Expand Up @@ -24972,7 +24980,7 @@ rxjs-marbles@^5.0.6:
dependencies:
fast-equals "^2.0.0"

rxjs@^6.3.3, rxjs@^6.4.0, rxjs@^6.5.1, rxjs@^6.5.5, rxjs@^6.6.0, rxjs@^6.6.3:
rxjs@^6.3.3, rxjs@^6.4.0, rxjs@^6.5.1, rxjs@^6.5.5, rxjs@^6.6.0:
version "6.6.3"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.6.3.tgz#8ca84635c4daa900c0d3967a6ee7ac60271ee552"
integrity sha512-trsQc+xYYXZ3urjOiJOuCOa5N3jAZ3eiSpQB5hIT8zGlL2QfnHLJ2r7GMkBGuIausdJN1OneaI6gQlsqNHHmZQ==
Expand Down Expand Up @@ -29220,17 +29228,6 @@ w3c-xmlserializer@^2.0.0:
dependencies:
xml-name-validator "^3.0.0"

wait-on@^5.2.1:
version "5.2.1"
resolved "https://registry.yarnpkg.com/wait-on/-/wait-on-5.2.1.tgz#05b66fcb4d7f5da01537f03e7cf96e8836422996"
integrity sha512-H2F986kNWMU9hKlI9l/ppO6tN8ZSJd35yBljMLa1/vjzWP++Qh6aXyt77/u7ySJFZQqBtQxnvm/xgG48AObXcw==
dependencies:
axios "^0.21.1"
joi "^17.3.0"
lodash "^4.17.20"
minimist "^1.2.5"
rxjs "^6.6.3"

walk@^2.3.14:
version "2.3.14"
resolved "https://registry.yarnpkg.com/walk/-/walk-2.3.14.tgz#60ec8631cfd23276ae1e7363ce11d626452e1ef3"
Expand Down

0 comments on commit 52746c3

Please sign in to comment.