mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 10:12:53 +00:00
fix(apns): cap relay timeout
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { generateKeyPairSync } from "node:crypto";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { MAX_TIMER_TIMEOUT_MS } from "../shared/number-coercion.js";
|
||||
import {
|
||||
deriveDeviceIdFromPublicKey,
|
||||
publicKeyRawBase64UrlFromPem,
|
||||
@@ -122,6 +123,18 @@ describe("push-apns.relay", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("caps oversized timeout values before they reach AbortSignal.timeout", () => {
|
||||
const resolved = resolveApnsRelayConfigFromEnv({
|
||||
OPENCLAW_APNS_RELAY_BASE_URL: "https://relay.example.com",
|
||||
OPENCLAW_APNS_RELAY_TIMEOUT_MS: String(Number.MAX_SAFE_INTEGER),
|
||||
} as NodeJS.ProcessEnv);
|
||||
|
||||
expectRelayConfig(resolved, {
|
||||
baseUrl: "https://relay.example.com",
|
||||
timeoutMs: MAX_TIMER_TIMEOUT_MS,
|
||||
});
|
||||
});
|
||||
|
||||
it("allows loopback http URLs for alternate truthy env values", () => {
|
||||
const resolved = resolveApnsRelayConfigFromEnv({
|
||||
OPENCLAW_APNS_RELAY_BASE_URL: "http://[::1]:8787",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { URL } from "node:url";
|
||||
import type { GatewayConfig } from "../config/types.gateway.js";
|
||||
import { resolveTimerTimeoutMs } from "../shared/number-coercion.js";
|
||||
import {
|
||||
normalizeLowercaseStringOrEmpty,
|
||||
normalizeOptionalString,
|
||||
@@ -71,10 +72,7 @@ function normalizeTimeoutMs(value: string | number | undefined): number {
|
||||
return DEFAULT_APNS_RELAY_TIMEOUT_MS;
|
||||
}
|
||||
const parsed = Number(raw);
|
||||
if (!Number.isFinite(parsed)) {
|
||||
return DEFAULT_APNS_RELAY_TIMEOUT_MS;
|
||||
}
|
||||
return Math.max(1000, Math.trunc(parsed));
|
||||
return resolveTimerTimeoutMs(parsed, DEFAULT_APNS_RELAY_TIMEOUT_MS, 1000);
|
||||
}
|
||||
|
||||
function readAllowHttp(value: string | undefined): boolean {
|
||||
|
||||
Reference in New Issue
Block a user