fix(javascript): integrate verified namespace interop with main
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
commit
9788112548
@@ -73,4 +73,51 @@ describe("Electron API identity", () => {
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("follows bundler namespace interop helpers without accepting other writes", () => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
var __toESM = (mod) => mod;
|
||||
var __importStar = (mod) => mod;
|
||||
let electron = require("electron");
|
||||
electron = __toESM(electron);
|
||||
new electron.BrowserWindow({ webPreferences: { preload: "./rolldown.js" } });
|
||||
var import_electron = __toESM(require("electron"));
|
||||
new import_electron.BrowserWindow({ webPreferences: { preload: "./esbuild.js" } });
|
||||
function _interopRequireWildcard(mod) { return mod; }
|
||||
const Electron = __importStar(require("electron"));
|
||||
new Electron.BrowserWindow({ webPreferences: { preload: "./tsc.js" } });
|
||||
|
||||
let replaced = require("electron");
|
||||
replaced = __toESM(require("./fake"));
|
||||
new replaced.BrowserWindow({ webPreferences: { preload: "./replaced.js" } });
|
||||
let rewritten = require("electron");
|
||||
rewritten = __toESM(rewritten);
|
||||
rewritten = fake;
|
||||
new rewritten.BrowserWindow({ webPreferences: { preload: "./rewritten.js" } });
|
||||
const babel = _interopRequireWildcard(require("electron"));
|
||||
new babel.BrowserWindow({ webPreferences: { preload: "./babel.js" } });
|
||||
function nested() {
|
||||
const __toESM = (mod) => mod;
|
||||
const scoped = __toESM(require("electron"));
|
||||
new scoped.BrowserWindow({ webPreferences: { preload: "./nested.js" } });
|
||||
}
|
||||
`);
|
||||
|
||||
expect(
|
||||
analysis.electron.browser_windows.map(({ preload_path }) => preload_path),
|
||||
).toEqual(["./rolldown.js", "./esbuild.js", "./tsc.js", "./babel.js"]);
|
||||
});
|
||||
|
||||
it("does not trust unbound helper names or non-function helper values", () => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
const __toESM = makeLookalike();
|
||||
const electron = __toESM(require("electron"));
|
||||
new electron.BrowserWindow({});
|
||||
let unbound = require("electron");
|
||||
unbound = __importStar(unbound);
|
||||
new unbound.BrowserWindow({});
|
||||
`);
|
||||
|
||||
expect(analysis.electron.browser_windows).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user