diff --git a/src/api.js b/src/api.js index f27c8c5..ed833cf 100644 --- a/src/api.js +++ b/src/api.js @@ -31,7 +31,7 @@ async function inject(filename, resourceName, resourceData, options) { } const executableFormat = postject.getExecutableFormat(executable); - if (!executableFormat) { + if (executableFormat === postject.ExecutableFormat.kUnknown) { throw new Error( "Executable must be a supported format: ELF, PE, or Mach-O" ); diff --git a/test/cli.mjs b/test/cli.mjs index 67d4f67..2b06da9 100644 --- a/test/cli.mjs +++ b/test/cli.mjs @@ -138,6 +138,29 @@ describe("postject CLI", () => { expect(status).to.equal(1); } }).timeout(3_00_000); + + it("should display an error message when the file is not a supported executable type", async () => { + const bogusFile = path.join(tempDir, "bogus.exe"); + await fs.writeFile(bogusFile, "#!/bin/bash"); + + const { status, stdout } = spawnSync( + "node", + [ + "./dist/cli.js", + bogusFile, + "foobar", + resourceFilename, + "--sentinel-fuse", + "NODE_JS_FUSE_fce680ab2cc467b6e072b8b5df1996b2", + ], + { encoding: "utf-8" } + ); + expect(stdout).to.have.string( + "Error: Executable must be a supported format: ELF, PE, or Mach-O" + ); + expect(stdout).to.not.have.string("Injection done!"); + expect(status).to.equal(1); + }).timeout(3_00_000); }); describe("postject API", () => {