Skip to content

Commit acacdb8

Browse files
committed
- Upgrade axios package to fix CVE
- Remove axios-mock package Signed-off-by: Ian Bolton <[email protected]>
1 parent 6b23d48 commit acacdb8

File tree

11 files changed

+138
-159
lines changed

11 files changed

+138
-159
lines changed

client/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"@react-keycloak/web": "^3.4.0",
3535
"@tanstack/react-query": "^4.22.0",
3636
"@tanstack/react-query-devtools": "^4.22.0",
37-
"axios": "^0.21.2",
37+
"axios": "^1.6.8",
3838
"dayjs": "^1.11.7",
3939
"ejs": "^3.1.7",
4040
"fast-xml-parser": "^4.0.3",
@@ -71,7 +71,6 @@
7171
"@types/react-measure": "^2.0.12",
7272
"@types/react-router-dom": "^5.1.7",
7373
"@types/tinycolor2": "^1.4.6",
74-
"axios-mock-adapter": "^1.19.0",
7574
"browserslist": "^4.19.1",
7675
"case-sensitive-paths-webpack-plugin": "^2.4.0",
7776
"copy-webpack-plugin": "^12.0.2",

client/src/app/api/rest.ts

+20-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// hub OpenAPI definition: https://github.com/konveyor/tackle2-hub/blob/main/docs/openapi3.json
2-
3-
import axios, { AxiosPromise } from "axios";
1+
import axios, { AxiosPromise, RawAxiosRequestHeaders } from "axios";
42

