Skip to content

Commit

Permalink
Fix type issues with latest pify version.
Browse files Browse the repository at this point in the history
  • Loading branch information
octet-stream committed Sep 2, 2022
1 parent 1543a53 commit 2cd8600
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
7 changes: 4 additions & 3 deletions test/helpers/create-https-test-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,8 +26,8 @@ export type ExtendedHttpsTestServer = {
} & express.Express;

const createHttpsTestServer = async (options: HttpsServerOptions = {}): Promise<ExtendedHttpsTestServer> => {
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({
Expand Down Expand Up @@ -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)}`;
Expand Down
7 changes: 4 additions & 3 deletions test/https.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
19 changes: 19 additions & 0 deletions test/types/pem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type {
CertificateCreationOptions,
CertificateCreationResult,
PrivateKeyCreationOptions,
CSRCreationOptions,
Callback
} from 'pem';

export interface CreateCertificate {
(options: CertificateCreationOptions, callback: Callback<CertificateCreationResult>): 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
}

0 comments on commit 2cd8600

Please sign in to comment.