diff --git a/packages/compartment-mapper/test/fixtures-policy/node_modules/app/attack-name.js b/packages/compartment-mapper/test/fixtures-policy/node_modules/app/attack-name.js new file mode 100644 index 0000000000..f8467f5fdc --- /dev/null +++ b/packages/compartment-mapper/test/fixtures-policy/node_modules/app/attack-name.js @@ -0,0 +1,7 @@ +import { alice, carol } from 'alice/alice.js'; +import bob from './bob.cjs'; +import scopedBob from '@ohmyscope/bob'; +import { alice as evilAlice } from 'eve/getalice.js'; + + +export { alice, bob, carol, scopedBob, evilAlice }; \ No newline at end of file diff --git a/packages/compartment-mapper/test/fixtures-policy/node_modules/eve/getalice.js b/packages/compartment-mapper/test/fixtures-policy/node_modules/eve/getalice.js new file mode 100644 index 0000000000..d1c8dd36aa --- /dev/null +++ b/packages/compartment-mapper/test/fixtures-policy/node_modules/eve/getalice.js @@ -0,0 +1 @@ +export { default as alice } from 'alice'; \ No newline at end of file diff --git a/packages/compartment-mapper/test/fixtures-policy/node_modules/eve/index.js b/packages/compartment-mapper/test/fixtures-policy/node_modules/eve/index.js index 31928c7d65..19572b65b3 100644 --- a/packages/compartment-mapper/test/fixtures-policy/node_modules/eve/index.js +++ b/packages/compartment-mapper/test/fixtures-policy/node_modules/eve/index.js @@ -3,5 +3,4 @@ export default { bluePill: typeof bluePill, yellowPill: typeof yellowPill, }; - import 'dan'; diff --git a/packages/compartment-mapper/test/fixtures-policy/node_modules/eve/node_modules/alice/index.js b/packages/compartment-mapper/test/fixtures-policy/node_modules/eve/node_modules/alice/index.js new file mode 100644 index 0000000000..c20a849df1 --- /dev/null +++ b/packages/compartment-mapper/test/fixtures-policy/node_modules/eve/node_modules/alice/index.js @@ -0,0 +1,6 @@ +export default { + redPill: typeof redPill, + bluePill: typeof bluePill, + purplePill: typeof purplePill, + }; + \ No newline at end of file diff --git a/packages/compartment-mapper/test/fixtures-policy/node_modules/eve/node_modules/alice/package.json b/packages/compartment-mapper/test/fixtures-policy/node_modules/eve/node_modules/alice/package.json new file mode 100644 index 0000000000..041bfd0d32 --- /dev/null +++ b/packages/compartment-mapper/test/fixtures-policy/node_modules/eve/node_modules/alice/package.json @@ -0,0 +1,7 @@ +{ + "name": "alice", + "version": "1.0.0", + "description": "A package named alice", + "main": "index.js", + "type": "module" +} diff --git a/packages/compartment-mapper/test/fixtures-policy/node_modules/eve/package.json b/packages/compartment-mapper/test/fixtures-policy/node_modules/eve/package.json index b1ef577174..09406aead6 100644 --- a/packages/compartment-mapper/test/fixtures-policy/node_modules/eve/package.json +++ b/packages/compartment-mapper/test/fixtures-policy/node_modules/eve/package.json @@ -1,14 +1,17 @@ { "name": "eve", "version": "1.0.0", - "main": "./index.js", "type": "module", "browser": { "dan": "hackity" }, "dependencies": { - "hackity": "*" + "hackity": "*", + "alice": "*" }, + "bundledDependencies": [ + "alice" + ], "scripts": { "preinstall": "echo DO NOT INSTALL TEST FIXTURES; exit -1" } diff --git a/packages/compartment-mapper/test/scaffold.js b/packages/compartment-mapper/test/scaffold.js index bedbe37296..98e20da452 100644 --- a/packages/compartment-mapper/test/scaffold.js +++ b/packages/compartment-mapper/test/scaffold.js @@ -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`; }; @@ -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}`, ); } diff --git a/packages/compartment-mapper/test/snapshots/test-policy.js.snap b/packages/compartment-mapper/test/snapshots/test-policy.js.snap index 2848cf1ebc..a541d7c800 100644 Binary files a/packages/compartment-mapper/test/snapshots/test-policy.js.snap and b/packages/compartment-mapper/test/snapshots/test-policy.js.snap differ diff --git a/packages/compartment-mapper/test/test-policy.js b/packages/compartment-mapper/test/test-policy.js index 0203b620c0..d06ce043ce 100644 --- a/packages/compartment-mapper/test/test-policy.js +++ b/packages/compartment-mapper/test/test-policy.js @@ -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, @@ -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: { @@ -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', + }, + evilAlice: { + bluePill: 'undefined', + purplePill: 'undefined', + redPill: 'undefined', + }, + scopedBob: { + scoped: 1, + }, + }, +}; + const powerlessCarolExpectations = { namespace: { ...defaultExpectations.namespace, @@ -225,6 +266,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 => {