UNPKG

@pact-foundation/pact

Version:
130 lines 5.47 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var chai = __importStar(require("chai")); var stream_1 = require("stream"); var proxyRequest_1 = require("./proxyRequest"); var expect = chai.expect; describe('#toServerOptions', function () { var toServerOptions = function (opts, req) { if (opts === void 0) { opts = {}; } return (0, proxyRequest_1.toServerOptions)(opts, req !== null && req !== void 0 ? req : {}); }; context('changeOrigin', function () { it('forwards option', function () { var res = toServerOptions({ changeOrigin: true }); expect(res.changeOrigin).to.be.true; }); it('is false by default', function () { var res = toServerOptions(); expect(res.changeOrigin).to.be.false; }); }); context('secure', function () { it('is true when validating ssl', function () { var res = toServerOptions({ validateSSL: true }); expect(res.secure).to.be.true; }); it('is false by default', function () { var res = toServerOptions(); expect(res.secure).to.be.false; }); }); context('target', function () { it('uses providerBaseUrl', function () { var expectedTarget = 'http://test.com'; var res = toServerOptions({ providerBaseUrl: expectedTarget }); expect(res.target).to.eq(expectedTarget); }); it('uses loopback address by default', function () { var res = toServerOptions(); expect(res.target).to.eq('http://127.0.0.1/'); }); }); context('agent', function () { var initialEnv = __assign({}, process.env); afterEach(function () { process.env = __assign({}, initialEnv); }); it('uses no agent by default', function () { var res = toServerOptions(); expect(res.agent).to.be.undefined; }); it('uses HTTPS_PROXY', function () { var _a, _b; var expectedProxy = 'http://proxy.host/'; process.env.HTTPS_PROXY = expectedProxy; var res = toServerOptions(); expect((_b = (_a = res.agent) === null || _a === void 0 ? void 0 : _a.proxy) === null || _b === void 0 ? void 0 : _b.toString()).to.eq(expectedProxy); }); it('uses HTTP_PROXY', function () { var _a, _b; var expectedProxy = 'http://my.proxy/'; process.env.HTTP_PROXY = expectedProxy; var res = toServerOptions(); expect((_b = (_a = res.agent) === null || _a === void 0 ? void 0 : _a.proxy) === null || _b === void 0 ? void 0 : _b.toString()).to.eq(expectedProxy); }); it('prefers HTTPS_PROXY to HTTP_PROXY', function () { var _a, _b; process.env.HTTPS_PROXY = 'http://unused/'; var expectedProxy = 'http://expected.proxy/'; process.env.HTTPS_PROXY = expectedProxy; var res = toServerOptions(); expect((_b = (_a = res.agent) === null || _a === void 0 ? void 0 : _a.proxy) === null || _b === void 0 ? void 0 : _b.toString()).to.eq(expectedProxy); }); }); context('buffer', function () { it('provides readable of body', function () { var res = toServerOptions({}, { body: 'a' }); expect(res.buffer).to.be.instanceOf(stream_1.Readable); }); it('provides readable when body is undefined', function () { var res = toServerOptions(); expect(res.buffer).to.be.instanceOf(stream_1.Readable); }); }); }); //# sourceMappingURL=proxyRequest.spec.js.map