Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const tmpDir = os.tmpdir();
describe("basic tests", () => {
it("generates", (done) => {
keygen((err, result) => {
expect(expect(err).to.be.null);
expect(err).to.be.null;
expect(result.private).to.match(/^-----BEGIN (RSA|OPENSSH) PRIVATE KEY-----\n/);
expect(result.public).to.match(/^ssh-(ed25519|rsa) /);
expect(result.fingerprint.length > 0);
Expand All @@ -25,7 +25,7 @@ describe("basic tests", () => {

it("encrypts using password", (done) => {
keygen({ password: "blahblahblah" }, (err, result) => {
expect(expect(err).to.be.null);
expect(err).to.be.null;
expect(result.private).to.match(/^-----BEGIN (RSA|OPENSSH) PRIVATE KEY-----\n/);
expect(result.public).to.match(/^ssh-(ed25519|rsa) /);
expect(result.fingerprint.length > 0);
Expand All @@ -36,7 +36,7 @@ describe("basic tests", () => {

it("encrypts using passphrase", (done) => {
keygen({ passphrase: "foo bar biz bat" }, (err, result) => {
expect(expect(err).to.be.null);
expect(err).to.be.null;
expect(result.private).to.match(/^-----BEGIN (RSA|OPENSSH) PRIVATE KEY-----\n/);
expect(result.public).to.match(/^ssh-(ed25519|rsa) /);
expect(result.fingerprint.length > 0);
Expand All @@ -47,15 +47,15 @@ describe("basic tests", () => {

it("fails with negative number of bits", (done) => {
keygen({ bits: -1 }, (err, _) => {
expect(expect(err).to.not.be.null);
expect(err).to.not.be.null;
expect(err).to.match(/Bits has bad value/);
done();
});
});

it("fails with invalid key type", (done) => {
keygen({ type: "foo" }, (err, _) => {
expect(expect(err).to.not.be.null);
expect(err).to.not.be.null;
expect(err).to.match(/unknown key type/);
done();
});
Expand All @@ -64,7 +64,7 @@ describe("basic tests", () => {
["ecdsa", "ed25519", "rsa"].forEach((keyType) => {
it(`can generate a ${keyType} key`, (done) => {
keygen({ type: keyType }, (err, result) => {
expect(expect(err).to.be.null);
expect(err).to.be.null;
expect(result.private).to.match(/^-----BEGIN (.*) PRIVATE KEY-----\n/);
expect(result.public.length > 0);
expect(result.fingerprint.length > 0);
Expand All @@ -78,11 +78,11 @@ describe("basic tests", () => {
const dummyLocation = path.join(tmpDir, `dummy_file_to_keep_${crypto.randomBytes(16).toString("hex")}`);

keygen({ keep: true, location: dummyLocation }, (err, result) => {
expect(expect(err).to.be.null);
expect(expect(result.path).to.not.be.null);
expect(err).to.be.null;
expect(result.path).to.not.be.null;
const privateKey = result.private;
fs.readFile(result.path, { encoding: "ascii" }, (fileReadErr, key) => {
expect(expect(fileReadErr).to.be.null);
expect(fileReadErr).to.be.null;
expect(key).to.match(/^-----BEGIN (RSA|OPENSSH) PRIVATE KEY-----\n/);
expect(key).to.eql(privateKey);
done();
Expand All @@ -94,11 +94,11 @@ describe("basic tests", () => {
const dummyLocation = path.join(tmpDir, `dummy_file_to_discard_${crypto.randomBytes(16).toString("hex")}`);

keygen({ keep: false, location: dummyLocation }, (err, result) => {
expect(expect(err).to.be.null);
expect(expect(result.path).to.be.undefined);
expect(err).to.be.null;
expect(result.path).to.be.undefined;
expect(result.private).to.match(/^-----BEGIN (RSA|OPENSSH) PRIVATE KEY-----\n/);
fs.readFile(dummyLocation, { encoding: "ascii" }, (fileReadErr, _) => {
expect(expect(fileReadErr).to.not.be.null);
expect(fileReadErr).to.not.be.null;
expect(fileReadErr.code).to.eql("ENOENT");
done();
});
Expand All @@ -107,7 +107,7 @@ describe("basic tests", () => {

it("should fail if a bad location is specified", (done) => {
keygen({ location: "/bad/location/" }, (err, _) => {
expect(expect(err).to.not.be.null);
expect(err).to.not.be.null;
expect(err).to.match(/No such file or directory/);
done();
});
Expand All @@ -118,11 +118,11 @@ describe("basic tests", () => {

// run the process twice with a fixed location, and the second one should fail
keygen({ keep: true, location: dummyLocation }, (firstErr, firstResult) => {
expect(expect(firstErr).to.be.null);
expect(expect(firstResult.path).to.not.be.undefined);
expect(firstErr).to.be.null;
expect(firstResult.path).to.not.be.undefined;
expect(firstResult.private).to.match(/^-----BEGIN (RSA|OPENSSH) PRIVATE KEY-----\n/);
keygen({ keep: true, location: dummyLocation }, (secondErr, _) => {
expect(expect(secondErr).to.not.be.null);
expect(secondErr).to.not.be.null;
expect(secondErr).to.match(/Key not generated because it would overwrite an existing file/);
done();
});
Expand Down Expand Up @@ -152,7 +152,7 @@ describe("Advanced error scenarios", () => {
}, 5);

keygen((err, _) => {
expect(expect(err).to.not.be.null);
expect(err).to.not.be.null;
expect(err).to.match(/Some unexpected failure reading the private key/);
done();
});
Expand All @@ -171,7 +171,7 @@ describe("Advanced error scenarios", () => {
}, 10);

keygen((err, _) => {
expect(expect(err).to.not.be.null);
expect(err).to.not.be.null;
expect(err).to.match(/Something bad happened/);
done();
});
Expand All @@ -190,7 +190,7 @@ describe("Advanced error scenarios", () => {
}, 5);

keygen((err, _) => {
expect(expect(err).to.not.be.null);
expect(err).to.not.be.null;
expect(err).to.match(/Some unexpected failure reading the public key/);
done();
});
Expand All @@ -212,7 +212,7 @@ describe("Advanced error scenarios", () => {
}, 10);

keygen((err, _) => {
expect(expect(err).to.not.be.null);
expect(err).to.not.be.null;
expect(err).to.match(/Something bad happened with the public key/);
done();
});
Expand All @@ -229,7 +229,7 @@ describe("Advanced error scenarios", () => {
}, 5);

keygen((err, _) => {
expect(expect(err).to.not.be.null);
expect(err).to.not.be.null;
expect(err).to.match(/Some unexpected failure deleting the private key/);
done();
});
Expand All @@ -249,7 +249,7 @@ describe("Advanced error scenarios", () => {
}, 5);

keygen((err, _) => {
expect(expect(err).to.not.be.null);
expect(err).to.not.be.null;
expect(err).to.match(/Some unexpected failure deleting the public key/);
done();
});
Expand Down