Skip to content

Commit

Permalink
test: remove Node.js specific tests (#61)
Browse files Browse the repository at this point in the history
It doesn't make sense to test just the resource injection part on a
program that doesn't use the runtime API by calling any of the functions
inside postject-api.h.

Refs: #59 (comment)
Signed-off-by: Darshan Sen <raisinten@gmail.com>

Signed-off-by: Darshan Sen <raisinten@gmail.com>
  • Loading branch information
RaisinTen authored Oct 28, 2022
1 parent 2f858f7 commit dfb7a70
Showing 1 changed file with 0 additions and 121 deletions.
121 changes: 0 additions & 121 deletions test/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit dfb7a70

Please sign in to comment.