diff --git a/test/index.spec.js b/test/index.spec.js index df8444a..fb8df62 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -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); @@ -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); @@ -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); @@ -47,7 +47,7 @@ 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(); }); @@ -55,7 +55,7 @@ describe("basic tests", () => { 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(); }); @@ -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); @@ -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(); @@ -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(); }); @@ -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(); }); @@ -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(); }); @@ -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(); }); @@ -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(); }); @@ -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(); }); @@ -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(); }); @@ -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(); }); @@ -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(); });