53
import {
64
AnalysisDependency,
@@ -107,14 +105,18 @@ export const QUESTIONNAIRES = HUB + "/questionnaires";
107105

108106
export const ARCHETYPES = HUB + "/archetypes";
109107

110-
// PATHFINDER
111-
export const PATHFINDER = "/hub/pathfinder";
112108
export const ASSESSMENTS = HUB + "/assessments";
113109

114-
const jsonHeaders = { headers: { Accept: "application/json" } };
115-
const formHeaders = { headers: { Accept: "multipart/form-data" } };
116-
const fileHeaders = { headers: { Accept: "application/json" } };
117-
const yamlHeaders = { headers: { Accept: "application/x-yaml" } };
110+
const jsonHeaders: RawAxiosRequestHeaders = {
111+
Accept: "application/json",
112+
};
113+
const formHeaders: RawAxiosRequestHeaders = {
114+
Accept: "multipart/form-data",
115+
};
116+
const fileHeaders: RawAxiosRequestHeaders = { Accept: "application/json" };
117+
const yamlHeaders: RawAxiosRequestHeaders = {
118+
Accept: "application/x-yaml",
119+
};
118120

119121
type Direction = "asc" | "desc";
120122

@@ -137,7 +139,7 @@ export const getApplicationDependencies = (
137139
return axios
138140
.get(`${APPLICATION_DEPENDENCY}`, {
139141
params,
140-
headers: jsonHeaders.headers,
142+
headers: jsonHeaders,
141143
})
142144
.then((response) => response.data);
143145
};
@@ -243,7 +245,7 @@ export const deleteAssessment = (id: number) => {
243245
};
244246

245247
export const getIdentities = () => {
246-
return axios.get<Identity[]>(`${IDENTITIES}`, jsonHeaders);
248+
return axios.get<Identity[]>(`${IDENTITIES}`, { headers: jsonHeaders });
247249
};
248250

249251
export const createIdentity = (obj: New<Identity>) => {
@@ -322,8 +324,7 @@ export function getTaskById(
322324
format: string,
323325
merged: boolean = false
324326
): Promise<Task | string> {
325-
const headers =
326-
format === "yaml" ? { ...yamlHeaders.headers } : { ...jsonHeaders.headers };
327+
const headers = format === "yaml" ? { ...yamlHeaders } : { ...jsonHeaders };
327328
const responseType = format === "yaml" ? "text" : "json";
328329

329330
let url = `${TASKS}/${id}`;
@@ -371,11 +372,9 @@ export const uploadFileTaskgroup = ({
371372
formData: any;
372373
file: any;
373374
}) => {
374-
return axios.post<Taskgroup>(
375-
`${TASKGROUPS}/${id}/bucket/${path}`,
376-
formData,
377-
formHeaders
378-
);
375+
return axios.post<Taskgroup>(`${TASKGROUPS}/${id}/bucket/${path}`, formData, {
376+
headers: formHeaders,
377+
});
379378
};
380379

381380
export const removeFileTaskgroup = ({
@@ -430,7 +429,9 @@ export const createFile = ({
430429
file: IReadFile;
431430
}) =>
432431
axios
433-
.post<HubFile>(`${FILES}/${file.fileName}`, formData, fileHeaders)
432+
.post<HubFile>(`${FILES}/${file.fileName}`, formData, {
433+
headers: fileHeaders,
434+
})
434435
.then((response) => {
435436
return response.data;
436437
});

client/src/app/pages/applications/analysis-wizard/__tests__/analysis-wizard.test.tsx

+14-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ import React from "react";
22
import "@testing-library/jest-dom";
33
import { render, screen, waitFor } from "@app/test-config/test-utils";
44
import { AnalysisWizard } from "../analysis-wizard";
5-
import { TASKGROUPS } from "@app/api/rest";
6-
import mock from "@app/test-config/mockInstance";
75
import userEvent from "@testing-library/user-event";
8-
9-
mock.onAny().reply(200, []);
6+
import { server } from "@mocks/server";
7+
import { rest } from "msw";
108

119
const applicationData1 = {
1210
id: 1,
@@ -53,6 +51,13 @@ const taskgroupData = {
5351
};
5452

5553
describe("<AnalysisWizard />", () => {
54+
beforeEach(() => {
55+
jest.clearAllMocks();
56+
});
57+
afterEach(() => {
58+
server.resetHandlers();
59+
});
60+
5661
let isAnalyzeModalOpen = true;
5762
const setAnalyzeModalOpen = (toggle: boolean) =>
5863
(isAnalyzeModalOpen = toggle);
@@ -157,7 +162,11 @@ describe("<AnalysisWizard />", () => {
157162
},
158163
];
159164

160-
mock.onPost(`${TASKGROUPS}`).reply(200, taskgroupData);
165+
server.use(
166+
rest.get("/hub/taskgroups", (req, res, ctx) => {
167+
return res(ctx.json([taskgroupData]));
168+
})
169+
);
161170

162171
render(
163172
<AnalysisWizard

client/src/app/pages/applications/components/application-form/__tests__/application-form.test.tsx

+16-11
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,31 @@ import {
66
fireEvent,
77
} from "@app/test-config/test-utils";
88

9-
import { BUSINESS_SERVICES } from "@app/api/rest";
10-
import mock from "@app/test-config/mockInstance";
119
import userEvent from "@testing-library/user-event";
1210

1311
import "@testing-library/jest-dom";
14-
import { BusinessService } from "@app/api/models";
1512
import { ApplicationFormModal } from "../application-form-modal";
13+
import { server } from "@mocks/server";
14+
import { rest } from "msw";
1615

1716
describe("Component: application-form", () => {
1817
const mockChangeValue = jest.fn();
18+
beforeAll(() => server.listen({ onUnhandledRequest: "warn" }));
19+
afterAll(() => server.close());
20+
21+
beforeEach(() => {
22+
jest.clearAllMocks();
23+
});
24+
afterEach(() => {
25+
server.resetHandlers();
26+
});
27+
server.use(
28+
rest.get("/hub/businessservices", (req, res, ctx) => {
29+
return res(ctx.status(200), ctx.json([{ id: 1, name: "service" }]));
30+
})
31+
);
1932

2033
it("Validation tests", async () => {
21-
const businessServices: BusinessService[] = [{ id: 1, name: "service" }];
22-
23-
mock
24-
.onGet(`${BUSINESS_SERVICES}`)
25-
.reply(200, businessServices)
26-
.onAny()
27-
.reply(200, []);
28-
2934
render(
3035
<ApplicationFormModal application={null} onClose={mockChangeValue} />
3136
);

client/src/app/pages/controls/tags/tags.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export const Tags: React.FC = () => {
9191
const onDeleteTagError = (error: AxiosError) => {
9292
if (
9393
error.response?.status === 500 &&
94-
error.response?.data.error === "FOREIGN KEY constraint failed"
94+
error.message === "FOREIGN KEY constraint failed"
9595
) {
9696
pushNotification({
9797
title: "Cannot delete a used tag",
@@ -121,7 +121,7 @@ export const Tags: React.FC = () => {
121121
const onDeleteTagCategoryError = (error: AxiosError) => {
122122
if (
123123
error.response?.status === 500 &&
124-
error.response?.data.error === "FOREIGN KEY constraint failed"
124+
error.message === "FOREIGN KEY constraint failed"
125125
) {
126126
pushNotification({
127127
title: "Cannot delete a used tag",

client/src/app/pages/identities/components/identity-form/__tests__/identity-form.test.tsx

+15-8
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,25 @@ import {
66
fireEvent,
77
} from "@app/test-config/test-utils";
88

9-
import { IDENTITIES } from "@app/api/rest";
10-
import mock from "@app/test-config/mockInstance";
11-
129
import { IdentityForm } from "..";
1310
import "@testing-library/jest-dom";
11+
import { server } from "@mocks/server";
12+
import { rest } from "msw";
1413

15-
const data: any[] = [];
14+
describe("Component: identity-form", () => {
15+
beforeAll(() => server.listen({ onUnhandledRequest: "bypass" }));
1616

17-
mock.onGet(`${IDENTITIES}`).reply(200, data);
17+
afterEach(() => server.resetHandlers());
18+
afterAll(() => server.close());
1819

19-
describe("Component: identity-form", () => {
2020
const mockChangeValue = jest.fn();
21+
const data: any = [];
22+
23+
server.use(
24+
rest.get("*", (req, res, ctx) => {
25+
return res(ctx.json(data));
26+
})
27+
);
2128

2229
it("Display form on initial load", async () => {
2330
render(<IdentityForm onClose={mockChangeValue} />);
@@ -176,7 +183,7 @@ describe("Component: identity-form", () => {
176183
expect(createButton).toBeDisabled();
177184
});
178185

179-
it.skip("Identity form validation test - source - key upload", async () => {
186+
it("Identity form validation test - source - key upload", async () => {
180187
render(<IdentityForm onClose={mockChangeValue} />);
181188

182189
const identityNameInput = await screen.findByLabelText("Name *");
@@ -231,7 +238,7 @@ describe("Component: identity-form", () => {
231238
expect(createButton).toBeEnabled();
232239
});
233240

234-
it.skip("Identity form validation test - maven", async () => {
241+
it("Identity form validation test - maven", async () => {
235242
render(<IdentityForm onClose={mockChangeValue} xmlValidator={jest.fn()} />);
236243

237244
const identityNameInput = await screen.findByLabelText("Name *");

client/src/app/pages/proxies/__tests__/proxy-form.test.tsx

+49-49
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,38 @@ import {
88
} from "@app/test-config/test-utils";
99

1010
import { Proxies } from "../proxies";
11-
import MockAdapter from "axios-mock-adapter";
12-
import { IDENTITIES, PROXIES } from "@app/api/rest";
13-
import axios from "axios";
14-
import { Proxy, Identity } from "@app/api/models";
1511
import userEvent from "@testing-library/user-event";
16-
import { ProxyForm } from "../proxy-form";
17-
import mock from "@app/test-config/mockInstance";
18-
19-
const identitiesData: Identity[] = [];
20-
mock.onGet(`${IDENTITIES}`).reply(200, identitiesData);
21-
22-
const proxiesData = [
23-
{
24-
host: "",
25-
kind: "http",
26-
port: 0,
27-
excluded: [],
28-
identity: null,
29-
id: 1,
30-
enabled: false,
31-
},
32-
{
33-
host: "",
34-
kind: "https",
35-
port: 0,
36-
excluded: [],
37-
identity: null,
38-
id: 1,
39-
enabled: false,
40-
},
41-
];
42-
mock.onGet(`${PROXIES}`).reply(200, proxiesData);
12+
import { server } from "@mocks/server";
13+
import { rest } from "msw";
4314

4415
describe("Component: proxy-form", () => {
16+
beforeEach(() => {
17+
jest.clearAllMocks();
18+
});
19+
afterEach(() => {
20+
server.resetHandlers();
21+
});
22+
server.use(
23+
rest.get("/hub/identities", (req, res, ctx) => {
24+
return res(
25+
ctx.status(200),
26+
ctx.json([
27+
{ id: 0, name: "proxy-cred", kind: "proxy" },
28+
{ id: 1, name: "maven-cred", kind: "maven" },
29+
{ id: 2, name: "source-cred", kind: "source" },
30+
])
31+
);
32+
})
33+
);
34+
4535
it("Display switch statements on initial load", async () => {
4636
render(<Proxies />);
4737
await screen.findByLabelText("HTTP proxy");
4838

4939
await screen.findByLabelText("HTTPS proxy");
5040
});
5141

52-
it.skip("Show HTTP proxy form when switch button clicked", async () => {
42+
it("Show HTTP proxy form when switch button clicked", async () => {
5343
render(<Proxies />);
5444
const httpProxySwitch = await screen.findByLabelText("HTTP proxy");
5545

@@ -62,7 +52,7 @@ describe("Component: proxy-form", () => {
6252
);
6353
});
6454

65-
it.skip("Show HTTPS proxy form when switch button clicked", async () => {
55+
it("Show HTTPS proxy form when switch button clicked", async () => {
6656
render(<Proxies />);
6757
const httpsProxySwitch = await screen.findByLabelText("HTTPS proxy");
6858

@@ -75,14 +65,19 @@ describe("Component: proxy-form", () => {
7565
);
7666
});
7767

78-
it.skip("Select http proxy identity", async () => {
79-
const identitiesData: Identity[] = [
80-
{ id: 0, name: "proxy-cred", kind: "proxy" },
81-
{ id: 1, name: "maven-cred", kind: "maven" },
82-
{ id: 2, name: "source-cred", kind: "source" },
83-
];
84-
85-
mock.onGet(`${IDENTITIES}`).reply(200, identitiesData);
68+
it("Select http proxy identity", async () => {
69+
server.use(
70+
rest.get("/hub/identities", (req, res, ctx) => {
71+
return res(
72+
ctx.status(200),
73+
ctx.json([
74+
{ id: 0, name: "proxy-cred", kind: "proxy" },
75+
{ id: 1, name: "maven-cred", kind: "maven" },
76+
{ id: 2, name: "source-cred", kind: "source" },
77+
])
78+
);
79+
})
80+
);
8681

8782
render(<Proxies />);
8883
const httpProxySwitch = await screen.findByLabelText("HTTP proxy");
@@ -112,14 +107,19 @@ describe("Component: proxy-form", () => {
112107
expect(sourceCred).toBeNull(); // it doesn't exist
113108
});
114109

115-
it.skip("Select https proxy identity", async () => {
116-
const identitiesData: Identity[] = [
117-
{ id: 0, name: "proxy-cred", kind: "proxy" },
118-
{ id: 1, name: "maven-cred", kind: "maven" },
119-
{ id: 2, name: "source-cred", kind: "source" },
120-
];
121-
122-
mock.onGet(`${IDENTITIES}`).reply(200, identitiesData);
110+
it("Select https proxy identity", async () => {
111+
server.use(
112+
rest.get("/hub/identities", (req, res, ctx) => {
113+
return res(
114+
ctx.status(200),
115+
ctx.json([
116+
{ id: 0, name: "proxy-cred", kind: "proxy" },
117+
{ id: 1, name: "maven-cred", kind: "maven" },
118+
{ id: 2, name: "source-cred", kind: "source" },
119+
])
120+
);
121+
})
122+
);
123123

124124
render(<Proxies />);
125125
const httpsProxySwitch = await screen.findByLabelText("HTTPS proxy");

client/src/app/test-config/mockInstance.ts

-4
This file was deleted.

0 commit comments

Comments
 (0)