Improve lockdown tests
RENAME
packages/lockdown-shim/test/date-allow.test.js
packages/lockdown-shim/test/tame-date-allow.test.js
RENAME
packages/lockdown-shim/test/date.test.js
packages/lockdown-shim/test/tame-date.test.js
@@ -4,7 +4,7 @@ import { lockdown } from '../src/main.js';
lockdown();
-test('lockdown() - Date in Compartment is tamed', t => {
+test('lockdown() default - Date in Compartment is tamed', t => {
const c = new Compartment();
t.equal(c.evaluate('Date.parse("1982-04-09")'), Date.parse('1982-04-09'));
@@ -18,7 +18,7 @@ test('lockdown() - Date in Compartment is tamed', t => {
t.end();
});
-test('lockdown() - Date in nested Compartment is tamed', t => {
+test('lockdown() default - Date in nested Compartment is tamed', t => {
const c = new Compartment().evaluate('new Compartment()');
const now = c.evaluate('Date.now()');

RENAME
packages/lockdown-shim/test/error-allow.test.js
packages/lockdown-shim/test/tame-error-allow.test.js
RENAME
packages/lockdown-shim/test/error.test.js
packages/lockdown-shim/test/tame-error.test.js
@@ -4,7 +4,7 @@ import { lockdown } from '../src/main.js';
lockdown();
-test('lockdown allow Error - Error is tamed', t => {
+test('lockdown default - Error is tamed', t => {
const c = new Compartment();
t.equal(c.evaluate('typeof Error.captureStackTrace'), 'undefined');
t.equal(c.evaluate('typeof Error.stackTraceLimit'), 'undefined');
@@ -12,7 +12,7 @@ test('lockdown allow Error - Error is tamed', t => {
t.end();
});
-test('lockdown allow Error - Error in nested Compartment is tamed', t => {
+test('lockdown default - Error in nested Compartment is tamed', t => {
const c = new Compartment().evaluate('new Compartment()');
t.equal(c.evaluate('typeof Error.captureStackTrace'), 'undefined');
t.equal(c.evaluate('typeof Error.stackTraceLimit'), 'undefined');

RENAME
packages/lockdown-shim/test/math-allow.test.js
packages/lockdown-shim/test/tame-math-allow.test.js
RENAME
packages/lockdown-shim/test/math.test.js
packages/lockdown-shim/test/tame-math.test.js
@@ -4,13 +4,13 @@ import { lockdown } from '../src/main.js';
lockdown();
-test('lockdown() Math allowed - Math from Compartment is tamed', t => {
+test('lockdown() default - Math from Compartment is tamed', t => {
const c = new Compartment();
t.throws(() => c.evaluate('Math.random()'));
t.end();
});
-test('lockdown() Math allowed - Math from nested Compartment is tamed', t => {
+test('lockdown() default - Math from nested Compartment is tamed', t => {
const c = new Compartment().evaluate('new Compartment()');
t.throws(() => c.evaluate('Math.random()'));
t.end();

MODIFY
packages/lockdown-shim/test/whitelist.test.js
packages/lockdown-shim/test/whitelist.test.js
@@ -5,14 +5,9 @@ import { lockdown } from '../src/main.js';
lockdown();
test('indirect eval is possible', t => {
- try {
const c = new Compartment();
t.equal(c.evaluate(`(1,eval)('123')`), 123, 'indirect eval succeeds');
- } catch (e) {
- t.assert(false, e);
- } finally {
t.end();
- }
});
test('SharedArrayBuffer should be removed because it is not on the whitelist', t => {
@@ -34,13 +29,21 @@ test('SharedArrayBuffer should be removed because it is not on the whitelist', t
test('remove RegExp.prototype.compile', t => {
const c = new Compartment();
- t.equal(c.evaluate('const r = /./; typeof r.compile'), 'undefined');
+ t.equal(
+ c.evaluate('const r = /./; typeof r.compile'),
+ 'undefined',
+ 'should remove RegExp.prototype.compile',
+ );
t.end();
});
test('remove RegExp.$1', t => {
const c = new Compartment();
- t.equal(typeof c.evaluate('RegExp.$1'), 'undefined');
+ t.equal(
+ typeof c.evaluate('RegExp.$1'),
+ 'undefined',
+ 'should remove RegExp.$1',
+ );
t.end();
});
@@ -52,7 +55,6 @@ test('remove Intl', t => {
});
test('do not remove Object.prototype.__proto__', t => {
- try {
const c = new Compartment();
t.equal(
c.evaluate('({}).__proto__'),
@@ -74,9 +76,6 @@ x.slice;
c.global.Array.prototype.slice,
`prototype __proto__ inheritance works`,
);
- } catch (e) {
- t.isNot(e, e, 'unexpected exception');
- } finally {
+
t.end();
- }
});

Improve lockdown tests