Skip to content

Commit

Permalink
Reorder test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
robinvdvleuten committed May 2, 2022
1 parent 85b59f9 commit 4e526f2
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ cases('get(undefined, key, def)', ({ key, value, def }) => {
"get(undefined, 'one', 'foo')": { key: 'one', value: 'foo', def: 'foo' },
});

// Prevent prototype pollution.
cases('get(Object, key)', ({ key, value, test }) => {
shvl.set({}, key, value);
expect(shvl.get(Object, test || key)).toEqual(undefined);
}, {
"set({}, '__proto__.b', 'foo')": { key: '__proto__.b', value: 'foo' },
"set({}, 'a.__proto__.b', 'foo')": { key: 'a.__proto__.b', value: 'foo' },
"set({}, 'constructor.prototype.b', 'foo')": { key: 'constructor.prototype.b', value: 'foo'},
"set({}, 'a.constructor.prototype.b', 'foo')": { key: 'a.constructor.prototype.b', value: 'foo'}
});

cases('set(obj, key, value)', ({ obj, key, value, expected }) => {
expect(shvl.set(obj || {}, key, value)).toEqual(expected);
}, {
Expand All @@ -77,17 +88,6 @@ cases('set({}, key, value)', ({ obj, key, value, expected }) => {
"set(obj, 'a.constructorx.b', 'foo')": { key: 'a.constructorx.b', value: 'foo', expected: { a: { constructorx: { b: 'foo' } } } },
});

// prevent prototype pollution
cases('get(Object, key)', ({ key, value, test }) => {
shvl.set({}, key, value);
expect(shvl.get(Object, test || key)).toEqual(undefined);
}, {
"set({}, '__proto__.b', 'foo')": { key: '__proto__.b', value: 'foo' },
"set({}, 'a.__proto__.b', 'foo')": { key: 'a.__proto__.b', value: 'foo' },
"set({}, 'constructor.prototype.b', 'foo')": { key: 'constructor.prototype.b', value: 'foo'},
"set({}, 'a.constructor.prototype.b', 'foo')": { key: 'a.constructor.prototype.b', value: 'foo'}
});

cases('set(undefined, key, value)', ({ obj, key, value }) => {
expect(() => shvl.set(undefined, key, val)).toThrow();
}, {
Expand Down

0 comments on commit 4e526f2

Please sign in to comment.