Skip to content

Commit 5d7e74e

Browse files
authored
chore(deps): upgrade path-to-regexp to fix CVE (#5769)
* chore(deps): upgrade path-to-regexp to fix CVE * fix tests
1 parent 67431a4 commit 5d7e74e

45 files changed

Lines changed: 545 additions & 532 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/metal-pianos-draw.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@talend/react-cmf-router': minor
3+
'@talend/react-cmf': minor
4+
---
5+
6+
Upgrade path-to-regexp to fix CVE
7+
Reintroduce react-cmf unit tests

.changeset/ripe-mammals-build.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@talend/react-forms': patch
3+
---
4+
5+
Mock some dates in test that does not handle daylight saving change

packages/cmf-router/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"connected-react-router": "^6.9.3",
3232
"history": "^5.3.0",
3333
"lodash": "^4.17.23",
34-
"path-to-regexp": "^8.3.0",
3534
"prop-types": "^15.8.1",
3635
"react-redux": "^7.2.9",
3736
"react-router": "~6.3.0",
Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,26 @@ import App from '../src/App';
66
import ErrorBoundary from '../src/components/ErrorBoundary/ErrorBoundary.component';
77
import RegistryProvider from '../src/RegistryProvider';
88

9-
jest.mock('react-redux', () => ({
10-
esModule: true,
11-
Provider: jest.fn(props => <div className="ReactReduxProvider">{props.children}</div>),
12-
connect: jest.requireActual('react-redux').connect,
13-
}));
9+
vi.mock('react-redux', async importOriginal => {
10+
const mod = await importOriginal(); // type is inferred
1411

15-
jest.mock('../src/RegistryProvider', () =>
16-
jest.fn(props => <div className="RegistryProvider">{props.children}</div>),
17-
);
18-
jest.mock('../src/components/ErrorBoundary/ErrorBoundary.component', () =>
19-
jest.fn(props => <div className="ErrorBoundary">{props.children}</div>),
20-
);
12+
return {
13+
...mod,
14+
esModule: true,
15+
Provider: vi.fn(props => <div className="ReactReduxProvider">{props.children}</div>),
16+
};
17+
});
18+
19+
vi.mock('../src/RegistryProvider', () => {
20+
return {
21+
default: vi.fn(props => <div className="RegistryProvider">{props.children}</div>),
22+
};
23+
});
24+
vi.mock('../src/components/ErrorBoundary/ErrorBoundary.component', () => {
25+
return {
26+
default: vi.fn(props => <div className="ErrorBoundary">{props.children}</div>),
27+
};
28+
});
2129

2230
describe('CMF App', () => {
2331
it('App should init stuff', () => {

packages/cmf/__tests__/Dispatcher.test.js renamed to packages/cmf/__tests__/Dispatcher.test.jsx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ const noopRId = `${CONST.REGISTRY_ACTION_CREATOR_PREFIX}:noOp`;
99

1010
describe('Testing <Dispatcher />', () => {
1111
let registry;
12-
const onError = jest.fn();
12+
const onError = vi.fn();
1313
beforeEach(() => {
1414
registry = {
15-
[`${CONST.REGISTRY_ACTION_CREATOR_PREFIX}:existingActionCreator:id`]: jest.fn(),
16-
[`${CONST.REGISTRY_ACTION_CREATOR_PREFIX}:actionCreator:id`]: jest.fn(),
17-
[`${CONST.REGISTRY_ACTION_CREATOR_PREFIX}:noOp`]: jest.fn(),
18-
[`${CONST.REGISTRY_ACTION_CREATOR_PREFIX}:another:actionCreator:id`]: jest.fn(),
15+
[`${CONST.REGISTRY_ACTION_CREATOR_PREFIX}:existingActionCreator:id`]: vi.fn(),
16+
[`${CONST.REGISTRY_ACTION_CREATOR_PREFIX}:actionCreator:id`]: vi.fn(),
17+
[`${CONST.REGISTRY_ACTION_CREATOR_PREFIX}:noOp`]: vi.fn(),
18+
[`${CONST.REGISTRY_ACTION_CREATOR_PREFIX}:another:actionCreator:id`]: vi.fn(),
1919
};
2020

21-
jest.resetAllMocks();
21+
vi.resetAllMocks();
2222
});
2323

2424
it('should add onclick event handler to its children', () => {
25-
const dispatchActionCreator = jest.fn();
25+
const dispatchActionCreator = vi.fn();
2626

2727
render(
2828
<mock.Provider registry={registry} onError={onError}>
@@ -38,7 +38,7 @@ describe('Testing <Dispatcher />', () => {
3838
render(
3939
<mock.Provider registry={registry}>
4040
<mock.Provider.ErrorBoundary onError={onError}>
41-
<Dispatcher onClick="unknnown:actionCreator:id" dispatchActionCreator={jest.fn()}>
41+
<Dispatcher onClick="unknnown:actionCreator:id" dispatchActionCreator={vi.fn()}>
4242
<button type="button">Hello</button>
4343
</Dispatcher>
4444
</mock.Provider.ErrorBoundary>
@@ -85,8 +85,8 @@ describe('Testing <Dispatcher />', () => {
8585
);
8686

8787
it('should not prevent event propagation by default', () => {
88-
const dispatchActionCreator = jest.fn();
89-
const onClick = jest.fn();
88+
const dispatchActionCreator = vi.fn();
89+
const onClick = vi.fn();
9090
render(
9191
<mock.Provider registry={registry}>
9292
<div onClick={onClick}>
@@ -105,8 +105,8 @@ describe('Testing <Dispatcher />', () => {
105105
});
106106

107107
it('should prevent event propagation if stopPropagation is set', () => {
108-
const dispatchActionCreator = jest.fn();
109-
const onClick = jest.fn();
108+
const dispatchActionCreator = vi.fn();
109+
const onClick = vi.fn();
110110
render(
111111
<mock.Provider registry={registry}>
112112
<div onClick={onClick}>
@@ -126,7 +126,7 @@ describe('Testing <Dispatcher />', () => {
126126
});
127127

128128
it('should preventDefault if props is set', () => {
129-
const dispatchActionCreator = jest.fn();
129+
const dispatchActionCreator = vi.fn();
130130
render(
131131
<mock.Provider registry={registry}>
132132
<Dispatcher dispatchActionCreator={dispatchActionCreator} preventDefault onClick="noOp">
@@ -136,13 +136,13 @@ describe('Testing <Dispatcher />', () => {
136136
);
137137
const el = screen.getByText('foo');
138138
const event = createEvent.click(el, {});
139-
event.preventDefault = jest.fn();
139+
event.preventDefault = vi.fn();
140140
fireEvent(el, event);
141141
expect(event.preventDefault).toHaveBeenCalled();
142142
});
143143

144144
it('should dispatch actionCreator with props as data', () => {
145-
const dispatchActionCreator = jest.fn();
145+
const dispatchActionCreator = vi.fn();
146146
const props = {
147147
dispatchActionCreator,
148148
preventDefault: true,
@@ -160,7 +160,7 @@ describe('Testing <Dispatcher />', () => {
160160
const el = screen.getByText('foo');
161161

162162
const event = createEvent.click(el, {});
163-
event.preventDefault = jest.fn();
163+
event.preventDefault = vi.fn();
164164
expect(event.type).toBe('click');
165165

166166
fireEvent(el, event);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { mock } from '../src';
66
describe('Inject', () => {
77
it('should render', () => {
88
// given
9-
const MyComponent = jest.fn(props => <span {...props}>Hello</span>);
9+
const MyComponent = vi.fn(props => <span {...props}>Hello</span>);
1010
MyComponent.displayName = 'MyComponent';
1111
const registry = {
1212
'_.route.component:MyComponent': MyComponent,
@@ -27,7 +27,7 @@ describe('Inject', () => {
2727

2828
it('should render error if component not found', () => {
2929
// given
30-
const MyComponent = jest.fn();
30+
const MyComponent = vi.fn();
3131
MyComponent.displayName = 'MyComponent';
3232

3333
// when

packages/cmf/__tests__/__snapshots__/cmfConnect.test.jsx.snap

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`cmfConnect Higher Order Component should not remove the component state when unmount and cmfConnect keepComponentState is true 1`] = `
3+
exports[`cmfConnect > Higher Order Component > should not remove the component state when unmount and cmfConnect keepComponentState is true 1`] = `
44
{
55
"cmf": {
66
"componentState": {
@@ -15,7 +15,7 @@ exports[`cmfConnect Higher Order Component should not remove the component state
1515
}
1616
`;
1717

18-
exports[`cmfConnect Higher Order Component should not remove the component state when unmount and props keepComponentState is true 1`] = `
18+
exports[`cmfConnect > Higher Order Component > should not remove the component state when unmount and props keepComponentState is true 1`] = `
1919
{
2020
"cmf": {
2121
"componentState": {
@@ -30,7 +30,7 @@ exports[`cmfConnect Higher Order Component should not remove the component state
3030
}
3131
`;
3232

33-
exports[`cmfConnect Higher Order Component should remove the component state when unmount 1`] = `
33+
exports[`cmfConnect > Higher Order Component > should remove the component state when unmount 1`] = `
3434
{
3535
"cmf": {
3636
"componentState": {
@@ -45,7 +45,7 @@ exports[`cmfConnect Higher Order Component should remove the component state whe
4545
}
4646
`;
4747

48-
exports[`cmfConnect Higher Order Component should remove the component state when unmount 2`] = `
48+
exports[`cmfConnect > Higher Order Component > should remove the component state when unmount 2`] = `
4949
{
5050
"cmf": {
5151
"componentState": {
@@ -59,7 +59,7 @@ exports[`cmfConnect Higher Order Component should remove the component state whe
5959
}
6060
`;
6161

62-
exports[`cmfConnect Higher Order Component should remove the component state when unmount and props keepComponentState is false 1`] = `
62+
exports[`cmfConnect > Higher Order Component > should remove the component state when unmount and props keepComponentState is false 1`] = `
6363
{
6464
"cmf": {
6565
"componentState": {
@@ -74,7 +74,7 @@ exports[`cmfConnect Higher Order Component should remove the component state whe
7474
}
7575
`;
7676

77-
exports[`cmfConnect Higher Order Component should remove the component state when unmount and props keepComponentState is false 2`] = `
77+
exports[`cmfConnect > Higher Order Component > should remove the component state when unmount and props keepComponentState is false 2`] = `
7878
{
7979
"cmf": {
8080
"componentState": {

packages/cmf/__tests__/__snapshots__/componentState.test.js.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`state should getStateAccessors return accessors 1`] = `
3+
exports[`state > should getStateAccessors return accessors 1`] = `
44
{
55
"cmf": {
66
"componentState": {
@@ -17,7 +17,7 @@ exports[`state should getStateAccessors return accessors 1`] = `
1717
}
1818
`;
1919

20-
exports[`state should getStateAccessors return accessors 2`] = `
20+
exports[`state > should getStateAccessors return accessors 2`] = `
2121
{
2222
"cmf": {
2323
"componentState": {
@@ -34,7 +34,7 @@ exports[`state should getStateAccessors return accessors 2`] = `
3434
}
3535
`;
3636

37-
exports[`state should getStateAccessors return accessors 3`] = `
37+
exports[`state > should getStateAccessors return accessors 3`] = `
3838
{
3939
"cmf": {
4040
"componentState": {
@@ -48,7 +48,7 @@ exports[`state should getStateAccessors return accessors 3`] = `
4848
}
4949
`;
5050

51-
exports[`state should getStateAccessors should support no DEFAULT_STATE 1`] = `
51+
exports[`state > should getStateAccessors should support no DEFAULT_STATE 1`] = `
5252
{
5353
"cmf": {
5454
"componentState": {

packages/cmf/__tests__/action.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ describe('CMF action', () => {
116116
actionCreator: 'myActionCreator',
117117
};
118118
context.registry = {};
119-
context.registry['actionCreator:myActionCreator'] = jest.fn(() => ({ type: 'MY_ACTION_TYPE' }));
119+
context.registry['actionCreator:myActionCreator'] = vi.fn(() => ({ type: 'MY_ACTION_TYPE' }));
120120
const action = actionAPI.getActionObject(context, obj);
121121
expect(context.registry['actionCreator:myActionCreator']).toHaveBeenCalled();
122122
expect(action.type).toBe('MY_ACTION_TYPE');

packages/cmf/__tests__/actionCreator.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('CMF action', () => {
3333
});
3434

3535
it('should register an actionCreator in context', () => {
36-
const creator = jest.fn();
36+
const creator = vi.fn();
3737
const id = 'myactioncreator';
3838
context.registry = {};
3939
actionCreatorAPI.register(id, creator, context);

0 commit comments

Comments
 (0)