Skip to content

Commit

Permalink
Deprecate trustAdditionalCAs in favour of additionalTrustedCAs
Browse files Browse the repository at this point in the history
This makes the passthrough options consistent with the proxy config
options, and more consistent with option naming elsewhere.
  • Loading branch information
pimterry committed Jul 12, 2024
1 parent e143578 commit 7b32a62
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
7 changes: 7 additions & 0 deletions src/rules/passthrough-handling-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ export interface PassThroughHandlerConnectionOptions {
* or buffer value containing the PEM certificate, or a `certPath` key and a
* string value containing the local path to the PEM certificate.
*/
additionalTrustedCAs?: Array<CADefinition>;

/**
* Deprecated alias for `additionalTrustedCAs`
*
* @deprecated
*/
trustAdditionalCAs?: Array<CADefinition>;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/rules/passthrough-handling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export async function getTrustedCAs(
trustedCAs: Array<string | CADefinition> | undefined,
additionalTrustedCAs: Array<CADefinition> | undefined
): Promise<Array<string> | undefined> {
if (trustedCAs && additionalTrustedCAs) {
if (trustedCAs && additionalTrustedCAs?.length) {
throw new Error(`trustedCAs and additionalTrustedCAs options are mutually exclusive`);
}

Expand Down
9 changes: 7 additions & 2 deletions src/rules/requests/request-handler-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
} from '../../serialization/body-serialization';
import { ProxyConfig } from '../proxy-config';
import {
CADefinition,
ForwardingOptions,
PassThroughHandlerConnectionOptions,
PassThroughLookupOptions
Expand Down Expand Up @@ -771,7 +772,7 @@ export class PassThroughHandlerDefinition extends Serializable implements Reques
[host: string]: { pfx: Buffer, passphrase?: string }
};

public readonly extraCACertificates: Array<{ cert: string | Buffer } | { certPath: string }> = [];
public readonly extraCACertificates: Array<CADefinition> = [];

public readonly transformRequest?: RequestTransform;
public readonly transformResponse?: ResponseTransform;
Expand Down Expand Up @@ -820,7 +821,11 @@ export class PassThroughHandlerDefinition extends Serializable implements Reques
this.proxyConfig = options.proxyConfig;
this.simulateConnectionErrors = !!options.simulateConnectionErrors;

this.extraCACertificates = options.trustAdditionalCAs || [];
this.extraCACertificates =
options.additionalTrustedCAs ||
options.trustAdditionalCAs ||
[];

this.clientCertificateHostMap = options.clientCertificateHostMap || {};

if (options.beforeRequest && options.transformRequest && !_.isEmpty(options.transformRequest)) {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/requests/request-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,7 @@ export class PassThroughHandler extends PassThroughHandlerDefinition {
lookupOptions: data.lookupOptions,
simulateConnectionErrors: !!data.simulateConnectionErrors,
ignoreHostHttpsErrors: data.ignoreHostCertificateErrors,
trustAdditionalCAs: data.extraCACertificates,
additionalTrustedCAs: data.extraCACertificates,
clientCertificateHostMap: _.mapValues(data.clientCertificateHostMap,
({ pfx, passphrase }) => ({ pfx: deserializeBuffer(pfx), passphrase })
),
Expand Down
10 changes: 7 additions & 3 deletions src/rules/websockets/websocket-handler-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import { ProxyConfig } from '../proxy-config';
import {
PassThroughHandlerConnectionOptions,
ForwardingOptions,
PassThroughLookupOptions
PassThroughLookupOptions,
CADefinition
} from '../passthrough-handling-definitions';
import {
CloseConnectionHandlerDefinition,
Expand Down Expand Up @@ -69,7 +70,7 @@ export class PassThroughWebSocketHandlerDefinition extends Serializable implemen
[host: string]: { pfx: Buffer, passphrase?: string }
};

public readonly extraCACertificates: Array<{ cert: string | Buffer } | { certPath: string }> = [];
public readonly extraCACertificates: Array<CADefinition> = [];

constructor(options: PassThroughWebSocketHandlerOptions = {}) {
super();
Expand Down Expand Up @@ -98,7 +99,10 @@ export class PassThroughWebSocketHandlerDefinition extends Serializable implemen
this.lookupOptions = options.lookupOptions;
this.proxyConfig = options.proxyConfig;

this.extraCACertificates = options.trustAdditionalCAs || [];
this.extraCACertificates =
options.additionalTrustedCAs ||
options.trustAdditionalCAs ||
[];
this.clientCertificateHostMap = options.clientCertificateHostMap || {};
}

Expand Down
4 changes: 2 additions & 2 deletions test/integration/proxying/https-proxying.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ nodeOnly(() => {
await badServer.forAnyRequest().thenReply(200);

await server.forAnyRequest().thenPassThrough({
trustAdditionalCAs: [{ cert }]
additionalTrustedCAs: [{ cert }]
});

let response = await request.get(badServer.url, {
Expand All @@ -237,7 +237,7 @@ nodeOnly(() => {
await badServer.forAnyRequest().thenReply(200);

await server.forAnyRequest().thenPassThrough({
trustAdditionalCAs: [{ certPath }]
additionalTrustedCAs: [{ certPath }]
});

let response = await request.get(badServer.url, {
Expand Down

0 comments on commit 7b32a62

Please sign in to comment.