Skip to content

Commit 4c06bae

Browse files
committed
Added positive assertions to tests
1 parent 17740f2 commit 4c06bae

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

packages/mui-utils/src/deepmerge/deepmerge.test.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,46 @@ import deepmerge from './deepmerge';
55
describe('deepmerge', () => {
66
// https://snyk.io/blog/after-three-years-of-silence-a-new-jquery-prototype-pollution-vulnerability-emerges-once-again/
77
it('should not be subject to prototype pollution via __proto__', () => {
8-
deepmerge({}, JSON.parse('{ "myProperty": "a", "__proto__" : { "isAdmin" : true } }'), {
9-
clone: false,
10-
});
8+
const result = deepmerge(
9+
{},
10+
JSON.parse('{ "myProperty": "a", "__proto__" : { "isAdmin" : true } }'),
11+
{
12+
clone: false,
13+
},
14+
);
1115

16+
// @ts-expect-error __proto__ is not on this object type
17+
// eslint-disable-next-line no-proto
18+
expect(result.__proto__).to.have.property('isAdmin');
1219
expect({}).not.to.have.property('isAdmin');
1320
});
1421

1522
// https://cwe.mitre.org/data/definitions/915.html
1623
it('should not be subject to prototype pollution via constructor', () => {
17-
deepmerge(
24+
const result = deepmerge(
1825
{},
1926
JSON.parse('{ "myProperty": "a", "constructor" : { "prototype": { "isAdmin" : true } } }'),
2027
{
2128
clone: true,
2229
},
2330
);
2431

32+
expect(result.constructor.prototype).to.have.property('isAdmin');
2533
expect({}).not.to.have.property('isAdmin');
2634
});
2735

2836
// https://cwe.mitre.org/data/definitions/915.html
2937
it('should not be subject to prototype pollution via prototype', () => {
30-
deepmerge({}, JSON.parse('{ "myProperty": "a", "prototype": { "isAdmin" : true } }'), {
31-
clone: false,
32-
});
38+
const result = deepmerge(
39+
{},
40+
JSON.parse('{ "myProperty": "a", "prototype": { "isAdmin" : true } }'),
41+
{
42+
clone: false,
43+
},
44+
);
3345

46+
// @ts-expect-error prototype is not on this object type
47+
expect(result.prototype).to.have.property('isAdmin');
3448
expect({}).not.to.have.property('isAdmin');
3549
});
3650

@@ -44,7 +58,7 @@ describe('deepmerge', () => {
4458
// eslint-disable-next-line no-proto
4559
expect(result.__proto__).to.have.property('isAdmin');
4660
expect({}).not.to.have.property('isAdmin');
47-
})
61+
});
4862

4963
it('should merge objects across realms', function test() {
5064
if (!/jsdom/.test(window.navigator.userAgent)) {

0 commit comments

Comments
 (0)