diff --git a/test/cert.test.ts b/test/cert.test.ts index 056f0c1..9947507 100644 --- a/test/cert.test.ts +++ b/test/cert.test.ts @@ -331,8 +331,8 @@ describe("Certification Tests", () => { describe("resolveCert", () => { test("Resolves to certificate and key", async () => { const c = await _private.resolveCert({ - key: resolve("test", "fixture", "cert", "key.pem"), - cert: resolve("test", "fixture", "cert", "cert.pem"), + key: resolve("test", "cert", "key.pem"), + cert: resolve("test", "cert", "cert.pem"), }); expect(c.key).toBeTruthy(); expect(c.key).toContain("-----BEGIN RSA PRIVATE KEY-----"); @@ -344,8 +344,8 @@ describe("Certification Tests", () => { test("Resolves to certificate and encrypted key", async () => { const c = await _private.resolveCert({ - key: resolve("test", "fixture", "cert", "encrypted-key.pem"), - cert: resolve("test", "fixture", "cert", "cert.pem"), + key: resolve("test", "cert", "encrypted-key.pem"), + cert: resolve("test", "cert", "cert.pem"), }); expect(c.key).toBeTruthy(); expect(c.key).toContain("-----BEGIN ENCRYPTED PRIVATE KEY-----"); @@ -389,7 +389,7 @@ describe("Certification Tests", () => { expect( _private.resolveCert({ - key: resolve("test", "fixture", "cert", "key.pem"), + key: resolve("test", "cert", "key.pem"), cert: "non-existing.pem", }), ).rejects.toThrowError("ENOENT: no such file or directory"); @@ -397,7 +397,7 @@ describe("Certification Tests", () => { expect( _private.resolveCert({ key: "non-existing.pem", - cert: resolve("test", "fixture", "cert", "cert.pem"), + cert: resolve("test", "cert", "cert.pem"), }), ).rejects.toThrowError("ENOENT: no such file or directory"); }); @@ -406,11 +406,11 @@ describe("Certification Tests", () => { describe("resolvePfx", () => { test("Resolves certificate and key from store (without store passphrase)", async () => { const certs = await _private.resolveCert({ - cert: resolve("test", "fixture", "cert", "cert.pem"), - key: resolve("test", "fixture", "cert", "key.pem"), + cert: resolve("test", "cert", "cert.pem"), + key: resolve("test", "cert", "key.pem"), }); const pfx = await _private.resolvePfx({ - pfx: resolve("test", "fixture", "cert", "keystore2.p12"), + pfx: resolve("test", "cert", "keystore2.p12"), }); expect(pfx).toBeTruthy(); expect(pfx.safeContents.length).toEqual(2); @@ -425,11 +425,11 @@ describe("Certification Tests", () => { }); test("Resolves certificate and key from store (with store passphrase)", async () => { const certs = await _private.resolveCert({ - cert: resolve("test", "fixture", "cert", "cert.pem"), - key: resolve("test", "fixture", "cert", "key.pem"), + cert: resolve("test", "cert", "cert.pem"), + key: resolve("test", "cert", "key.pem"), }); const pfx = await _private.resolvePfx({ - pfx: resolve("test", "fixture", "cert", "keystore.p12"), + pfx: resolve("test", "cert", "keystore.p12"), passphrase: "store-pw", }); expect(pfx).toBeTruthy(); @@ -447,7 +447,7 @@ describe("Certification Tests", () => { test("Throws error on wrong store password", () => { expect( _private.resolvePfx({ - pfx: resolve("test", "fixture", "cert", "keystore.p12"), + pfx: resolve("test", "cert", "keystore.p12"), passphrase: "wrong-pw", }), ).rejects.toThrowError( @@ -456,7 +456,7 @@ describe("Certification Tests", () => { expect( _private.resolvePfx({ - pfx: resolve("test", "fixture", "cert", "keystore.p12"), + pfx: resolve("test", "cert", "keystore.p12"), passphrase: "", }), ).rejects.toThrowError( @@ -467,23 +467,13 @@ describe("Certification Tests", () => { test("Throws error on non existing store", () => { expect( _private.resolvePfx({ - pfx: resolve( - "test", - "fixture", - "cert", - "non-existing-keystore.p12", - ), + pfx: resolve("test", "cert", "non-existing-keystore.p12"), }), ).rejects.toThrowError("ENOENT: no such file or directory"); expect( _private.resolvePfx({ - pfx: resolve( - "test", - "fixture", - "cert", - "non-existing-keystore.p12", - ), + pfx: resolve("test", "cert", "non-existing-keystore.p12"), passphrase: "wrong-pw", }), ).rejects.toThrowError("ENOENT: no such file or directory"); diff --git a/test/generate-cert.ts b/test/generate-cert.ts index 7f6effc..39fbaf7 100644 --- a/test/generate-cert.ts +++ b/test/generate-cert.ts @@ -10,31 +10,17 @@ export default async function generateCert() { }); const decryptedKey = forge.pki.decryptRsaPrivateKey(certs.cert.key, pw); - mkdirSync(resolve("test", "fixture", "cert")); + mkdirSync(resolve("test", "cert")); + writeFileSync(resolve("test", "cert", "cert.pem"), certs.cert.cert); + writeFileSync(resolve("test", "cert", "encrypted-key.pem"), certs.cert.key); writeFileSync( - resolve("test", "fixture", "cert", "cert.pem"), - certs.cert.cert, - ); - writeFileSync( - resolve("test", "fixture", "cert", "encrypted-key.pem"), - certs.cert.key, - ); - writeFileSync( - resolve("test", "fixture", "cert", "key.pem"), + resolve("test", "cert", "key.pem"), forge.pki.privateKeyToPem(decryptedKey), ); const pfx = convertToPFX(certs.cert.cert, certs.cert.key, "store-pw"); const pfx2 = convertToPFX(certs.cert.cert, certs.cert.key, ""); - writeFileSync( - resolve("test", "fixture", "cert", "keystore.p12"), - pfx, - "binary", - ); - writeFileSync( - resolve("test", "fixture", "cert", "keystore2.p12"), - pfx2, - "binary", - ); + writeFileSync(resolve("test", "cert", "keystore.p12"), pfx, "binary"); + writeFileSync(resolve("test", "cert", "keystore2.p12"), pfx2, "binary"); } function convertToPFX( diff --git a/test/index.test.ts b/test/index.test.ts index 69ad872..6e3cdd6 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -57,9 +57,9 @@ describe("listhen", () => { listener = await listen(handle, { https: { // eslint-disable-next-line unicorn/prefer-module - key: resolve(__dirname, "fixture", "cert", "key.pem"), + key: resolve(__dirname, "cert", "key.pem"), // eslint-disable-next-line unicorn/prefer-module - cert: resolve(__dirname, "fixture", "cert", "cert.pem"), + cert: resolve(__dirname, "cert", "cert.pem"), }, hostname: "localhost", }); @@ -70,9 +70,9 @@ describe("listhen", () => { listener = await listen(handle, { https: { // eslint-disable-next-line unicorn/prefer-module - key: resolve(__dirname, "fixture", "cert", "encrypted-key.pem"), + key: resolve(__dirname, "cert", "encrypted-key.pem"), // eslint-disable-next-line unicorn/prefer-module - cert: resolve(__dirname, "fixture", "cert", "cert.pem"), + cert: resolve(__dirname, "cert", "cert.pem"), passphrase: "cert-pw", }, hostname: "localhost", @@ -85,9 +85,9 @@ describe("listhen", () => { listen(handle, { https: { // eslint-disable-next-line unicorn/prefer-module - key: resolve(__dirname, "fixture/cert/encrypted-key.pem"), + key: resolve(__dirname, "cert", "encrypted-key.pem"), // eslint-disable-next-line unicorn/prefer-module - cert: resolve(__dirname, "fixture/cert/cert.pem"), + cert: resolve(__dirname, "cert", "cert.pem"), passphrase: "wrong-pw", }, hostname: "localhost", @@ -99,7 +99,7 @@ describe("listhen", () => { const listener = await listen(handle, { https: { // eslint-disable-next-line unicorn/prefer-module - pfx: resolve(__dirname, "fixture/cert/keystore.p12"), + pfx: resolve(__dirname, "cert", "keystore.p12"), passphrase: "store-pw", }, hostname: "localhost", @@ -112,7 +112,7 @@ describe("listhen", () => { listen(handle, { https: { // eslint-disable-next-line unicorn/prefer-module - pfx: resolve(__dirname, "fixture/cert/keystore.p12"), + pfx: resolve(__dirname, "cert", "keystore.p12"), }, hostname: "localhost", }), @@ -126,7 +126,7 @@ describe("listhen", () => { listen(handle, { https: { // eslint-disable-next-line unicorn/prefer-module - pfx: resolve(__dirname, "fixture/cert/keystore.p12"), + pfx: resolve(__dirname, "cert", "keystore.p12"), passphrase: "wrong-pw", }, hostname: "localhost", diff --git a/test/setup.ts b/test/setup.ts index 2374cd4..394f719 100644 --- a/test/setup.ts +++ b/test/setup.ts @@ -4,7 +4,7 @@ import generateCert from "./generate-cert"; export async function setup() { process.env.NO_COLOR = "1"; - if (!existsSync(resolve("test", "fixture", "cert", "cert.pem"))) { + if (!existsSync(resolve("test", "cert", "cert.pem"))) { // eslint-disable-next-line unicorn/prefer-top-level-await await generateCert(); }