Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import {
requestOAuth2,
} from '../request-helper-functions';

const TEST_CA_CERT = '-----BEGIN CERTIFICATE-----\nTEST\n-----END CERTIFICATE-----';

describe('Request Helper Functions', () => {
describe('proxyRequestToAxios', () => {
const baseUrl = 'https://example.de';
Expand Down Expand Up @@ -447,7 +449,7 @@ describe('Request Helper Functions', () => {

describe('should set SSL certificates', () => {
const agentOptions: SecureContextOptions = {
ca: '-----BEGIN CERTIFICATE-----\nTEST\n-----END CERTIFICATE-----',
ca: TEST_CA_CERT,
};
const requestObject: IRequestOptions = {
method: 'GET',
Expand Down Expand Up @@ -644,6 +646,36 @@ describe('Request Helper Functions', () => {
expect(axiosConfig.validateStatus!(401)).toBe(true);
expect(axiosConfig.validateStatus!(500)).toBe(true);
});

test('should pass agentOptions through to the https agent', () => {
const requestOptions: IHttpRequestOptions = {
method: 'GET',
url: 'https://example.com',
agentOptions: {
ca: TEST_CA_CERT,
},
};

const axiosConfig = convertN8nRequestToAxios(requestOptions);

expect((axiosConfig.httpsAgent as HttpsAgent).options.ca).toBe(TEST_CA_CERT);
});

test('should merge agentOptions with skipSslCertificateValidation', () => {
const requestOptions: IHttpRequestOptions = {
method: 'GET',
url: 'https://example.com',
skipSslCertificateValidation: true,
agentOptions: {
ca: TEST_CA_CERT,
},
};

const axiosConfig = convertN8nRequestToAxios(requestOptions);

expect((axiosConfig.httpsAgent as HttpsAgent).options.rejectUnauthorized).toBe(false);
expect((axiosConfig.httpsAgent as HttpsAgent).options.ca).toBe(TEST_CA_CERT);
});
});

describe('applyPaginationRequestData', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ export function convertN8nRequestToAxios(
}

const host = getHostFromRequestObject(n8nRequest);
const agentOptions: AgentOptions = {};
const agentOptions: AgentOptions = { ...n8nRequest.agentOptions };
if (host) {
agentOptions.servername = host;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/workflow/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type * as express from 'express';
import type FormData from 'form-data';
import type { PathLike } from 'fs';
import type { IncomingHttpHeaders } from 'http';
import type { AgentOptions } from 'https';
import type { ReplyHeaders, RequestBodyMatcher, RequestHeaderMatcher } from 'nock';
import type { Client as SSHClient } from 'ssh2';
import type { Readable } from 'stream';
Expand Down Expand Up @@ -514,6 +515,7 @@ export interface IHttpRequestOptions {
* If set, requests to domains not in this list will be blocked.
*/
allowedDomains?: string;
agentOptions?: AgentOptions;
}

/**
Expand Down
Loading