diff --git a/test/helpers/create-https-test-server.ts b/test/helpers/create-https-test-server.ts index 05b5c3565..494662367 100644 --- a/test/helpers/create-https-test-server.ts +++ b/test/helpers/create-https-test-server.ts @@ -5,6 +5,7 @@ import type {SecureContextOptions} from 'tls'; import express from 'express'; import pify from 'pify'; import pem from 'pem'; +import type {CreateCSR, CreateCertificate} from '../types/pem.js'; export type HttpsServerOptions = { commonName?: string; @@ -25,8 +26,8 @@ export type ExtendedHttpsTestServer = { } & express.Express; const createHttpsTestServer = async (options: HttpsServerOptions = {}): Promise => { - const createCsr = pify(pem.createCSR); - const createCertificate = pify(pem.createCertificate); + const createCsr = pify(pem.createCSR as CreateCSR); + const createCertificate = pify(pem.createCertificate as CreateCertificate); const caCsrResult = await createCsr({commonName: 'authority'}); const caResult = await createCertificate({ @@ -68,7 +69,7 @@ const createHttpsTestServer = async (options: HttpsServerOptions = {}): Promise< await pify(server.https.listen.bind(server.https))(); - server.caKey = caKey; + server.caKey = caKey as any; server.caCert = caCert; server.port = (server.https.address() as net.AddressInfo).port; server.url = `https://localhost:${(server.port)}`; diff --git a/test/https.ts b/test/https.ts index e1b80ec75..0fa6f7f95 100644 --- a/test/https.ts +++ b/test/https.ts @@ -6,10 +6,11 @@ import pify from 'pify'; import pem from 'pem'; import got from '../source/index.js'; import {withHttpsServer} from './helpers/with-server.js'; +import type {CreatePrivateKey, CreateCSR, CreateCertificate} from './types/pem.js'; -const createPrivateKey = pify(pem.createPrivateKey); -const createCsr = pify(pem.createCSR); -const createCertificate = pify(pem.createCertificate); +const createPrivateKey = pify(pem.createPrivateKey as CreatePrivateKey); +const createCsr = pify(pem.createCSR as CreateCSR); +const createCertificate = pify(pem.createCertificate as CreateCertificate); const createPkcs12 = pify(pem.createPkcs12); test('https request without ca', withHttpsServer(), async (t, server, got) => { diff --git a/test/types/pem.ts b/test/types/pem.ts new file mode 100644 index 000000000..29c252ffe --- /dev/null +++ b/test/types/pem.ts @@ -0,0 +1,19 @@ +import type { + CertificateCreationOptions, + CertificateCreationResult, + PrivateKeyCreationOptions, + CSRCreationOptions, + Callback +} from 'pem'; + +export interface CreateCertificate { + (options: CertificateCreationOptions, callback: Callback): void +} + +export interface CreateCSR { + (options: CSRCreationOptions, callback: Callback<{ csr: string, clientKey: string }>): void +} + +export interface CreatePrivateKey { + (keyBitsize: number, options: PrivateKeyCreationOptions, callback: Callback<{ key: string }>): void +}