diff --git a/test/cli.mjs b/test/cli.mjs index fbe0f0e..302bde2 100644 --- a/test/cli.mjs +++ b/test/cli.mjs @@ -183,127 +183,6 @@ describe("postject API", () => { }).timeout(3_00_000); }); -describe("Inject data into Node.js using CLI", () => { - let filename; - let tempDir; - let resourceContents; - let resourceFilename; - - beforeEach(async () => { - tempDir = temporaryDirectory(); - await fs.ensureDir(tempDir); - - filename = path.join(tempDir, path.basename(process.execPath)); - - await fs.copy(process.execPath, filename); - - resourceContents = crypto.randomBytes(64).toString("hex"); - resourceFilename = path.join(tempDir, "resource.bin"); - await fs.writeFile(resourceFilename, resourceContents); - }); - - afterEach(() => { - rimraf.sync(tempDir); - }); - - it("should inject a resource successfully", async () => { - { - const { status, stdout, stderr } = spawnSync( - "node", - ["./dist/cli.js", filename, "foobar", resourceFilename], - { encoding: "utf-8" } - ); - // TODO(dsanders11) - Enable this once we squelch LIEF warnings - // expect(stderr).to.be.empty; - expect(stdout).to.be.empty; - expect(status).to.equal(0); - } - - // Verifying code signing using a self-signed certificate. - { - if (process.platform === "darwin") { - let codesignFound = false; - try { - execSync("command -v codesign"); - codesignFound = true; - } catch (err) { - console.log(err.message); - } - if (codesignFound) { - execSync(`codesign --sign - ${filename}`); - execSync(`codesign --verify ${filename}`); - } - } - // TODO(RaisinTen): Test code signing on Windows. - } - - // After injection - { - const { status } = spawnSync(filename, ["-e", "process.exit()"], { - encoding: "utf-8", - }); - expect(status).to.equal(0); - } - }).timeout(3_00_000); -}); - -describe("Inject data into Node.js using API", () => { - let filename; - let tempDir; - let resourceContents; - let resourceFilename; - - beforeEach(async () => { - tempDir = temporaryDirectory(); - await fs.ensureDir(tempDir); - - filename = path.join(tempDir, path.basename(process.execPath)); - - await fs.copy(process.execPath, filename); - - resourceContents = crypto.randomBytes(64).toString("hex"); - resourceFilename = path.join(tempDir, "resource.bin"); - await fs.writeFile(resourceFilename, resourceContents); - }); - - afterEach(() => { - rimraf.sync(tempDir); - }); - - it("should inject a resource successfully", async () => { - { - const resourceData = await fs.readFile(resourceFilename); - await inject(filename, "foobar", resourceData); - } - - // Verifying code signing using a self-signed certificate. - { - if (process.platform === "darwin") { - let codesignFound = false; - try { - execSync("command -v codesign"); - codesignFound = true; - } catch (err) { - console.log(err.message); - } - if (codesignFound) { - execSync(`codesign --sign - ${filename}`); - execSync(`codesign --verify ${filename}`); - } - } - // TODO(RaisinTen): Test code signing on Windows. - } - - // After injection - { - const { status } = spawnSync(filename, ["-e", "process.exit()"], { - encoding: "utf-8", - }); - expect(status).to.equal(0); - } - }).timeout(3_00_000); -}); - describe("api.js should not contain __filename and __dirname", () => { let contents;