@abyss-project/main 36.2.0 → 36.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/tests/sdk-account-deletion.spec.d.ts +1 -0
- package/dist/api/tests/sdk-account-deletion.spec.js +54 -0
- package/dist/api/tests/sdk-account-deletion.spec.js.map +1 -0
- package/dist/api/tests/sdk-auth-session.spec.d.ts +1 -0
- package/dist/api/tests/sdk-auth-session.spec.js +177 -0
- package/dist/api/tests/sdk-auth-session.spec.js.map +1 -0
- package/dist/api/tests/sdk-chat-reliquats.spec.d.ts +1 -0
- package/dist/api/tests/sdk-chat-reliquats.spec.js +28 -0
- package/dist/api/tests/sdk-chat-reliquats.spec.js.map +1 -0
- package/dist/api/tests/sdk-funding.spec.d.ts +1 -0
- package/dist/api/tests/sdk-funding.spec.js +278 -0
- package/dist/api/tests/sdk-funding.spec.js.map +1 -0
- package/dist/api/tests/sdk-service-nudge.spec.d.ts +1 -0
- package/dist/api/tests/sdk-service-nudge.spec.js +63 -0
- package/dist/api/tests/sdk-service-nudge.spec.js.map +1 -0
- package/dist/constants/billing-catalog.constants.js +1 -1
- package/dist/constants/billing-catalog.constants.js.map +1 -1
- package/dist/constants/catalog-plan-quotas.constants.js +3 -3
- package/dist/constants/catalog-plan-quotas.constants.js.map +1 -1
- package/dist/constants/enforcement-registry.constants.d.ts +1 -1
- package/dist/constants/enforcement-registry.constants.js +6 -6
- package/dist/constants/enforcement-registry.constants.js.map +1 -1
- package/dist/constants/public-plans.constants.js +6 -6
- package/dist/constants/public-plans.constants.js.map +1 -1
- package/dist/constants/tests/activity.constants.spec.d.ts +1 -0
- package/dist/constants/tests/activity.constants.spec.js +63 -0
- package/dist/constants/tests/activity.constants.spec.js.map +1 -0
- package/dist/constants/tests/billing-catalog.constants.spec.d.ts +1 -0
- package/dist/constants/tests/billing-catalog.constants.spec.js +623 -0
- package/dist/constants/tests/billing-catalog.constants.spec.js.map +1 -0
- package/dist/constants/tests/catalog-plan-quotas.coherence.spec.d.ts +1 -0
- package/dist/constants/tests/catalog-plan-quotas.coherence.spec.js +111 -0
- package/dist/constants/tests/catalog-plan-quotas.coherence.spec.js.map +1 -0
- package/dist/constants/tests/demo-quotas.spec.d.ts +1 -0
- package/dist/constants/tests/demo-quotas.spec.js +64 -0
- package/dist/constants/tests/demo-quotas.spec.js.map +1 -0
- package/dist/constants/tests/environment.constants.spec.d.ts +1 -0
- package/dist/constants/tests/environment.constants.spec.js +27 -0
- package/dist/constants/tests/environment.constants.spec.js.map +1 -0
- package/dist/constants/tests/key-action-catalog.constants.spec.d.ts +1 -0
- package/dist/constants/tests/key-action-catalog.constants.spec.js +56 -0
- package/dist/constants/tests/key-action-catalog.constants.spec.js.map +1 -0
- package/dist/constants/tests/metric-price-scale.constants.spec.d.ts +1 -0
- package/dist/constants/tests/metric-price-scale.constants.spec.js +84 -0
- package/dist/constants/tests/metric-price-scale.constants.spec.js.map +1 -0
- package/dist/constants/tests/module-calibration.constants.spec.d.ts +1 -0
- package/dist/constants/tests/module-calibration.constants.spec.js +79 -0
- package/dist/constants/tests/module-calibration.constants.spec.js.map +1 -0
- package/dist/constants/tests/module-catalog.constants.spec.d.ts +1 -0
- package/dist/constants/tests/module-catalog.constants.spec.js +219 -0
- package/dist/constants/tests/module-catalog.constants.spec.js.map +1 -0
- package/dist/constants/tests/overage-pricing-single-source.spec.d.ts +1 -0
- package/dist/constants/tests/overage-pricing-single-source.spec.js +23 -0
- package/dist/constants/tests/overage-pricing-single-source.spec.js.map +1 -0
- package/dist/constants/tests/pack-catalog.constants.spec.d.ts +1 -0
- package/dist/constants/tests/pack-catalog.constants.spec.js +68 -0
- package/dist/constants/tests/pack-catalog.constants.spec.js.map +1 -0
- package/dist/constants/tests/password-policy.constants.spec.d.ts +1 -0
- package/dist/constants/tests/password-policy.constants.spec.js +67 -0
- package/dist/constants/tests/password-policy.constants.spec.js.map +1 -0
- package/dist/constants/tests/pausable-metrics.constants.spec.d.ts +1 -0
- package/dist/constants/tests/pausable-metrics.constants.spec.js +27 -0
- package/dist/constants/tests/pausable-metrics.constants.spec.js.map +1 -0
- package/dist/constants/tests/rum-sessions-catalog.spec.d.ts +1 -0
- package/dist/constants/tests/rum-sessions-catalog.spec.js +29 -0
- package/dist/constants/tests/rum-sessions-catalog.spec.js.map +1 -0
- package/dist/constants/tests/service-conformity.spec.d.ts +1 -0
- package/dist/constants/tests/service-conformity.spec.js +47 -0
- package/dist/constants/tests/service-conformity.spec.js.map +1 -0
- package/dist/explore/tests/expression.parser.spec.d.ts +1 -0
- package/dist/explore/tests/expression.parser.spec.js +228 -0
- package/dist/explore/tests/expression.parser.spec.js.map +1 -0
- package/dist/plan-name/tests/plan-name.utils.spec.d.ts +1 -0
- package/dist/plan-name/tests/plan-name.utils.spec.js +73 -0
- package/dist/plan-name/tests/plan-name.utils.spec.js.map +1 -0
- package/dist/server/archive/tests/archive-fixture.spec.d.ts +1 -0
- package/dist/server/archive/tests/archive-fixture.spec.js +84 -0
- package/dist/server/archive/tests/archive-fixture.spec.js.map +1 -0
- package/dist/server/archive/tests/archive-seal.util.spec.d.ts +1 -0
- package/dist/server/archive/tests/archive-seal.util.spec.js +98 -0
- package/dist/server/archive/tests/archive-seal.util.spec.js.map +1 -0
- package/dist/server/archive/tests/archive-stream.service.spec.d.ts +1 -0
- package/dist/server/archive/tests/archive-stream.service.spec.js +309 -0
- package/dist/server/archive/tests/archive-stream.service.spec.js.map +1 -0
- package/dist/server/demo/tests/demo-guard.spec.d.ts +1 -0
- package/dist/server/demo/tests/demo-guard.spec.js +142 -0
- package/dist/server/demo/tests/demo-guard.spec.js.map +1 -0
- package/dist/server/demo/tests/model-manifest.spec.d.ts +1 -0
- package/dist/server/demo/tests/model-manifest.spec.js +29 -0
- package/dist/server/demo/tests/model-manifest.spec.js.map +1 -0
- package/dist/server/demo/tests/route-manifest.spec.d.ts +1 -0
- package/dist/server/demo/tests/route-manifest.spec.js +256 -0
- package/dist/server/demo/tests/route-manifest.spec.js.map +1 -0
- package/dist/server/explore/tests/sql-translator.spec.d.ts +1 -0
- package/dist/server/explore/tests/sql-translator.spec.js +309 -0
- package/dist/server/explore/tests/sql-translator.spec.js.map +1 -0
- package/dist/server/tests/abyss-signature.util.spec.d.ts +1 -0
- package/dist/server/tests/abyss-signature.util.spec.js +53 -0
- package/dist/server/tests/abyss-signature.util.spec.js.map +1 -0
- package/dist/server/tests/after-commit-emit.util.spec.d.ts +1 -0
- package/dist/server/tests/after-commit-emit.util.spec.js +99 -0
- package/dist/server/tests/after-commit-emit.util.spec.js.map +1 -0
- package/dist/server/tests/encrypt-secret.util.spec.d.ts +1 -0
- package/dist/server/tests/encrypt-secret.util.spec.js +183 -0
- package/dist/server/tests/encrypt-secret.util.spec.js.map +1 -0
- package/dist/server/tests/hash-visitor.spec.d.ts +1 -0
- package/dist/server/tests/hash-visitor.spec.js +133 -0
- package/dist/server/tests/hash-visitor.spec.js.map +1 -0
- package/dist/server/tests/safe-url.util.spec.d.ts +1 -0
- package/dist/server/tests/safe-url.util.spec.js +989 -0
- package/dist/server/tests/safe-url.util.spec.js.map +1 -0
- package/dist/server/tests/utils/test-env.util.d.ts +5 -0
- package/dist/server/tests/utils/test-env.util.js +43 -0
- package/dist/server/tests/utils/test-env.util.js.map +1 -0
- package/dist/server/tests/utils/test-env.util.spec.d.ts +1 -0
- package/dist/server/tests/utils/test-env.util.spec.js +105 -0
- package/dist/server/tests/utils/test-env.util.spec.js.map +1 -0
- package/dist/tests/no-console-workflow-names.spec.d.ts +1 -0
- package/dist/tests/no-console-workflow-names.spec.js +25 -0
- package/dist/tests/no-console-workflow-names.spec.js.map +1 -0
- package/dist/translate/en.translate.d.ts +4 -4
- package/dist/translate/en.translate.js +4 -4
- package/dist/translate/en.translate.js.map +1 -1
- package/dist/translate/fr.translate.d.ts +4 -4
- package/dist/translate/fr.translate.js +4 -4
- package/dist/translate/fr.translate.js.map +1 -1
- package/dist/translate/tests/board-card-notifications.spec.d.ts +1 -0
- package/dist/translate/tests/board-card-notifications.spec.js +78 -0
- package/dist/translate/tests/board-card-notifications.spec.js.map +1 -0
- package/dist/translate/tests/cloud-file-infected-notification.spec.d.ts +1 -0
- package/dist/translate/tests/cloud-file-infected-notification.spec.js +20 -0
- package/dist/translate/tests/cloud-file-infected-notification.spec.js.map +1 -0
- package/dist/translate/tests/desk-ticket-notifications.spec.d.ts +1 -0
- package/dist/translate/tests/desk-ticket-notifications.spec.js +39 -0
- package/dist/translate/tests/desk-ticket-notifications.spec.js.map +1 -0
- package/dist/translate/tests/flow-rehydration-ready.spec.d.ts +1 -0
- package/dist/translate/tests/flow-rehydration-ready.spec.js +18 -0
- package/dist/translate/tests/flow-rehydration-ready.spec.js.map +1 -0
- package/dist/translate/tests/flow-webhook-undeliverable.spec.d.ts +1 -0
- package/dist/translate/tests/flow-webhook-undeliverable.spec.js +24 -0
- package/dist/translate/tests/flow-webhook-undeliverable.spec.js.map +1 -0
- package/dist/translate/tests/funding-notifications.spec.d.ts +1 -0
- package/dist/translate/tests/funding-notifications.spec.js +129 -0
- package/dist/translate/tests/funding-notifications.spec.js.map +1 -0
- package/dist/translate/tests/mcp-connection-notifications.spec.d.ts +1 -0
- package/dist/translate/tests/mcp-connection-notifications.spec.js +50 -0
- package/dist/translate/tests/mcp-connection-notifications.spec.js.map +1 -0
- package/dist/translate/tests/monitor-archive-damaged-notifications.spec.d.ts +1 -0
- package/dist/translate/tests/monitor-archive-damaged-notifications.spec.js +55 -0
- package/dist/translate/tests/monitor-archive-damaged-notifications.spec.js.map +1 -0
- package/dist/translate/tests/monitor-experiment-guardrail-notifications.spec.d.ts +1 -0
- package/dist/translate/tests/monitor-experiment-guardrail-notifications.spec.js +56 -0
- package/dist/translate/tests/monitor-experiment-guardrail-notifications.spec.js.map +1 -0
- package/dist/translate/tests/monitor-incident-notifications.spec.d.ts +1 -0
- package/dist/translate/tests/monitor-incident-notifications.spec.js +122 -0
- package/dist/translate/tests/monitor-incident-notifications.spec.js.map +1 -0
- package/dist/translate/tests/monitor-notification-channel-disabled-notifications.spec.d.ts +1 -0
- package/dist/translate/tests/monitor-notification-channel-disabled-notifications.spec.js +36 -0
- package/dist/translate/tests/monitor-notification-channel-disabled-notifications.spec.js.map +1 -0
- package/dist/translate/tests/monitor-oncall-page-notifications.spec.d.ts +1 -0
- package/dist/translate/tests/monitor-oncall-page-notifications.spec.js +43 -0
- package/dist/translate/tests/monitor-oncall-page-notifications.spec.js.map +1 -0
- package/dist/translate/tests/monitor-rehydration-ready.spec.d.ts +1 -0
- package/dist/translate/tests/monitor-rehydration-ready.spec.js +36 -0
- package/dist/translate/tests/monitor-rehydration-ready.spec.js.map +1 -0
- package/dist/translate/tests/monitor-sentinel-disable-on-failure.spec.d.ts +1 -0
- package/dist/translate/tests/monitor-sentinel-disable-on-failure.spec.js +33 -0
- package/dist/translate/tests/monitor-sentinel-disable-on-failure.spec.js.map +1 -0
- package/dist/translate/tests/overage-grace-notification.spec.d.ts +1 -0
- package/dist/translate/tests/overage-grace-notification.spec.js +17 -0
- package/dist/translate/tests/overage-grace-notification.spec.js.map +1 -0
- package/dist/types/enum/email-type.enum.d.ts +1 -1
- package/dist/types/enum/email-type.enum.js +1 -1
- package/dist/types/enum/email-type.enum.js.map +1 -1
- package/dist/types/enum/organization-billing.enum.d.ts +1 -2
- package/dist/types/enum/organization-billing.enum.js +0 -1
- package/dist/types/enum/organization-billing.enum.js.map +1 -1
- package/dist/types/enum/tests/abyss-application-event.enum.spec.d.ts +1 -0
- package/dist/types/enum/tests/abyss-application-event.enum.spec.js +68 -0
- package/dist/types/enum/tests/abyss-application-event.enum.spec.js.map +1 -0
- package/dist/types/enum/tests/billing-addon-status.enum.spec.d.ts +1 -0
- package/dist/types/enum/tests/billing-addon-status.enum.spec.js +66 -0
- package/dist/types/enum/tests/billing-addon-status.enum.spec.js.map +1 -0
- package/dist/types/enum/tests/email-type.desk-reporter.spec.d.ts +1 -0
- package/dist/types/enum/tests/email-type.desk-reporter.spec.js +27 -0
- package/dist/types/enum/tests/email-type.desk-reporter.spec.js.map +1 -0
- package/dist/types/enum/tests/external-delivery.enum.spec.d.ts +1 -0
- package/dist/types/enum/tests/external-delivery.enum.spec.js +9 -0
- package/dist/types/enum/tests/external-delivery.enum.spec.js.map +1 -0
- package/dist/types/enum/tests/internal-ticket-dead-permissions.enum.spec.d.ts +1 -0
- package/dist/types/enum/tests/internal-ticket-dead-permissions.enum.spec.js +35 -0
- package/dist/types/enum/tests/internal-ticket-dead-permissions.enum.spec.js.map +1 -0
- package/dist/types/enum/tests/organization-external-identity.enum.spec.d.ts +1 -0
- package/dist/types/enum/tests/organization-external-identity.enum.spec.js +28 -0
- package/dist/types/enum/tests/organization-external-identity.enum.spec.js.map +1 -0
- package/dist/types/enum/tests/report-notification-type.enum.spec.d.ts +1 -0
- package/dist/types/enum/tests/report-notification-type.enum.spec.js +18 -0
- package/dist/types/enum/tests/report-notification-type.enum.spec.js.map +1 -0
- package/dist/types/enum/tests/user-notification-content-type.enum.spec.d.ts +1 -0
- package/dist/types/enum/tests/user-notification-content-type.enum.spec.js +145 -0
- package/dist/types/enum/tests/user-notification-content-type.enum.spec.js.map +1 -0
- package/dist/types/enum/user-notification-category.enum.js +1 -1
- package/dist/types/enum/user-notification-category.enum.js.map +1 -1
- package/dist/types/enum/user-notification-content-type.enum.d.ts +8 -6
- package/dist/types/enum/user-notification-content-type.enum.js +2 -2
- package/dist/types/enum/user-notification-content-type.enum.js.map +1 -1
- package/dist/types/tests/desk-reporter-token.spec.d.ts +1 -0
- package/dist/types/tests/desk-reporter-token.spec.js +9 -0
- package/dist/types/tests/desk-reporter-token.spec.js.map +1 -0
- package/dist/types/tests/mcp-contract.spec.d.ts +1 -0
- package/dist/types/tests/mcp-contract.spec.js +102 -0
- package/dist/types/tests/mcp-contract.spec.js.map +1 -0
- package/dist/types/utils/tests/onboarding.utils.spec.d.ts +1 -0
- package/dist/types/utils/tests/onboarding.utils.spec.js +54 -0
- package/dist/types/utils/tests/onboarding.utils.spec.js.map +1 -0
- package/dist/utils/tests/annual-price.utils.spec.d.ts +1 -0
- package/dist/utils/tests/annual-price.utils.spec.js +50 -0
- package/dist/utils/tests/annual-price.utils.spec.js.map +1 -0
- package/dist/utils/tests/billing-deep-link.utils.spec.d.ts +1 -0
- package/dist/utils/tests/billing-deep-link.utils.spec.js +103 -0
- package/dist/utils/tests/billing-deep-link.utils.spec.js.map +1 -0
- package/dist/utils/tests/billing.utils.spec.d.ts +1 -0
- package/dist/utils/tests/billing.utils.spec.js +81 -0
- package/dist/utils/tests/billing.utils.spec.js.map +1 -0
- package/dist/utils/tests/board-card-due.utils.spec.d.ts +1 -0
- package/dist/utils/tests/board-card-due.utils.spec.js +63 -0
- package/dist/utils/tests/board-card-due.utils.spec.js.map +1 -0
- package/dist/utils/tests/invoice-amounts.utils.spec.d.ts +1 -0
- package/dist/utils/tests/invoice-amounts.utils.spec.js +215 -0
- package/dist/utils/tests/invoice-amounts.utils.spec.js.map +1 -0
- package/dist/utils/tests/invoice-line-label.utils.spec.d.ts +1 -0
- package/dist/utils/tests/invoice-line-label.utils.spec.js +108 -0
- package/dist/utils/tests/invoice-line-label.utils.spec.js.map +1 -0
- package/dist/utils/tests/module-lot-price.utils.spec.d.ts +1 -0
- package/dist/utils/tests/module-lot-price.utils.spec.js +56 -0
- package/dist/utils/tests/module-lot-price.utils.spec.js.map +1 -0
- package/dist/utils/tests/module-price.utils.spec.d.ts +1 -0
- package/dist/utils/tests/module-price.utils.spec.js +79 -0
- package/dist/utils/tests/module-price.utils.spec.js.map +1 -0
- package/dist/utils/tests/overage-negotiated-rate.utils.spec.d.ts +1 -0
- package/dist/utils/tests/overage-negotiated-rate.utils.spec.js +59 -0
- package/dist/utils/tests/overage-negotiated-rate.utils.spec.js.map +1 -0
- package/dist/utils/tests/plan-capacity.utils.spec.d.ts +1 -0
- package/dist/utils/tests/plan-capacity.utils.spec.js +81 -0
- package/dist/utils/tests/plan-capacity.utils.spec.js.map +1 -0
- package/dist/utils/tests/pricing-calculator.utils.spec.d.ts +1 -0
- package/dist/utils/tests/pricing-calculator.utils.spec.js +33 -0
- package/dist/utils/tests/pricing-calculator.utils.spec.js.map +1 -0
- package/dist/utils/tests/pricing.utils.spec.d.ts +1 -0
- package/dist/utils/tests/pricing.utils.spec.js +219 -0
- package/dist/utils/tests/pricing.utils.spec.js.map +1 -0
- package/dist/utils/tests/quota-ceiling.utils.spec.d.ts +1 -0
- package/dist/utils/tests/quota-ceiling.utils.spec.js +119 -0
- package/dist/utils/tests/quota-ceiling.utils.spec.js.map +1 -0
- package/dist/utils/tests/quote-overage-rate.spec.d.ts +1 -0
- package/dist/utils/tests/quote-overage-rate.spec.js +39 -0
- package/dist/utils/tests/quote-overage-rate.spec.js.map +1 -0
- package/dist/utils/tests/resolve-user.utils.spec.d.ts +1 -0
- package/dist/utils/tests/resolve-user.utils.spec.js +350 -0
- package/dist/utils/tests/resolve-user.utils.spec.js.map +1 -0
- package/dist/utils/tests/shifted-tiers.utils.spec.d.ts +1 -0
- package/dist/utils/tests/shifted-tiers.utils.spec.js +176 -0
- package/dist/utils/tests/shifted-tiers.utils.spec.js.map +1 -0
- package/dist/utils/tests/subscription-retention.utils.spec.d.ts +1 -0
- package/dist/utils/tests/subscription-retention.utils.spec.js +80 -0
- package/dist/utils/tests/subscription-retention.utils.spec.js.map +1 -0
- package/dist/utils/tests/tracking.utils.spec.d.ts +1 -0
- package/dist/utils/tests/tracking.utils.spec.js +520 -0
- package/dist/utils/tests/tracking.utils.spec.js.map +1 -0
- package/dist/utils/tests/user-currency.utils.spec.d.ts +1 -0
- package/dist/utils/tests/user-currency.utils.spec.js +13 -0
- package/dist/utils/tests/user-currency.utils.spec.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,989 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const axios_1 = __importStar(require("axios"));
|
|
37
|
+
const http = __importStar(require("http"));
|
|
38
|
+
const https = __importStar(require("https"));
|
|
39
|
+
const safe_url_util_1 = require("../safe-url.util");
|
|
40
|
+
const demo_outbound_1 = require("../demo/demo-outbound");
|
|
41
|
+
const test_env_util_1 = require("./utils/test-env.util");
|
|
42
|
+
const agentOptions = (agent) => typeof agent === 'object' &&
|
|
43
|
+
agent !== null &&
|
|
44
|
+
'options' in agent &&
|
|
45
|
+
typeof agent.options === 'object'
|
|
46
|
+
? { ...agent.options }
|
|
47
|
+
: {};
|
|
48
|
+
const isConnectionFactory = (agent) => 'createConnection' in agent && typeof agent.createConnection === 'function';
|
|
49
|
+
const spyOnCreateConnection = () => {
|
|
50
|
+
const prototype = http.Agent.prototype;
|
|
51
|
+
if (!isConnectionFactory(prototype)) {
|
|
52
|
+
throw new Error('http.Agent.prototype.createConnection is missing');
|
|
53
|
+
}
|
|
54
|
+
return jest.spyOn(prototype, 'createConnection');
|
|
55
|
+
};
|
|
56
|
+
const FORM_SIGNATURE_HEADER = 'abyss-form-webhook-signature';
|
|
57
|
+
const MONITOR_SIGNATURE_HEADER = 'abyss-monitor-webhook-signature';
|
|
58
|
+
const resolverReturning = (...addresses) => jest.fn(async () => addresses.map((address) => ({ address })));
|
|
59
|
+
const hangingResolver = () => jest.fn(() => new Promise(() => undefined));
|
|
60
|
+
const redirectError = (location, status = 302) => new axios_1.AxiosError('redirect', 'ERR_BAD_RESPONSE', undefined, undefined, {
|
|
61
|
+
status,
|
|
62
|
+
headers: { location },
|
|
63
|
+
});
|
|
64
|
+
const okResponse = (data = 'ok') => ({ status: 200, data });
|
|
65
|
+
const captureError = async (pending) => {
|
|
66
|
+
try {
|
|
67
|
+
await pending;
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
return error;
|
|
71
|
+
}
|
|
72
|
+
throw new Error('the call was expected to fail');
|
|
73
|
+
};
|
|
74
|
+
const lookupThrough = (lookup, hostname) => new Promise((resolve, reject) => lookup(hostname, { all: true }, (error, addresses) => error ? reject(error) : resolve(addresses)));
|
|
75
|
+
describe('safe-url.util', () => {
|
|
76
|
+
beforeEach(() => {
|
|
77
|
+
(0, test_env_util_1.setTestEnv)(safe_url_util_1.ALLOW_PRIVATE_OUTBOUND_TARGETS_ENV, undefined);
|
|
78
|
+
(0, test_env_util_1.setTestEnv)('NODE_ENV', 'test');
|
|
79
|
+
});
|
|
80
|
+
afterEach(() => {
|
|
81
|
+
jest.restoreAllMocks();
|
|
82
|
+
});
|
|
83
|
+
describe('isBlockedIp', () => {
|
|
84
|
+
it.each([
|
|
85
|
+
['0.0.0.0/8', '0.1.2.3'],
|
|
86
|
+
['10.0.0.0/8', '10.20.30.40'],
|
|
87
|
+
['100.64.0.0/10', '100.127.255.254'],
|
|
88
|
+
['127.0.0.0/8', '127.5.5.5'],
|
|
89
|
+
['169.254.0.0/16 (cloud metadata)', '169.254.169.254'],
|
|
90
|
+
['172.16.0.0/12', '172.31.255.255'],
|
|
91
|
+
['192.0.0.0/24', '192.0.0.8'],
|
|
92
|
+
['192.168.0.0/16', '192.168.1.1'],
|
|
93
|
+
['198.18.0.0/15', '198.19.0.1'],
|
|
94
|
+
['224.0.0.0/4 (multicast)', '239.255.255.250'],
|
|
95
|
+
['240.0.0.0/4 (reserved, broadcast included)', '255.255.255.255'],
|
|
96
|
+
['192.0.2.0/24 (TEST-NET-1)', '192.0.2.1'],
|
|
97
|
+
['198.51.100.0/24 (TEST-NET-2)', '198.51.100.1'],
|
|
98
|
+
['203.0.113.0/24 (TEST-NET-3)', '203.0.113.1'],
|
|
99
|
+
])('blocks IPv4 %s (%s)', (_family, ip) => {
|
|
100
|
+
expect((0, safe_url_util_1.isBlockedIp)(ip)).toBe(true);
|
|
101
|
+
});
|
|
102
|
+
it.each([
|
|
103
|
+
['unspecified', '::'],
|
|
104
|
+
['loopback', '::1'],
|
|
105
|
+
['IPv4-mapped loopback', '::ffff:127.0.0.1'],
|
|
106
|
+
['IPv4-mapped metadata', '::ffff:169.254.169.254'],
|
|
107
|
+
['IPv4-compatible loopback', '::127.0.0.1'],
|
|
108
|
+
['link-local fe80::/10', 'fe80::'],
|
|
109
|
+
['unique-local fc00::/7 (fc)', 'fc00::'],
|
|
110
|
+
['unique-local fc00::/7 (fd)', 'fd00::'],
|
|
111
|
+
['multicast ff00::/8', 'ff02::'],
|
|
112
|
+
['NAT64 of loopback', '64:ff9b::127.0.0.1'],
|
|
113
|
+
['NAT64 of metadata', '64:ff9b::a9fe:a9fe'],
|
|
114
|
+
['NAT64 local-use 64:ff9b:1::/48', '64:ff9b:1::8.8.8.8'],
|
|
115
|
+
['6to4 of a private network', '2002:a00:1::'],
|
|
116
|
+
['6to4 of metadata', '2002:a9fe:a9fe::1'],
|
|
117
|
+
])('blocks IPv6 %s (%s)', (_family, ip) => {
|
|
118
|
+
expect((0, safe_url_util_1.isBlockedIp)(ip)).toBe(true);
|
|
119
|
+
});
|
|
120
|
+
it.each([
|
|
121
|
+
'8.8.8.8',
|
|
122
|
+
'93.184.216.34',
|
|
123
|
+
'100.128.0.1',
|
|
124
|
+
'172.32.0.1',
|
|
125
|
+
'192.0.1.1',
|
|
126
|
+
'198.20.0.1',
|
|
127
|
+
'223.255.255.255',
|
|
128
|
+
'2606:4700:4700::1111',
|
|
129
|
+
'::ffff:8.8.8.8',
|
|
130
|
+
'64:ff9b::8.8.8.8',
|
|
131
|
+
'2002:808:808::1',
|
|
132
|
+
])('accepts the public address %s', (ip) => {
|
|
133
|
+
expect((0, safe_url_util_1.isBlockedIp)(ip)).toBe(false);
|
|
134
|
+
});
|
|
135
|
+
it.each(['not-an-ip', '', '999.1.1.1'])('treats %p as blocked', (value) => {
|
|
136
|
+
expect((0, safe_url_util_1.isBlockedIp)(value)).toBe(true);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
describe('assertSafeHost', () => {
|
|
140
|
+
it('returns every address of a host that resolves only to public addresses', async () => {
|
|
141
|
+
await expect((0, safe_url_util_1.assertSafeHost)('monitored.example', resolverReturning('93.184.216.34', '2606:4700:4700::1111'))).resolves.toEqual([
|
|
142
|
+
{ address: '93.184.216.34', family: 4 },
|
|
143
|
+
{ address: '2606:4700:4700::1111', family: 6 },
|
|
144
|
+
]);
|
|
145
|
+
});
|
|
146
|
+
it('returns a public literal IP without resolving', async () => {
|
|
147
|
+
const resolver = resolverReturning('10.0.0.1');
|
|
148
|
+
await expect((0, safe_url_util_1.assertSafeHost)('[2606:4700:4700::1111]', resolver)).resolves.toEqual([
|
|
149
|
+
{ address: '2606:4700:4700::1111', family: 6 },
|
|
150
|
+
]);
|
|
151
|
+
expect(resolver).not.toHaveBeenCalled();
|
|
152
|
+
});
|
|
153
|
+
it('refuses a host when ONE of its resolved addresses is private', async () => {
|
|
154
|
+
const error = await captureError((0, safe_url_util_1.assertSafeHost)('rebind.example', resolverReturning('93.184.216.34', '10.0.0.5')));
|
|
155
|
+
expect(error.reason).toBe(safe_url_util_1.UnsafeDestinationReason.PRIVATE_ADDRESS);
|
|
156
|
+
});
|
|
157
|
+
it('refuses a host that resolves to no address at all', async () => {
|
|
158
|
+
const error = await captureError((0, safe_url_util_1.assertSafeHost)('empty.example', resolverReturning()));
|
|
159
|
+
expect(error).toBeInstanceOf(safe_url_util_1.HostResolutionError);
|
|
160
|
+
expect(error.resolverCode).toBeNull();
|
|
161
|
+
expect(error.reason).toBe(safe_url_util_1.UnsafeDestinationReason.UNRESOLVABLE_HOST);
|
|
162
|
+
});
|
|
163
|
+
it('refuses an empty bracketed host as an invalid URL', async () => {
|
|
164
|
+
const error = await captureError((0, safe_url_util_1.assertSafeHost)('[]'));
|
|
165
|
+
expect(error.reason).toBe(safe_url_util_1.UnsafeDestinationReason.INVALID_URL);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
describe('assertSafeRequestUrl', () => {
|
|
169
|
+
it('accepts a public hostname and returns its validated addresses', async () => {
|
|
170
|
+
const target = await (0, safe_url_util_1.assertSafeRequestUrl)('https://cdn.example.com/avatar.png', resolverReturning('93.184.216.34'));
|
|
171
|
+
expect(target.url.hostname).toBe('cdn.example.com');
|
|
172
|
+
expect(target.addresses).toEqual([{ address: '93.184.216.34', family: 4 }]);
|
|
173
|
+
});
|
|
174
|
+
it('accepts a raw public IP host without resolving', async () => {
|
|
175
|
+
const resolver = resolverReturning();
|
|
176
|
+
const target = await (0, safe_url_util_1.assertSafeRequestUrl)('https://8.8.8.8/x', resolver);
|
|
177
|
+
expect(target.addresses).toEqual([{ address: '8.8.8.8', family: 4 }]);
|
|
178
|
+
expect(resolver).not.toHaveBeenCalled();
|
|
179
|
+
});
|
|
180
|
+
it.each(['ftp://example.com/x', 'file:///etc/passwd', 'gopher://127.0.0.1:11211/_stats'])('refuses the scheme of %s as unsupported_scheme', async (url) => {
|
|
181
|
+
const resolver = resolverReturning('8.8.8.8');
|
|
182
|
+
const error = await captureError((0, safe_url_util_1.assertSafeRequestUrl)(url, resolver));
|
|
183
|
+
expect(error.reason).toBe(safe_url_util_1.UnsafeDestinationReason.UNSUPPORTED_SCHEME);
|
|
184
|
+
expect(resolver).not.toHaveBeenCalled();
|
|
185
|
+
});
|
|
186
|
+
it('refuses an unparseable URL as invalid_url', async () => {
|
|
187
|
+
const error = await captureError((0, safe_url_util_1.assertSafeRequestUrl)('not a url'));
|
|
188
|
+
expect(error.reason).toBe(safe_url_util_1.UnsafeDestinationReason.INVALID_URL);
|
|
189
|
+
});
|
|
190
|
+
it.each(['http://127.0.0.1/x', 'http://169.254.169.254/latest/meta-data/', 'http://[::1]/x'])('refuses the raw private host of %s without resolving', async (url) => {
|
|
191
|
+
const resolver = resolverReturning('8.8.8.8');
|
|
192
|
+
const error = await captureError((0, safe_url_util_1.assertSafeRequestUrl)(url, resolver));
|
|
193
|
+
expect(error.reason).toBe(safe_url_util_1.UnsafeDestinationReason.PRIVATE_ADDRESS);
|
|
194
|
+
expect(resolver).not.toHaveBeenCalled();
|
|
195
|
+
});
|
|
196
|
+
it('refuses a hostname when ONE of its resolved addresses is private (private_address)', async () => {
|
|
197
|
+
const error = await captureError((0, safe_url_util_1.assertSafeRequestUrl)('https://evil.example.com/x', resolverReturning('8.8.8.8', '169.254.169.254')));
|
|
198
|
+
expect(error).toBeInstanceOf(safe_url_util_1.UnsafeDestinationError);
|
|
199
|
+
expect(error).not.toBeInstanceOf(safe_url_util_1.HostResolutionError);
|
|
200
|
+
expect(error.reason).toBe(safe_url_util_1.UnsafeDestinationReason.PRIVATE_ADDRESS);
|
|
201
|
+
expect(error.hostname).toBe('evil.example.com');
|
|
202
|
+
});
|
|
203
|
+
it.each(['EAI_AGAIN', 'ENOTFOUND', 'ESERVFAIL'])('turns a DNS failure (%s) into a HostResolutionError carrying the resolver code', async (code) => {
|
|
204
|
+
const resolver = jest.fn(async () => {
|
|
205
|
+
throw Object.assign(new Error(`getaddrinfo ${code} nope.example.com`), { code });
|
|
206
|
+
});
|
|
207
|
+
const error = await captureError((0, safe_url_util_1.assertSafeRequestUrl)('https://nope.example.com/x', resolver));
|
|
208
|
+
expect(error).toBeInstanceOf(safe_url_util_1.HostResolutionError);
|
|
209
|
+
expect(error.resolverCode).toBe(code);
|
|
210
|
+
expect(error.reason).toBe(safe_url_util_1.UnsafeDestinationReason.UNRESOLVABLE_HOST);
|
|
211
|
+
expect(error.message).toBe(`Could not resolve host nope.example.com (${code})`);
|
|
212
|
+
});
|
|
213
|
+
it('keeps a null resolverCode when the resolver gives none', async () => {
|
|
214
|
+
const resolver = jest.fn(async () => {
|
|
215
|
+
throw new Error('resolution failed');
|
|
216
|
+
});
|
|
217
|
+
const error = await captureError((0, safe_url_util_1.assertSafeRequestUrl)('https://nope.example.com/x', resolver));
|
|
218
|
+
expect(error.resolverCode).toBeNull();
|
|
219
|
+
expect(error.message).toBe('Could not resolve host nope.example.com');
|
|
220
|
+
});
|
|
221
|
+
it('refuses a hostname that resolves to an empty list with a HostResolutionError', async () => {
|
|
222
|
+
const error = await captureError((0, safe_url_util_1.assertSafeRequestUrl)('https://empty.example.com/x', resolverReturning()));
|
|
223
|
+
expect(error).toBeInstanceOf(safe_url_util_1.HostResolutionError);
|
|
224
|
+
});
|
|
225
|
+
it('never puts the path or the query of the URL in its messages', async () => {
|
|
226
|
+
const messages = await Promise.all([
|
|
227
|
+
captureError((0, safe_url_util_1.assertSafeRequestUrl)('https://evil.example.com/hook/s3cr3t?token=s3cr3t', resolverReturning('10.0.0.1'))),
|
|
228
|
+
captureError((0, safe_url_util_1.assertSafeRequestUrl)('ftp://example.com/s3cr3t?token=s3cr3t')),
|
|
229
|
+
captureError((0, safe_url_util_1.assertSafeRequestUrl)('https://nope.example.com/s3cr3t?token=s3cr3t', async () => {
|
|
230
|
+
throw new Error('down');
|
|
231
|
+
})),
|
|
232
|
+
]);
|
|
233
|
+
for (const error of messages) {
|
|
234
|
+
expect(error.message).not.toContain('s3cr3t');
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
describe('development exception', () => {
|
|
239
|
+
it('validates nothing and returns addresses: null when set to true outside production', async () => {
|
|
240
|
+
(0, test_env_util_1.setTestEnv)(safe_url_util_1.ALLOW_PRIVATE_OUTBOUND_TARGETS_ENV, 'true');
|
|
241
|
+
(0, test_env_util_1.setTestEnv)('NODE_ENV', 'development');
|
|
242
|
+
const target = await (0, safe_url_util_1.assertSafeRequestUrl)('http://127.0.0.1:3000/hook');
|
|
243
|
+
expect(target.addresses).toBeNull();
|
|
244
|
+
});
|
|
245
|
+
it('is ignored when NODE_ENV is PRODUCTION', async () => {
|
|
246
|
+
(0, test_env_util_1.setTestEnv)(safe_url_util_1.ALLOW_PRIVATE_OUTBOUND_TARGETS_ENV, 'true');
|
|
247
|
+
(0, test_env_util_1.setTestEnv)('NODE_ENV', 'PRODUCTION');
|
|
248
|
+
const error = await captureError((0, safe_url_util_1.assertSafeRequestUrl)('http://127.0.0.1:3000/hook'));
|
|
249
|
+
expect(error.reason).toBe(safe_url_util_1.UnsafeDestinationReason.PRIVATE_ADDRESS);
|
|
250
|
+
});
|
|
251
|
+
it('is ignored when NODE_ENV is production', async () => {
|
|
252
|
+
(0, test_env_util_1.setTestEnv)(safe_url_util_1.ALLOW_PRIVATE_OUTBOUND_TARGETS_ENV, 'true');
|
|
253
|
+
(0, test_env_util_1.setTestEnv)('NODE_ENV', 'production');
|
|
254
|
+
const error = await captureError((0, safe_url_util_1.assertSafeHost)('127.0.0.1'));
|
|
255
|
+
expect(error.reason).toBe(safe_url_util_1.UnsafeDestinationReason.PRIVATE_ADDRESS);
|
|
256
|
+
});
|
|
257
|
+
it("is ignored when its value is not exactly 'true'", async () => {
|
|
258
|
+
(0, test_env_util_1.setTestEnv)(safe_url_util_1.ALLOW_PRIVATE_OUTBOUND_TARGETS_ENV, '1');
|
|
259
|
+
const error = await captureError((0, safe_url_util_1.assertSafeHost)('127.0.0.1'));
|
|
260
|
+
expect(error.reason).toBe(safe_url_util_1.UnsafeDestinationReason.PRIVATE_ADDRESS);
|
|
261
|
+
});
|
|
262
|
+
it('sets no pin: pinnedLookupConfig is empty for an unvalidated target', () => {
|
|
263
|
+
expect((0, safe_url_util_1.pinnedLookupConfig)({ url: new URL('http://127.0.0.1/'), addresses: null })).toEqual({});
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
describe('assertOutboundGuardEnvironment', () => {
|
|
267
|
+
it.each(['production', 'PRODUCTION'])('throws when the exception is set and NODE_ENV is %s', (nodeEnv) => {
|
|
268
|
+
expect(() => (0, safe_url_util_1.assertOutboundGuardEnvironment)({
|
|
269
|
+
NODE_ENV: nodeEnv,
|
|
270
|
+
[safe_url_util_1.ALLOW_PRIVATE_OUTBOUND_TARGETS_ENV]: 'true',
|
|
271
|
+
})).toThrow(`${safe_url_util_1.ALLOW_PRIVATE_OUTBOUND_TARGETS_ENV}=true`);
|
|
272
|
+
});
|
|
273
|
+
it.each([
|
|
274
|
+
['production without the exception', { NODE_ENV: 'production' }],
|
|
275
|
+
[
|
|
276
|
+
'development with the exception',
|
|
277
|
+
{ NODE_ENV: 'development', [safe_url_util_1.ALLOW_PRIVATE_OUTBOUND_TARGETS_ENV]: 'true' },
|
|
278
|
+
],
|
|
279
|
+
[
|
|
280
|
+
"production with a value other than 'true'",
|
|
281
|
+
{ NODE_ENV: 'production', [safe_url_util_1.ALLOW_PRIVATE_OUTBOUND_TARGETS_ENV]: 'false' },
|
|
282
|
+
],
|
|
283
|
+
])('does not throw for %s', (_case, env) => {
|
|
284
|
+
expect(() => (0, safe_url_util_1.assertOutboundGuardEnvironment)(env)).not.toThrow();
|
|
285
|
+
});
|
|
286
|
+
it('reads process.env by default', () => {
|
|
287
|
+
(0, test_env_util_1.setTestEnv)(safe_url_util_1.ALLOW_PRIVATE_OUTBOUND_TARGETS_ENV, 'true');
|
|
288
|
+
(0, test_env_util_1.setTestEnv)('NODE_ENV', 'production');
|
|
289
|
+
expect(() => (0, safe_url_util_1.assertOutboundGuardEnvironment)()).toThrow();
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
describe('isUnsafeDestinationError', () => {
|
|
293
|
+
it('is true for an UnsafeDestinationError', () => {
|
|
294
|
+
expect((0, safe_url_util_1.isUnsafeDestinationError)(new safe_url_util_1.UnsafeDestinationError(safe_url_util_1.UnsafeDestinationReason.PRIVATE_ADDRESS, 'h', 'refused'))).toBe(true);
|
|
295
|
+
});
|
|
296
|
+
it('is true for a HostResolutionError', () => {
|
|
297
|
+
expect((0, safe_url_util_1.isUnsafeDestinationError)(new safe_url_util_1.HostResolutionError('h', 'ENOTFOUND'))).toBe(true);
|
|
298
|
+
});
|
|
299
|
+
it('is false for a plain Error', () => {
|
|
300
|
+
expect((0, safe_url_util_1.isUnsafeDestinationError)(new Error('boom'))).toBe(false);
|
|
301
|
+
});
|
|
302
|
+
it('is false for an Error borrowing the name without a known reason', () => {
|
|
303
|
+
const impostor = Object.assign(new Error('x'), {
|
|
304
|
+
name: 'UnsafeDestinationError',
|
|
305
|
+
reason: 'other',
|
|
306
|
+
});
|
|
307
|
+
expect((0, safe_url_util_1.isUnsafeDestinationError)(impostor)).toBe(false);
|
|
308
|
+
});
|
|
309
|
+
it('recognises an error from another copy of the class by its name and reason', () => {
|
|
310
|
+
const foreign = Object.assign(new Error('x'), {
|
|
311
|
+
name: 'UnsafeDestinationError',
|
|
312
|
+
reason: safe_url_util_1.UnsafeDestinationReason.TOO_MANY_REDIRECTS,
|
|
313
|
+
});
|
|
314
|
+
expect((0, safe_url_util_1.isUnsafeDestinationError)(foreign)).toBe(true);
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
describe('safeAxiosRequest (transport stubbed)', () => {
|
|
318
|
+
it('sends nothing when the URL is refused', async () => {
|
|
319
|
+
const request = jest.spyOn(axios_1.default, 'request');
|
|
320
|
+
await expect((0, safe_url_util_1.safeAxiosRequest)({ url: 'http://169.254.169.254/latest/meta-data/', method: 'GET' }, { resolver: resolverReturning('8.8.8.8') })).rejects.toBeInstanceOf(safe_url_util_1.UnsafeDestinationError);
|
|
321
|
+
expect(request).not.toHaveBeenCalled();
|
|
322
|
+
});
|
|
323
|
+
it('sends a public URL once, with maxRedirects 0, a pinned lookup and no proxy', async () => {
|
|
324
|
+
const request = jest.spyOn(axios_1.default, 'request').mockResolvedValueOnce(okResponse());
|
|
325
|
+
const response = await (0, safe_url_util_1.safeAxiosRequest)({ url: 'https://cdn.example.com/avatar.png', method: 'GET' }, { resolver: resolverReturning('93.184.216.34') });
|
|
326
|
+
expect(response.status).toBe(200);
|
|
327
|
+
expect(request).toHaveBeenCalledTimes(1);
|
|
328
|
+
expect(request.mock.calls[0][0]).toMatchObject({ maxRedirects: 0, proxy: false });
|
|
329
|
+
expect(typeof request.mock.calls[0][0].lookup).toBe('function');
|
|
330
|
+
});
|
|
331
|
+
it('safeAxiosGet sends a GET whatever method the config carries', async () => {
|
|
332
|
+
const request = jest.spyOn(axios_1.default, 'request').mockResolvedValueOnce(okResponse());
|
|
333
|
+
await (0, safe_url_util_1.safeAxiosGet)('https://cdn.example.com/x', { method: 'POST' }, { resolver: resolverReturning('93.184.216.34') });
|
|
334
|
+
expect(request.mock.calls[0][0]).toMatchObject({
|
|
335
|
+
method: 'GET',
|
|
336
|
+
url: 'https://cdn.example.com/x',
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
it('refuses a redirect to a private address without calling the second host', async () => {
|
|
340
|
+
const request = jest
|
|
341
|
+
.spyOn(axios_1.default, 'request')
|
|
342
|
+
.mockRejectedValueOnce(redirectError('http://169.254.169.254/latest/'));
|
|
343
|
+
const error = await captureError((0, safe_url_util_1.safeAxiosGet)('https://cdn.example.com/x', {}, { resolver: resolverReturning('93.184.216.34') }));
|
|
344
|
+
expect(error.reason).toBe(safe_url_util_1.UnsafeDestinationReason.PRIVATE_ADDRESS);
|
|
345
|
+
expect(request).toHaveBeenCalledTimes(1);
|
|
346
|
+
});
|
|
347
|
+
it('refuses a redirect to a name resolving to a private address without calling it', async () => {
|
|
348
|
+
const resolver = jest.fn(async (hostname) => hostname === 'cdn.example.com' ? [{ address: '93.184.216.34' }] : [{ address: '10.0.0.7' }]);
|
|
349
|
+
const request = jest
|
|
350
|
+
.spyOn(axios_1.default, 'request')
|
|
351
|
+
.mockRejectedValueOnce(redirectError('https://internal.example.com/admin'));
|
|
352
|
+
const error = await captureError((0, safe_url_util_1.safeAxiosGet)('https://cdn.example.com/x', {}, { resolver }));
|
|
353
|
+
expect(error.reason).toBe(safe_url_util_1.UnsafeDestinationReason.PRIVATE_ADDRESS);
|
|
354
|
+
expect(resolver).toHaveBeenCalledWith('internal.example.com');
|
|
355
|
+
expect(request).toHaveBeenCalledTimes(1);
|
|
356
|
+
});
|
|
357
|
+
it('follows a redirect to another public URL after re-validating it', async () => {
|
|
358
|
+
const request = jest
|
|
359
|
+
.spyOn(axios_1.default, 'request')
|
|
360
|
+
.mockRejectedValueOnce(redirectError('https://other.example.com/final'))
|
|
361
|
+
.mockResolvedValueOnce(okResponse('final'));
|
|
362
|
+
const response = await (0, safe_url_util_1.safeAxiosRequest)({ url: 'https://cdn.example.com/x', method: 'GET' }, { resolver: resolverReturning('93.184.216.34') });
|
|
363
|
+
expect(response.data).toBe('final');
|
|
364
|
+
expect(request).toHaveBeenCalledTimes(2);
|
|
365
|
+
expect(request.mock.calls[1][0]).toMatchObject({ url: 'https://other.example.com/final' });
|
|
366
|
+
});
|
|
367
|
+
it('stops after 5 redirects with too_many_redirects', async () => {
|
|
368
|
+
const request = jest.spyOn(axios_1.default, 'request').mockImplementation(async () => {
|
|
369
|
+
throw redirectError('https://cdn.example.com/again');
|
|
370
|
+
});
|
|
371
|
+
const onSettled = jest.fn();
|
|
372
|
+
const error = await captureError((0, safe_url_util_1.safeAxiosGet)('https://cdn.example.com/x', {}, { resolver: resolverReturning('93.184.216.34'), onSettled }));
|
|
373
|
+
expect(error.reason).toBe(safe_url_util_1.UnsafeDestinationReason.TOO_MANY_REDIRECTS);
|
|
374
|
+
expect(error.message).toBe('Too many redirects (more than 5)');
|
|
375
|
+
expect(request).toHaveBeenCalledTimes(6);
|
|
376
|
+
expect(onSettled).toHaveBeenCalledWith({ hops: 5, durationMs: expect.any(Number) });
|
|
377
|
+
});
|
|
378
|
+
it('rethrows a non-redirect HTTP error as is', async () => {
|
|
379
|
+
const failure = new axios_1.AxiosError('boom', 'ERR_BAD_RESPONSE', undefined, undefined, {
|
|
380
|
+
status: 500,
|
|
381
|
+
headers: {},
|
|
382
|
+
});
|
|
383
|
+
jest.spyOn(axios_1.default, 'request').mockRejectedValueOnce(failure);
|
|
384
|
+
const error = await captureError((0, safe_url_util_1.safeAxiosGet)('https://cdn.example.com/x', {}, { resolver: resolverReturning('93.184.216.34') }));
|
|
385
|
+
expect(error).toBe(failure);
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
describe('safeAxiosInstanceRequest', () => {
|
|
389
|
+
it('drives the provided instance, never the global axios', async () => {
|
|
390
|
+
const globalRequest = jest.spyOn(axios_1.default, 'request');
|
|
391
|
+
const instanceRequest = jest.fn().mockResolvedValue(okResponse());
|
|
392
|
+
const instance = { request: instanceRequest };
|
|
393
|
+
const response = await (0, safe_url_util_1.safeAxiosInstanceRequest)(instance, { url: 'https://cdn.example.com/hook', method: 'POST', data: { a: 1 } }, { resolver: resolverReturning('93.184.216.34') });
|
|
394
|
+
expect(response.status).toBe(200);
|
|
395
|
+
expect(instanceRequest).toHaveBeenCalledTimes(1);
|
|
396
|
+
expect(instanceRequest.mock.calls[0][0]).toMatchObject({
|
|
397
|
+
url: 'https://cdn.example.com/hook',
|
|
398
|
+
method: 'POST',
|
|
399
|
+
data: { a: 1 },
|
|
400
|
+
maxRedirects: 0,
|
|
401
|
+
proxy: false,
|
|
402
|
+
});
|
|
403
|
+
expect(globalRequest).not.toHaveBeenCalled();
|
|
404
|
+
});
|
|
405
|
+
it('does not call the instance when the URL is refused', async () => {
|
|
406
|
+
const instanceRequest = jest.fn();
|
|
407
|
+
const instance = { request: instanceRequest };
|
|
408
|
+
await expect((0, safe_url_util_1.safeAxiosInstanceRequest)(instance, { url: 'http://169.254.169.254/latest/', method: 'POST' }, { resolver: resolverReturning('8.8.8.8') })).rejects.toBeInstanceOf(safe_url_util_1.UnsafeDestinationError);
|
|
409
|
+
expect(instanceRequest).not.toHaveBeenCalled();
|
|
410
|
+
});
|
|
411
|
+
it('follows redirects through the instance too', async () => {
|
|
412
|
+
const instanceRequest = jest
|
|
413
|
+
.fn()
|
|
414
|
+
.mockRejectedValueOnce(redirectError('https://other.example.com/final'))
|
|
415
|
+
.mockResolvedValueOnce(okResponse('final'));
|
|
416
|
+
const instance = { request: instanceRequest };
|
|
417
|
+
const response = await (0, safe_url_util_1.safeAxiosInstanceRequest)(instance, { url: 'https://cdn.example.com/x' }, { resolver: resolverReturning('93.184.216.34') });
|
|
418
|
+
expect(response.data).toBe('final');
|
|
419
|
+
expect(instanceRequest).toHaveBeenCalledTimes(2);
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
describe('one resolution, one pinned address (ADR-0168)', () => {
|
|
423
|
+
const connectThroughLookup = (resolver) => {
|
|
424
|
+
const connectedTo = [];
|
|
425
|
+
jest.spyOn(axios_1.default, 'request').mockImplementation((async (config) => {
|
|
426
|
+
const hostname = new URL(config.url).hostname;
|
|
427
|
+
const addresses = config.lookup
|
|
428
|
+
? await lookupThrough(config.lookup, hostname)
|
|
429
|
+
: await resolver(hostname);
|
|
430
|
+
connectedTo.push(addresses[0].address);
|
|
431
|
+
return okResponse();
|
|
432
|
+
}));
|
|
433
|
+
return connectedTo;
|
|
434
|
+
};
|
|
435
|
+
it('resolves the name once per attempt', async () => {
|
|
436
|
+
const resolver = resolverReturning('93.184.216.34');
|
|
437
|
+
const connectedTo = connectThroughLookup(resolver);
|
|
438
|
+
await (0, safe_url_util_1.safeAxiosRequest)({ url: 'https://cdn.example.com/hook', method: 'POST' }, { resolver });
|
|
439
|
+
expect(resolver).toHaveBeenCalledTimes(1);
|
|
440
|
+
expect(connectedTo).toEqual(['93.184.216.34']);
|
|
441
|
+
});
|
|
442
|
+
it('connects to the validated address even if the name then rebinds to a private one', async () => {
|
|
443
|
+
const resolver = jest
|
|
444
|
+
.fn()
|
|
445
|
+
.mockResolvedValueOnce([{ address: '93.184.216.34' }])
|
|
446
|
+
.mockResolvedValue([{ address: '10.0.0.7' }]);
|
|
447
|
+
const connectedTo = connectThroughLookup(resolver);
|
|
448
|
+
await (0, safe_url_util_1.safeAxiosRequest)({ url: 'https://rebind.example/hook', method: 'POST' }, { resolver });
|
|
449
|
+
expect(connectedTo).toEqual(['93.184.216.34']);
|
|
450
|
+
});
|
|
451
|
+
it('pins each hop to the addresses validated for that hop', async () => {
|
|
452
|
+
const resolver = jest.fn(async (hostname) => hostname === 'cdn.example.com' ? [{ address: '93.184.216.34' }] : [{ address: '1.1.1.1' }]);
|
|
453
|
+
const lookups = [];
|
|
454
|
+
jest.spyOn(axios_1.default, 'request').mockImplementation((async (config) => {
|
|
455
|
+
const hostname = new URL(config.url).hostname;
|
|
456
|
+
lookups.push({ hostname, addresses: await lookupThrough(config.lookup, hostname) });
|
|
457
|
+
if (hostname === 'cdn.example.com') {
|
|
458
|
+
throw redirectError('https://other.example.com/final');
|
|
459
|
+
}
|
|
460
|
+
return okResponse('final');
|
|
461
|
+
}));
|
|
462
|
+
await (0, safe_url_util_1.safeAxiosRequest)({ url: 'https://cdn.example.com/x', method: 'GET' }, { resolver });
|
|
463
|
+
expect(resolver).toHaveBeenCalledTimes(2);
|
|
464
|
+
expect(lookups).toEqual([
|
|
465
|
+
{ hostname: 'cdn.example.com', addresses: [{ address: '93.184.216.34', family: 4 }] },
|
|
466
|
+
{ hostname: 'other.example.com', addresses: [{ address: '1.1.1.1', family: 4 }] },
|
|
467
|
+
]);
|
|
468
|
+
});
|
|
469
|
+
it("does not let a caller's lookup replace the guard's pin", async () => {
|
|
470
|
+
const resolver = resolverReturning('93.184.216.34');
|
|
471
|
+
const connectedTo = connectThroughLookup(resolver);
|
|
472
|
+
const callerLookup = jest.fn((_hostname, _options, cb) => cb(null, [{ address: '10.0.0.7' }]));
|
|
473
|
+
await (0, safe_url_util_1.safeAxiosRequest)({
|
|
474
|
+
url: 'https://cdn.example.com/hook',
|
|
475
|
+
method: 'POST',
|
|
476
|
+
lookup: callerLookup,
|
|
477
|
+
}, { resolver });
|
|
478
|
+
expect(callerLookup).not.toHaveBeenCalled();
|
|
479
|
+
expect(connectedTo).toEqual(['93.184.216.34']);
|
|
480
|
+
});
|
|
481
|
+
it('disables any proxy along with the pin, even one passed by the caller', async () => {
|
|
482
|
+
const resolver = resolverReturning('93.184.216.34');
|
|
483
|
+
connectThroughLookup(resolver);
|
|
484
|
+
await (0, safe_url_util_1.safeAxiosRequest)({
|
|
485
|
+
url: 'https://cdn.example.com/hook',
|
|
486
|
+
method: 'POST',
|
|
487
|
+
proxy: { protocol: 'http', host: 'proxy.internal', port: 3128 },
|
|
488
|
+
}, { resolver });
|
|
489
|
+
expect(axios_1.default.request.mock.calls[0][0].proxy).toBe(false);
|
|
490
|
+
});
|
|
491
|
+
it('sets no pin under the development exception, which validates nothing', async () => {
|
|
492
|
+
(0, test_env_util_1.setTestEnv)(safe_url_util_1.ALLOW_PRIVATE_OUTBOUND_TARGETS_ENV, 'true');
|
|
493
|
+
const request = jest.spyOn(axios_1.default, 'request').mockResolvedValueOnce(okResponse());
|
|
494
|
+
await (0, safe_url_util_1.safeAxiosRequest)({ url: 'http://127.0.0.1:3000/hook' });
|
|
495
|
+
expect(request.mock.calls[0][0].lookup).toBeUndefined();
|
|
496
|
+
expect(request.mock.calls[0][0].proxy).toBeUndefined();
|
|
497
|
+
});
|
|
498
|
+
});
|
|
499
|
+
describe('pinnedLookup', () => {
|
|
500
|
+
it('answers with the validated addresses for their host', async () => {
|
|
501
|
+
const lookup = (0, safe_url_util_1.pinnedLookup)('cdn.example.com', [{ address: '93.184.216.34', family: 4 }]);
|
|
502
|
+
await expect(lookupThrough(lookup, 'cdn.example.com')).resolves.toEqual([
|
|
503
|
+
{ address: '93.184.216.34', family: 4 },
|
|
504
|
+
]);
|
|
505
|
+
});
|
|
506
|
+
it('refuses to resolve any other name', async () => {
|
|
507
|
+
const lookup = (0, safe_url_util_1.pinnedLookup)('cdn.example.com', [{ address: '93.184.216.34', family: 4 }]);
|
|
508
|
+
await expect(lookupThrough(lookup, 'internal.example')).rejects.toThrow('Refusing to resolve internal.example: only cdn.example.com was validated');
|
|
509
|
+
});
|
|
510
|
+
it('pinnedLookupConfig strips the brackets of an IPv6 host', async () => {
|
|
511
|
+
const config = (0, safe_url_util_1.pinnedLookupConfig)({
|
|
512
|
+
url: new URL('https://[2606:4700:4700::1111]/x'),
|
|
513
|
+
addresses: [{ address: '2606:4700:4700::1111', family: 6 }],
|
|
514
|
+
});
|
|
515
|
+
expect(config.proxy).toBe(false);
|
|
516
|
+
await expect(lookupThrough(config.lookup, '2606:4700:4700::1111')).resolves.toEqual([{ address: '2606:4700:4700::1111', family: 6 }]);
|
|
517
|
+
});
|
|
518
|
+
});
|
|
519
|
+
describe('redirect policy', () => {
|
|
520
|
+
const SIGNATURE = 'hmac-of-the-body';
|
|
521
|
+
const CUSTOM_SIGNATURE_HEADER = 'X-Customer-Signature';
|
|
522
|
+
const CLIENT_HOST_HEADER = 'internal.client.example';
|
|
523
|
+
const DELIVERY_TAG = 'delivery-4b7e';
|
|
524
|
+
const callerHeaders = () => ({
|
|
525
|
+
'Content-Type': 'application/json',
|
|
526
|
+
'Content-Length': '42',
|
|
527
|
+
Authorization: 'Bearer recipient-secret',
|
|
528
|
+
Cookie: 'session=recipient',
|
|
529
|
+
[FORM_SIGNATURE_HEADER]: SIGNATURE,
|
|
530
|
+
[MONITOR_SIGNATURE_HEADER]: SIGNATURE,
|
|
531
|
+
[CUSTOM_SIGNATURE_HEADER]: SIGNATURE,
|
|
532
|
+
Host: CLIENT_HOST_HEADER,
|
|
533
|
+
'X-Delivery-Tag': DELIVERY_TAG,
|
|
534
|
+
});
|
|
535
|
+
const sentConfig = (index) => axios_1.default.request.mock.calls[index][0];
|
|
536
|
+
const deliverThroughRedirect = async (location, status = 302, method = 'POST', options = {}) => {
|
|
537
|
+
jest
|
|
538
|
+
.spyOn(axios_1.default, 'request')
|
|
539
|
+
.mockRejectedValueOnce(redirectError(location, status))
|
|
540
|
+
.mockResolvedValueOnce(okResponse('delivered'));
|
|
541
|
+
await (0, safe_url_util_1.safeAxiosRequest)({
|
|
542
|
+
url: 'https://client.example/hook',
|
|
543
|
+
method,
|
|
544
|
+
data: { deliveryId: 'delivery-id' },
|
|
545
|
+
headers: callerHeaders(),
|
|
546
|
+
}, {
|
|
547
|
+
resolver: resolverReturning('93.184.216.34'),
|
|
548
|
+
confidentialHeaders: [CUSTOM_SIGNATURE_HEADER.toLowerCase()],
|
|
549
|
+
...options,
|
|
550
|
+
});
|
|
551
|
+
};
|
|
552
|
+
it('sends the first request with the caller headers untouched', async () => {
|
|
553
|
+
await deliverThroughRedirect('https://attacker.example/collect', 307);
|
|
554
|
+
expect(sentConfig(0).headers).toEqual(callerHeaders());
|
|
555
|
+
});
|
|
556
|
+
it('drops Authorization, Cookie, every signature and the caller confidential header on a hop to another host', async () => {
|
|
557
|
+
await deliverThroughRedirect('https://attacker.example/collect', 307);
|
|
558
|
+
const headers = sentConfig(1).headers;
|
|
559
|
+
expect(headers.Authorization).toBeUndefined();
|
|
560
|
+
expect(headers.Cookie).toBeUndefined();
|
|
561
|
+
expect(headers[FORM_SIGNATURE_HEADER]).toBeUndefined();
|
|
562
|
+
expect(headers[MONITOR_SIGNATURE_HEADER]).toBeUndefined();
|
|
563
|
+
expect(headers[CUSTOM_SIGNATURE_HEADER]).toBeUndefined();
|
|
564
|
+
expect(headers.Host).toBeUndefined();
|
|
565
|
+
expect(headers['X-Delivery-Tag']).toBe(DELIVERY_TAG);
|
|
566
|
+
});
|
|
567
|
+
it('keeps the confidential headers on a hop to a subdomain, but still drops Host', async () => {
|
|
568
|
+
await deliverThroughRedirect('https://api.client.example/hook', 307);
|
|
569
|
+
const headers = sentConfig(1).headers;
|
|
570
|
+
expect(headers.Authorization).toBe('Bearer recipient-secret');
|
|
571
|
+
expect(headers.Cookie).toBe('session=recipient');
|
|
572
|
+
expect(headers[FORM_SIGNATURE_HEADER]).toBe(SIGNATURE);
|
|
573
|
+
expect(headers[CUSTOM_SIGNATURE_HEADER]).toBe(SIGNATURE);
|
|
574
|
+
expect(headers.Host).toBeUndefined();
|
|
575
|
+
});
|
|
576
|
+
it('drops Host on a hop to the same host and keeps the signature', async () => {
|
|
577
|
+
await deliverThroughRedirect('/hook-v2', 307);
|
|
578
|
+
expect(sentConfig(1).headers.Host).toBeUndefined();
|
|
579
|
+
expect(sentConfig(1).headers[FORM_SIGNATURE_HEADER]).toBe(SIGNATURE);
|
|
580
|
+
});
|
|
581
|
+
it('drops the confidential headers on a protocol downgrade to the same host', async () => {
|
|
582
|
+
await deliverThroughRedirect('http://client.example/hook', 307);
|
|
583
|
+
expect(sentConfig(1).headers.Authorization).toBeUndefined();
|
|
584
|
+
expect(sentConfig(1).headers[FORM_SIGNATURE_HEADER]).toBeUndefined();
|
|
585
|
+
});
|
|
586
|
+
it('does not treat a lookalike suffix as a subdomain', async () => {
|
|
587
|
+
await deliverThroughRedirect('https://evilclient.example/hook', 307);
|
|
588
|
+
expect(sentConfig(1).headers[FORM_SIGNATURE_HEADER]).toBeUndefined();
|
|
589
|
+
});
|
|
590
|
+
it.each([303, 302])('turns a POST into a GET without body nor content-* on a %s', async (status) => {
|
|
591
|
+
await deliverThroughRedirect('/hook-v2', status);
|
|
592
|
+
expect(sentConfig(0).method).toBe('POST');
|
|
593
|
+
expect(sentConfig(0).data).toEqual({ deliveryId: 'delivery-id' });
|
|
594
|
+
const next = sentConfig(1);
|
|
595
|
+
expect(next.method).toBe('GET');
|
|
596
|
+
expect(next.data).toBeUndefined();
|
|
597
|
+
expect(next.headers['Content-Type']).toBeUndefined();
|
|
598
|
+
expect(next.headers['Content-Length']).toBeUndefined();
|
|
599
|
+
expect(next.headers['X-Delivery-Tag']).toBe(DELIVERY_TAG);
|
|
600
|
+
});
|
|
601
|
+
it('keeps the method, the body and its Content-Type on a 307', async () => {
|
|
602
|
+
await deliverThroughRedirect('/hook-v2', 307);
|
|
603
|
+
const next = sentConfig(1);
|
|
604
|
+
expect(next.method).toBe('POST');
|
|
605
|
+
expect(next.data).toEqual({ deliveryId: 'delivery-id' });
|
|
606
|
+
expect(next.headers['Content-Type']).toBe('application/json');
|
|
607
|
+
});
|
|
608
|
+
it('never brings a dropped body back at a later hop', async () => {
|
|
609
|
+
jest
|
|
610
|
+
.spyOn(axios_1.default, 'request')
|
|
611
|
+
.mockRejectedValueOnce(redirectError('/second', 303))
|
|
612
|
+
.mockRejectedValueOnce(redirectError('/third', 307))
|
|
613
|
+
.mockResolvedValueOnce(okResponse());
|
|
614
|
+
await (0, safe_url_util_1.safeAxiosRequest)({ url: 'https://client.example/hook', method: 'POST', data: { a: 1 } }, { resolver: resolverReturning('93.184.216.34') });
|
|
615
|
+
expect(sentConfig(2).method).toBe('GET');
|
|
616
|
+
expect(sentConfig(2).data).toBeUndefined();
|
|
617
|
+
});
|
|
618
|
+
describe('requestForRedirect', () => {
|
|
619
|
+
const from = new URL('https://client.example/hook');
|
|
620
|
+
it('turns a POST into a GET on a 301', () => {
|
|
621
|
+
expect((0, safe_url_util_1.requestForRedirect)({ headers: {}, method: 'POST' }, from, from, 301)).toEqual({
|
|
622
|
+
headers: {},
|
|
623
|
+
method: 'GET',
|
|
624
|
+
sendsBody: false,
|
|
625
|
+
});
|
|
626
|
+
});
|
|
627
|
+
it('keeps a PUT on a 302, which only normalises a POST', () => {
|
|
628
|
+
expect((0, safe_url_util_1.requestForRedirect)({ headers: {}, method: 'PUT' }, from, from, 302).method).toBe('PUT');
|
|
629
|
+
});
|
|
630
|
+
it('turns a PUT into a GET on a 303', () => {
|
|
631
|
+
expect((0, safe_url_util_1.requestForRedirect)({ headers: {}, method: 'PUT' }, from, from, 303).method).toBe('GET');
|
|
632
|
+
});
|
|
633
|
+
it('matches the caller confidential headers case-insensitively', () => {
|
|
634
|
+
const next = (0, safe_url_util_1.requestForRedirect)({ headers: { 'x-customer-signature': 's', Accept: 'json' }, method: 'GET' }, from, new URL('https://attacker.example/'), 307, ['X-Customer-Signature']);
|
|
635
|
+
expect(next.headers).toEqual({ Accept: 'json' });
|
|
636
|
+
});
|
|
637
|
+
});
|
|
638
|
+
});
|
|
639
|
+
describe('isOutboundDeadlineError', () => {
|
|
640
|
+
it.each([
|
|
641
|
+
['ECONNABORTED', 'timeout of 2000ms exceeded'],
|
|
642
|
+
['ECONNABORTED', 'Request aborted'],
|
|
643
|
+
['ETIMEDOUT', 'timeout of 2000ms exceeded'],
|
|
644
|
+
['ETIMEDOUT', 'Outbound deadline of 8000ms exceeded'],
|
|
645
|
+
['ERR_CANCELED', 'canceled'],
|
|
646
|
+
])('is true for an axios error %s "%s" without response', (code, message) => {
|
|
647
|
+
expect((0, safe_url_util_1.isOutboundDeadlineError)(new axios_1.AxiosError(message, code))).toBe(true);
|
|
648
|
+
});
|
|
649
|
+
it.each(['', 'connect ETIMEDOUT 104.21.76.245:443', 'connect ETIMEDOUT cdn.example.com'])('is false for a connection that could not be opened (ETIMEDOUT "%s")', (message) => {
|
|
650
|
+
expect((0, safe_url_util_1.isOutboundDeadlineError)(new axios_1.AxiosError(message, 'ETIMEDOUT'))).toBe(false);
|
|
651
|
+
});
|
|
652
|
+
it('is false with a response, another code, or a non-axios error', () => {
|
|
653
|
+
const answered = new axios_1.AxiosError('timeout of 2000ms exceeded', 'ETIMEDOUT', undefined, undefined, {
|
|
654
|
+
status: 504,
|
|
655
|
+
headers: {},
|
|
656
|
+
});
|
|
657
|
+
expect((0, safe_url_util_1.isOutboundDeadlineError)(answered)).toBe(false);
|
|
658
|
+
expect((0, safe_url_util_1.isOutboundDeadlineError)(new axios_1.AxiosError('x', 'ECONNREFUSED'))).toBe(false);
|
|
659
|
+
expect((0, safe_url_util_1.isOutboundDeadlineError)(new Error('ETIMEDOUT'))).toBe(false);
|
|
660
|
+
});
|
|
661
|
+
});
|
|
662
|
+
describe('connection agents', () => {
|
|
663
|
+
const sentConfig = async (send, config) => {
|
|
664
|
+
const request = jest.spyOn(axios_1.default, 'request').mockResolvedValue(okResponse());
|
|
665
|
+
await send(config);
|
|
666
|
+
return request.mock.calls[0][0];
|
|
667
|
+
};
|
|
668
|
+
const viaGlobal = (config) => (0, safe_url_util_1.safeAxiosRequest)(config, { resolver: resolverReturning('93.184.216.34') });
|
|
669
|
+
it('gives every address SAFE_CONNECT_ATTEMPT_TIMEOUT_MS, for http and https', async () => {
|
|
670
|
+
const sent = await sentConfig(viaGlobal, { url: 'https://cdn.example.com/hook' });
|
|
671
|
+
expect(safe_url_util_1.SAFE_CONNECT_ATTEMPT_TIMEOUT_MS).toBe(2000);
|
|
672
|
+
expect(sent.httpsAgent).toBeInstanceOf(https.Agent);
|
|
673
|
+
expect(sent.httpAgent).toBeInstanceOf(http.Agent);
|
|
674
|
+
for (const agent of [sent.httpsAgent, sent.httpAgent]) {
|
|
675
|
+
expect(agentOptions(agent)).toMatchObject({
|
|
676
|
+
autoSelectFamilyAttemptTimeout: 2000,
|
|
677
|
+
keepAlive: true,
|
|
678
|
+
scheduling: 'lifo',
|
|
679
|
+
timeout: 5000,
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
});
|
|
683
|
+
it('keeps the agent the caller passes with the call', async () => {
|
|
684
|
+
const callerAgent = new https.Agent();
|
|
685
|
+
const sent = await sentConfig(viaGlobal, {
|
|
686
|
+
url: 'https://cdn.example.com/hook',
|
|
687
|
+
httpsAgent: callerAgent,
|
|
688
|
+
});
|
|
689
|
+
expect(sent.httpsAgent).toBe(callerAgent);
|
|
690
|
+
expect(sent.httpAgent).toBeUndefined();
|
|
691
|
+
});
|
|
692
|
+
it("keeps the agent of the caller's instance", async () => {
|
|
693
|
+
const callerAgent = new https.Agent();
|
|
694
|
+
const instance = axios_1.default.create({ httpsAgent: callerAgent });
|
|
695
|
+
const instanceRequest = jest.spyOn(instance, 'request').mockResolvedValue(okResponse());
|
|
696
|
+
await (0, safe_url_util_1.safeAxiosInstanceRequest)(instance, { url: 'https://cdn.example.com/hook' }, { resolver: resolverReturning('93.184.216.34') });
|
|
697
|
+
expect(instanceRequest.mock.calls[0][0].httpsAgent).toBeUndefined();
|
|
698
|
+
expect(instanceRequest.mock.calls[0][0].httpAgent).toBeUndefined();
|
|
699
|
+
});
|
|
700
|
+
});
|
|
701
|
+
describe('real HTTP', () => {
|
|
702
|
+
let server;
|
|
703
|
+
let port;
|
|
704
|
+
let baseUrl;
|
|
705
|
+
let handler;
|
|
706
|
+
beforeAll(async () => {
|
|
707
|
+
server = http.createServer((req, res) => handler(req, res));
|
|
708
|
+
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
|
|
709
|
+
port = server.address().port;
|
|
710
|
+
baseUrl = `http://127.0.0.1:${port}`;
|
|
711
|
+
});
|
|
712
|
+
afterAll(async () => {
|
|
713
|
+
server.closeAllConnections();
|
|
714
|
+
await new Promise((resolve) => server.close(() => resolve()));
|
|
715
|
+
});
|
|
716
|
+
describe('address pinning with the exception disarmed', () => {
|
|
717
|
+
it('connects to the pinned address while Host keeps the name', async () => {
|
|
718
|
+
let receivedHost;
|
|
719
|
+
handler = (req, res) => {
|
|
720
|
+
receivedHost = req.headers.host;
|
|
721
|
+
res.writeHead(200, { 'content-type': 'text/plain' }).end('pinned');
|
|
722
|
+
};
|
|
723
|
+
const response = await axios_1.default.get(`http://pinned.invalid:${port}/ok`, {
|
|
724
|
+
lookup: (0, safe_url_util_1.pinnedLookup)('pinned.invalid', [{ address: '127.0.0.1', family: 4 }]),
|
|
725
|
+
proxy: false,
|
|
726
|
+
});
|
|
727
|
+
expect(response.data).toBe('pinned');
|
|
728
|
+
expect(receivedHost).toBe(`pinned.invalid:${port}`);
|
|
729
|
+
});
|
|
730
|
+
it('refuses a connection to a name the pin did not validate', async () => {
|
|
731
|
+
let reached = false;
|
|
732
|
+
handler = (_req, res) => {
|
|
733
|
+
reached = true;
|
|
734
|
+
res.writeHead(200).end();
|
|
735
|
+
};
|
|
736
|
+
await expect(axios_1.default.get(`http://other.invalid:${port}/ok`, {
|
|
737
|
+
lookup: (0, safe_url_util_1.pinnedLookup)('pinned.invalid', [{ address: '127.0.0.1', family: 4 }]),
|
|
738
|
+
proxy: false,
|
|
739
|
+
})).rejects.toThrow('Refusing to resolve other.invalid: only pinned.invalid was validated');
|
|
740
|
+
expect(reached).toBe(false);
|
|
741
|
+
});
|
|
742
|
+
it('refuses the local server itself through the guard', async () => {
|
|
743
|
+
let reached = false;
|
|
744
|
+
handler = (_req, res) => {
|
|
745
|
+
reached = true;
|
|
746
|
+
res.writeHead(200).end();
|
|
747
|
+
};
|
|
748
|
+
const error = await captureError((0, safe_url_util_1.safeAxiosGet)(`${baseUrl}/ok`));
|
|
749
|
+
expect(error.reason).toBe(safe_url_util_1.UnsafeDestinationReason.PRIVATE_ADDRESS);
|
|
750
|
+
expect(reached).toBe(false);
|
|
751
|
+
});
|
|
752
|
+
});
|
|
753
|
+
const redirectChain = (delayMs, last) => {
|
|
754
|
+
handler = (req, res) => {
|
|
755
|
+
const n = Number((req.url ?? '').split('/')[2]);
|
|
756
|
+
setTimeout(() => {
|
|
757
|
+
if (n >= last) {
|
|
758
|
+
res.writeHead(200, { 'content-type': 'text/plain' }).end('final');
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
761
|
+
res.writeHead(302, { location: `/hop/${n + 1}` }).end();
|
|
762
|
+
}, delayMs);
|
|
763
|
+
};
|
|
764
|
+
};
|
|
765
|
+
const variants = [
|
|
766
|
+
['safeAxiosRequest', (config, options) => (0, safe_url_util_1.safeAxiosRequest)(config, options)],
|
|
767
|
+
[
|
|
768
|
+
'safeAxiosInstanceRequest',
|
|
769
|
+
(config, options) => (0, safe_url_util_1.safeAxiosInstanceRequest)(axios_1.default.create(), config, options),
|
|
770
|
+
],
|
|
771
|
+
];
|
|
772
|
+
describe.each(variants)('total deadline through %s', (_name, send) => {
|
|
773
|
+
beforeEach(() => {
|
|
774
|
+
(0, test_env_util_1.setTestEnv)(safe_url_util_1.ALLOW_PRIVATE_OUTBOUND_TARGETS_ENV, 'true');
|
|
775
|
+
});
|
|
776
|
+
it('fails a slow redirect chain at the attempt deadline with ETIMEDOUT', async () => {
|
|
777
|
+
redirectChain(150, 5);
|
|
778
|
+
const onSettled = jest.fn();
|
|
779
|
+
const startedAt = Date.now();
|
|
780
|
+
const error = (await captureError(send({ url: `${baseUrl}/hop/0`, timeout: 400 }, { onSettled })));
|
|
781
|
+
expect(error.code).toBe('ETIMEDOUT');
|
|
782
|
+
expect(error.response).toBeUndefined();
|
|
783
|
+
expect(error.message).toBe('Outbound deadline of 400ms exceeded');
|
|
784
|
+
expect((0, safe_url_util_1.isOutboundDeadlineError)(error)).toBe(true);
|
|
785
|
+
expect(Date.now() - startedAt).toBeLessThan(400 + 300);
|
|
786
|
+
expect(onSettled).toHaveBeenCalledTimes(1);
|
|
787
|
+
expect(onSettled.mock.calls[0][0].hops).toBeGreaterThanOrEqual(1);
|
|
788
|
+
});
|
|
789
|
+
it('cuts a drip-fed response at the deadline', async () => {
|
|
790
|
+
handler = (_req, res) => {
|
|
791
|
+
res.writeHead(200, { 'content-type': 'text/plain' });
|
|
792
|
+
const drip = setInterval(() => res.write('.'), 50);
|
|
793
|
+
res.on('close', () => clearInterval(drip));
|
|
794
|
+
};
|
|
795
|
+
const startedAt = Date.now();
|
|
796
|
+
const error = (await captureError(send({ url: `${baseUrl}/drip`, timeout: 300 })));
|
|
797
|
+
expect(error.code).toBe('ETIMEDOUT');
|
|
798
|
+
expect(Date.now() - startedAt).toBeLessThan(300 + 300);
|
|
799
|
+
});
|
|
800
|
+
it('cuts a DNS resolution that never answers at the deadline', async () => {
|
|
801
|
+
(0, test_env_util_1.setTestEnv)(safe_url_util_1.ALLOW_PRIVATE_OUTBOUND_TARGETS_ENV, undefined);
|
|
802
|
+
const resolver = hangingResolver();
|
|
803
|
+
const onSettled = jest.fn();
|
|
804
|
+
const startedAt = Date.now();
|
|
805
|
+
const error = (await captureError(send({ url: 'https://silent-dns.example/cron', timeout: 200 }, { resolver, onSettled })));
|
|
806
|
+
expect(resolver).toHaveBeenCalledWith('silent-dns.example');
|
|
807
|
+
expect(error.code).toBe('ETIMEDOUT');
|
|
808
|
+
expect(error.message).toBe('Outbound deadline of 200ms exceeded');
|
|
809
|
+
expect(Date.now() - startedAt).toBeLessThan(200 + 300);
|
|
810
|
+
expect(onSettled).toHaveBeenCalledWith({ hops: 0, durationMs: expect.any(Number) });
|
|
811
|
+
});
|
|
812
|
+
it('succeeds in one healthy hop', async () => {
|
|
813
|
+
handler = (_req, res) => res.writeHead(200, { 'content-type': 'text/plain' }).end('ok');
|
|
814
|
+
const onSettled = jest.fn();
|
|
815
|
+
const response = await send({ url: `${baseUrl}/ok` }, { onSettled });
|
|
816
|
+
expect(response.data).toBe('ok');
|
|
817
|
+
expect(onSettled).toHaveBeenCalledWith({ hops: 0, durationMs: expect.any(Number) });
|
|
818
|
+
});
|
|
819
|
+
it('succeeds through redirects under the deadline and counts its hops', async () => {
|
|
820
|
+
redirectChain(20, 2);
|
|
821
|
+
const onSettled = jest.fn();
|
|
822
|
+
const response = await send({ url: `${baseUrl}/hop/0`, timeout: 2000 }, { onSettled });
|
|
823
|
+
expect(response.data).toBe('final');
|
|
824
|
+
expect(onSettled.mock.calls[0][0].hops).toBe(2);
|
|
825
|
+
});
|
|
826
|
+
it('refuses beyond 5 real redirects', async () => {
|
|
827
|
+
handler = (req, res) => res.writeHead(302, { location: `${req.url}/x` }).end();
|
|
828
|
+
const error = await captureError(send({ url: `${baseUrl}/loop`, timeout: 2000 }));
|
|
829
|
+
expect(error.reason).toBe(safe_url_util_1.UnsafeDestinationReason.TOO_MANY_REDIRECTS);
|
|
830
|
+
});
|
|
831
|
+
it('keeps a cancellation by the caller signal an ERR_CANCELED', async () => {
|
|
832
|
+
handler = () => undefined;
|
|
833
|
+
const controller = new AbortController();
|
|
834
|
+
setTimeout(() => controller.abort(), 50);
|
|
835
|
+
const error = (await captureError(send({ url: `${baseUrl}/pending`, timeout: 2000, signal: controller.signal })));
|
|
836
|
+
expect(error.code).toBe('ERR_CANCELED');
|
|
837
|
+
expect(error.message).not.toMatch(/Outbound deadline/);
|
|
838
|
+
});
|
|
839
|
+
it('lets the caller signal interrupt a DNS resolution that never answers', async () => {
|
|
840
|
+
(0, test_env_util_1.setTestEnv)(safe_url_util_1.ALLOW_PRIVATE_OUTBOUND_TARGETS_ENV, undefined);
|
|
841
|
+
const controller = new AbortController();
|
|
842
|
+
setTimeout(() => controller.abort(), 50);
|
|
843
|
+
const startedAt = Date.now();
|
|
844
|
+
const error = (await captureError(send({ url: 'https://silent-dns.example/cron', timeout: 2000, signal: controller.signal }, { resolver: hangingResolver() })));
|
|
845
|
+
expect(error.code).toBe('ERR_CANCELED');
|
|
846
|
+
expect(Date.now() - startedAt).toBeLessThan(50 + 300);
|
|
847
|
+
});
|
|
848
|
+
it('removes its listener from the caller signal once the attempt is over', async () => {
|
|
849
|
+
handler = (_req, res) => res.writeHead(200, { 'content-type': 'text/plain' }).end('ok');
|
|
850
|
+
const controller = new AbortController();
|
|
851
|
+
const add = jest.spyOn(controller.signal, 'addEventListener');
|
|
852
|
+
const remove = jest.spyOn(controller.signal, 'removeEventListener');
|
|
853
|
+
await send({ url: `${baseUrl}/ok`, signal: controller.signal });
|
|
854
|
+
expect(add).toHaveBeenCalledTimes(1);
|
|
855
|
+
expect(remove).toHaveBeenCalledWith('abort', add.mock.calls[0][1]);
|
|
856
|
+
});
|
|
857
|
+
});
|
|
858
|
+
describe('deadline details', () => {
|
|
859
|
+
beforeEach(() => {
|
|
860
|
+
(0, test_env_util_1.setTestEnv)(safe_url_util_1.ALLOW_PRIVATE_OUTBOUND_TARGETS_ENV, 'true');
|
|
861
|
+
});
|
|
862
|
+
it('does not cut a stream after its headers: the deadline stops at the response', async () => {
|
|
863
|
+
handler = (_req, res) => {
|
|
864
|
+
res.writeHead(200, { 'content-type': 'application/octet-stream' });
|
|
865
|
+
let sent = 0;
|
|
866
|
+
const chunks = setInterval(() => {
|
|
867
|
+
sent += 1;
|
|
868
|
+
res.write(`chunk${sent};`);
|
|
869
|
+
if (sent === 8) {
|
|
870
|
+
clearInterval(chunks);
|
|
871
|
+
res.end();
|
|
872
|
+
}
|
|
873
|
+
}, 100);
|
|
874
|
+
res.on('close', () => clearInterval(chunks));
|
|
875
|
+
};
|
|
876
|
+
const response = await (0, safe_url_util_1.safeAxiosRequest)({
|
|
877
|
+
url: `${baseUrl}/stream`,
|
|
878
|
+
responseType: 'stream',
|
|
879
|
+
timeout: 300,
|
|
880
|
+
});
|
|
881
|
+
let body = '';
|
|
882
|
+
for await (const chunk of response.data) {
|
|
883
|
+
body += chunk.toString();
|
|
884
|
+
}
|
|
885
|
+
expect(body).toBe(Array.from({ length: 8 }, (_, index) => `chunk${index + 1};`).join(''));
|
|
886
|
+
});
|
|
887
|
+
it.each(['ECONNABORTED', 'ETIMEDOUT'])('turns a hop inactivity timeout (%s, no response) into the deadline error, without the headers', async (code) => {
|
|
888
|
+
jest
|
|
889
|
+
.spyOn(axios_1.default, 'request')
|
|
890
|
+
.mockRejectedValueOnce(new axios_1.AxiosError('timeout of 2000ms exceeded', code));
|
|
891
|
+
const error = (await captureError((0, safe_url_util_1.safeAxiosRequest)({
|
|
892
|
+
url: `${baseUrl}/idle`,
|
|
893
|
+
timeout: 2000,
|
|
894
|
+
headers: { Authorization: 'Bearer secret' },
|
|
895
|
+
})));
|
|
896
|
+
expect(error.code).toBe('ETIMEDOUT');
|
|
897
|
+
expect(error.message).toBe('Outbound deadline of 2000ms exceeded');
|
|
898
|
+
expect(error.config?.url).toBe(`${baseUrl}/idle`);
|
|
899
|
+
expect(error.config?.headers.Authorization).toBeUndefined();
|
|
900
|
+
});
|
|
901
|
+
it('keeps a connection failure as it is and names the host when Node left the message empty', async () => {
|
|
902
|
+
jest.spyOn(axios_1.default, 'request').mockRejectedValueOnce(new axios_1.AxiosError('', 'ETIMEDOUT'));
|
|
903
|
+
const error = (await captureError((0, safe_url_util_1.safeAxiosRequest)({ url: `${baseUrl}/idle`, timeout: 2000 })));
|
|
904
|
+
expect(error.code).toBe('ETIMEDOUT');
|
|
905
|
+
expect(error.message).toBe(`connect ETIMEDOUT 127.0.0.1:${port}`);
|
|
906
|
+
expect((0, safe_url_util_1.isOutboundDeadlineError)(error)).toBe(false);
|
|
907
|
+
});
|
|
908
|
+
it('keeps the message Node gave to a connection failure', async () => {
|
|
909
|
+
jest
|
|
910
|
+
.spyOn(axios_1.default, 'request')
|
|
911
|
+
.mockRejectedValueOnce(new axios_1.AxiosError(`connect ECONNREFUSED 127.0.0.1:${port}`, 'ECONNREFUSED'));
|
|
912
|
+
const error = (await captureError((0, safe_url_util_1.safeAxiosRequest)({ url: `${baseUrl}/idle`, timeout: 2000 })));
|
|
913
|
+
expect(error.code).toBe('ECONNREFUSED');
|
|
914
|
+
expect(error.message).toBe(`connect ECONNREFUSED 127.0.0.1:${port}`);
|
|
915
|
+
});
|
|
916
|
+
it('opens the real connection with SAFE_CONNECT_ATTEMPT_TIMEOUT_MS per address, kept alive', async () => {
|
|
917
|
+
const createConnection = spyOnCreateConnection();
|
|
918
|
+
let connectionHeader;
|
|
919
|
+
handler = (req, res) => {
|
|
920
|
+
connectionHeader = req.headers.connection;
|
|
921
|
+
res.writeHead(200, { 'content-type': 'text/plain' }).end('ok');
|
|
922
|
+
};
|
|
923
|
+
const response = await (0, safe_url_util_1.safeAxiosRequest)({ url: `http://localhost:${port}/ok` });
|
|
924
|
+
expect(response.data).toBe('ok');
|
|
925
|
+
expect(connectionHeader).toBe('keep-alive');
|
|
926
|
+
expect(createConnection).toHaveBeenCalledTimes(1);
|
|
927
|
+
expect(createConnection.mock.calls[0][0]).toMatchObject({
|
|
928
|
+
autoSelectFamilyAttemptTimeout: safe_url_util_1.SAFE_CONNECT_ATTEMPT_TIMEOUT_MS,
|
|
929
|
+
});
|
|
930
|
+
});
|
|
931
|
+
it('hands the pinned lookup to the connection opened by the guard agent', async () => {
|
|
932
|
+
(0, test_env_util_1.setTestEnv)(safe_url_util_1.ALLOW_PRIVATE_OUTBOUND_TARGETS_ENV, undefined);
|
|
933
|
+
const opened = new Error('connection intercepted');
|
|
934
|
+
const createConnection = spyOnCreateConnection().mockImplementation(() => {
|
|
935
|
+
throw opened;
|
|
936
|
+
});
|
|
937
|
+
await captureError((0, safe_url_util_1.safeAxiosRequest)({ url: 'http://pinned.example/hook' }, { resolver: resolverReturning('93.184.216.34') }));
|
|
938
|
+
expect(createConnection).toHaveBeenCalledTimes(1);
|
|
939
|
+
const connectOptions = createConnection.mock.calls[0][0];
|
|
940
|
+
expect(connectOptions.autoSelectFamilyAttemptTimeout).toBe(safe_url_util_1.SAFE_CONNECT_ATTEMPT_TIMEOUT_MS);
|
|
941
|
+
const lookupOf = (hostname) => new Promise((resolve) => connectOptions.lookup?.(hostname, { all: true }, (error, addresses) => resolve({ error, addresses })));
|
|
942
|
+
expect((await lookupOf('pinned.example')).addresses).toEqual([
|
|
943
|
+
{ address: '93.184.216.34', family: 4 },
|
|
944
|
+
]);
|
|
945
|
+
expect((await lookupOf('other.example')).error?.message).toBe('Refusing to resolve other.example: only pinned.example was validated');
|
|
946
|
+
});
|
|
947
|
+
it('honours the deadline passed by the caller', async () => {
|
|
948
|
+
(0, test_env_util_1.setTestEnv)(safe_url_util_1.ALLOW_PRIVATE_OUTBOUND_TARGETS_ENV, undefined);
|
|
949
|
+
const startedAt = Date.now();
|
|
950
|
+
const error = (await captureError((0, safe_url_util_1.safeAxiosRequest)({ url: 'https://silent-dns.example/cron', timeout: 1000 }, { resolver: hangingResolver() })));
|
|
951
|
+
expect(error.message).toBe('Outbound deadline of 1000ms exceeded');
|
|
952
|
+
expect(Date.now() - startedAt).toBeGreaterThanOrEqual(950);
|
|
953
|
+
expect(Date.now() - startedAt).toBeLessThan(1000 + 500);
|
|
954
|
+
});
|
|
955
|
+
});
|
|
956
|
+
});
|
|
957
|
+
});
|
|
958
|
+
describe('safe-url.util — demonstration actors (#662)', () => {
|
|
959
|
+
afterEach(() => {
|
|
960
|
+
jest.restoreAllMocks();
|
|
961
|
+
});
|
|
962
|
+
it('safeAxiosRequest with demo: true makes no request and resolves no host', async () => {
|
|
963
|
+
const requestSpy = jest.spyOn(axios_1.default, 'request');
|
|
964
|
+
const resolver = resolverReturning('93.184.216.34');
|
|
965
|
+
const error = await captureError((0, safe_url_util_1.safeAxiosRequest)({ url: 'https://tiers.example/hook', method: 'POST' }, { resolver, demo: true }));
|
|
966
|
+
expect(error).toBeInstanceOf(demo_outbound_1.DemoOutboundBlockedError);
|
|
967
|
+
expect(requestSpy).not.toHaveBeenCalled();
|
|
968
|
+
expect(resolver).not.toHaveBeenCalled();
|
|
969
|
+
});
|
|
970
|
+
it('safeAxiosGet with demo: true makes no request', async () => {
|
|
971
|
+
const requestSpy = jest.spyOn(axios_1.default, 'request');
|
|
972
|
+
const error = await captureError((0, safe_url_util_1.safeAxiosGet)('https://tiers.example/data', {}, { resolver: resolverReturning('93.184.216.34'), demo: true }));
|
|
973
|
+
expect(error).toBeInstanceOf(demo_outbound_1.DemoOutboundBlockedError);
|
|
974
|
+
expect(requestSpy).not.toHaveBeenCalled();
|
|
975
|
+
});
|
|
976
|
+
it('safeAxiosInstanceRequest with demo: true never drives the instance', async () => {
|
|
977
|
+
const instance = { request: jest.fn() };
|
|
978
|
+
const error = await captureError((0, safe_url_util_1.safeAxiosInstanceRequest)(instance, { url: 'https://tiers.example/hook' }, { resolver: resolverReturning('93.184.216.34'), demo: true }));
|
|
979
|
+
expect(error).toBeInstanceOf(demo_outbound_1.DemoOutboundBlockedError);
|
|
980
|
+
expect(instance.request).not.toHaveBeenCalled();
|
|
981
|
+
});
|
|
982
|
+
it('a call without demo still goes through the chain', async () => {
|
|
983
|
+
(0, test_env_util_1.setTestEnv)(safe_url_util_1.ALLOW_PRIVATE_OUTBOUND_TARGETS_ENV, undefined);
|
|
984
|
+
jest.spyOn(axios_1.default, 'request').mockResolvedValue(okResponse());
|
|
985
|
+
const response = await (0, safe_url_util_1.safeAxiosGet)('https://tiers.example/data', {}, { resolver: resolverReturning('93.184.216.34'), demo: false });
|
|
986
|
+
expect(response.data).toBe('ok');
|
|
987
|
+
});
|
|
988
|
+
});
|
|
989
|
+
//# sourceMappingURL=safe-url.util.spec.js.map
|