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 5e009ad
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 5 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
Binary file modified packages/compartment-mapper/test/snapshots/test-policy.js.snap
Binary file not shown.
53 changes: 53 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',
},
evilAlice: {
bluePill: 'undefined',
purplePill: 'undefined',
redPill: 'undefined',
},
scopedBob: {
scoped: 1,
},
},
};

const powerlessCarolExpectations = {
namespace: {
...defaultExpectations.namespace,
Expand Down Expand Up @@ -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 => {
Expand Down

0 comments on commit 5e009ad

Please sign in to comment.