Skip to content

Commit

Permalink
test(compartment-mapper): check for resistance to bundled dependency …
Browse files Browse the repository at this point in the history
…name collision
  • Loading branch information
naugtur committed Jan 16, 2024
1 parent 1ff3c4b commit bef07ea
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 11 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions packages/compartment-mapper/test/scaffold.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,15 @@ export function scaffold(
};

const sourceMaps = new Set();
const sourceMapLog = [];
const sourceMapHook = (sourceMap, { sha512 }) => {
sourceMaps.add(sha512);
t.log(sha512, sourceMap);
sourceMapLog.push(['+', sha512, sourceMap]);
};

const computeSourceMapLocation = ({ sha512 }) => {
sourceMaps.delete(sha512);
sourceMapLog.push(['-', sha512]);
return `${sha512}.map.json`;
};

Expand All @@ -324,8 +326,10 @@ export function scaffold(
// in a way that is difficult to generalize since not all test paths
// reach here.
if (sourceMaps.size !== 0) {
sourceMapLog.forEach(l => t.log(...l));
t.log('left-over', sourceMaps);
throw new Error(
'The bundler and importer should agree on source map count',
`The bundler and importer should agree on source map count but they differ by ${sourceMaps.size}`,
);
}

Expand Down
12 changes: 6 additions & 6 deletions packages/compartment-mapper/test/snapshots/test-policy.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,37 @@ Generated by [AVA](https://avajs.dev).

> Snapshot 1
'Failed to load module "./attack.js" in package "file://.../compartment-mapper/test/fixtures-policy/node_modules/app/" (1 underlying failures: Importing "dan" in "eve-v1.0.0" was not allowed by packages policy {"dan":true} (info: Blocked in linking. "dan" is part of the compartment map and resolves to "file://.../compartment-mapper/test/fixtures-policy/node_modules/hackity/".)'
'Failed to load module "./attack.js" in package "file://.../compartment-mapper/test/fixtures-policy/node_modules/app/" (1 underlying failures: Importing "dan" in "eve-v1.0.0" was not allowed by packages policy {"dan":true,"eve>carol":true} (info: Blocked in linking. "dan" is part of the compartment map and resolves to "file://.../compartment-mapper/test/fixtures-policy/node_modules/hackity/".)'

## policy - attack - browser alias - with alias hint / importLocation

> Snapshot 1
'Failed to load module "./attack.js" in package "file://.../compartment-mapper/test/fixtures-policy/node_modules/app/" (1 underlying failures: Importing "dan" in "eve-v1.0.0" was not allowed by packages policy {"dan":true} (info: Blocked in linking. "dan" is part of the compartment map and resolves to "file://.../compartment-mapper/test/fixtures-policy/node_modules/hackity/".)'
'Failed to load module "./attack.js" in package "file://.../compartment-mapper/test/fixtures-policy/node_modules/app/" (1 underlying failures: Importing "dan" in "eve-v1.0.0" was not allowed by packages policy {"dan":true,"eve>carol":true} (info: Blocked in linking. "dan" is part of the compartment map and resolves to "file://.../compartment-mapper/test/fixtures-policy/node_modules/hackity/".)'

## policy - attack - browser alias - with alias hint / makeArchive / parseArchive

> Snapshot 1
'Failed to load module "./attack.js" in package "file://.../compartment-mapper/test/fixtures-policy/node_modules/app/" (1 underlying failures: Importing "dan" in "eve-v1.0.0" was not allowed by packages policy {"dan":true} (info: Blocked in linking. "dan" is part of the compartment map and resolves to "file://.../compartment-mapper/test/fixtures-policy/node_modules/hackity/".)'
'Failed to load module "./attack.js" in package "file://.../compartment-mapper/test/fixtures-policy/node_modules/app/" (1 underlying failures: Importing "dan" in "eve-v1.0.0" was not allowed by packages policy {"dan":true,"eve>carol":true} (info: Blocked in linking. "dan" is part of the compartment map and resolves to "file://.../compartment-mapper/test/fixtures-policy/node_modules/hackity/".)'

## policy - attack - browser alias - with alias hint / makeArchive / parseArchive with a prefix

> Snapshot 1
'Failed to load module "./attack.js" in package "file://.../compartment-mapper/test/fixtures-policy/node_modules/app/" (1 underlying failures: Importing "dan" in "eve-v1.0.0" was not allowed by packages policy {"dan":true} (info: Blocked in linking. "dan" is part of the compartment map and resolves to "file://.../compartment-mapper/test/fixtures-policy/node_modules/hackity/".)'
'Failed to load module "./attack.js" in package "file://.../compartment-mapper/test/fixtures-policy/node_modules/app/" (1 underlying failures: Importing "dan" in "eve-v1.0.0" was not allowed by packages policy {"dan":true,"eve>carol":true} (info: Blocked in linking. "dan" is part of the compartment map and resolves to "file://.../compartment-mapper/test/fixtures-policy/node_modules/hackity/".)'

## policy - attack - browser alias - with alias hint / writeArchive / loadArchive

> Snapshot 1
'Failed to load module "./attack.js" in package "file://.../compartment-mapper/test/fixtures-policy/node_modules/app/" (1 underlying failures: Importing "dan" in "eve-v1.0.0" was not allowed by packages policy {"dan":true} (info: Blocked in linking. "dan" is part of the compartment map and resolves to "file://.../compartment-mapper/test/fixtures-policy/node_modules/hackity/".)'
'Failed to load module "./attack.js" in package "file://.../compartment-mapper/test/fixtures-policy/node_modules/app/" (1 underlying failures: Importing "dan" in "eve-v1.0.0" was not allowed by packages policy {"dan":true,"eve>carol":true} (info: Blocked in linking. "dan" is part of the compartment map and resolves to "file://.../compartment-mapper/test/fixtures-policy/node_modules/hackity/".)'

## policy - attack - browser alias - with alias hint / writeArchive / importArchive

> Snapshot 1
'Failed to load module "./attack.js" in package "file://.../compartment-mapper/test/fixtures-policy/node_modules/app/" (1 underlying failures: Importing "dan" in "eve-v1.0.0" was not allowed by packages policy {"dan":true} (info: Blocked in linking. "dan" is part of the compartment map and resolves to "file://.../compartment-mapper/test/fixtures-policy/node_modules/hackity/".)'
'Failed to load module "./attack.js" in package "file://.../compartment-mapper/test/fixtures-policy/node_modules/app/" (1 underlying failures: Importing "dan" in "eve-v1.0.0" was not allowed by packages policy {"dan":true,"eve>carol":true} (info: Blocked in linking. "dan" is part of the compartment map and resolves to "file://.../compartment-mapper/test/fixtures-policy/node_modules/hackity/".)'

## policy - disallowed package with error hint / loadLocation

Expand Down
Binary file modified packages/compartment-mapper/test/snapshots/test-policy.js.snap
Binary file not shown.
54 changes: 54 additions & 0 deletions packages/compartment-mapper/test/test-policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ const fixtureAttack = new URL(
'fixtures-policy/node_modules/app/attack.js',
import.meta.url,
).toString();
const nameConfusionAttack = new URL(
'fixtures-policy/node_modules/app/attack-name.js',
import.meta.url,
).toString();

const globals = {
redPill: 42,
Expand Down Expand Up @@ -84,6 +88,15 @@ const anyPolicy = {
'alice>carol': ANY,
},
};
const evePolicy = {
entry: { ...policy.entry, packages: 'any' },
resources: {
...policy.resources,
eve: {
packages: 'any',
},
},
};

const defaultExpectations = {
namespace: {
Expand All @@ -110,6 +123,34 @@ const anyExpectations = {
carol: { bluePill: 'number', redPill: 'number', purplePill: 'number' },
},
};
const nameConfusionExpectations = {
namespace: {
alice: {
bluePill: 'undefined',
purplePill: 'undefined',
redPill: 'number',
},
bob: {
bluePill: 'number',
purplePill: 'undefined',
redPill: 'undefined',
},
carol: {
bluePill: 'undefined',
purplePill: 'number',
redPill: 'undefined',
},
evilCarol: {
bluePill: 'undefined',
purplePill: 'undefined',
redPill: 'undefined',
},
scopedBob: {
scoped: 1,
},
},
};

const powerlessCarolExpectations = {
namespace: {
...defaultExpectations.namespace,
Expand Down Expand Up @@ -193,6 +234,7 @@ scaffold(
eve: {
packages: {
dan: true,
'eve>carol': true,
},
},
dan: {},
Expand Down Expand Up @@ -225,6 +267,18 @@ scaffold(
},
);

scaffold(
'policy - attack - duplicated name via bundled dep',
test,
nameConfusionAttack,
makeResultAssertions(nameConfusionExpectations),
1, // expected number of assertions
{
addGlobals: globals,
policy: evePolicy,
},
);

const recursiveEdit = editor => originalPolicy => {
const policyToAlter = JSON.parse(JSON.stringify(originalPolicy));
const recur = obj => {
Expand Down

0 comments on commit bef07ea

Please sign in to comment.