fix(push): parse APNs relay timeout as strict decimal (#107883)

Co-authored-by: Peter Steinberger <peter@steipete.me>
This commit is contained in:
wahaha1223
2026-07-16 13:37:37 +08:00
committed by GitHub
parent 49410a2399
commit fbc5529fbf
2 changed files with 42 additions and 2 deletions

View File

@@ -107,6 +107,43 @@ describe("push-apns.relay", () => {
});
});
it.each(["0x1000", "2e4", "2500ms"])(
"falls back for non-decimal env timeout %s",
(timeoutMs) => {
const resolved = resolveApnsRelayConfigFromEnv({
OPENCLAW_APNS_RELAY_BASE_URL: "https://relay.example.com",
OPENCLAW_APNS_RELAY_TIMEOUT_MS: timeoutMs,
} as NodeJS.ProcessEnv);
expectRelayConfig(resolved, {
baseUrl: "https://relay.example.com",
timeoutMs: 10_000,
});
},
);
it("retains numeric timeout config values", () => {
const resolved = resolveApnsRelayConfigFromEnv(
{
OPENCLAW_APNS_RELAY_BASE_URL: "https://relay.example.com",
} as NodeJS.ProcessEnv,
{
push: {
apns: {
relay: {
timeoutMs: 2500,
},
},
},
},
);
expectRelayConfig(resolved, {
baseUrl: "https://relay.example.com",
timeoutMs: 2500,
});
});
it("allows loopback http URLs for alternate truthy env values", () => {
const resolved = resolveApnsRelayConfigFromEnv({
OPENCLAW_APNS_RELAY_BASE_URL: "http://[::1]:8787",

View File

@@ -1,6 +1,9 @@
// Sends APNs notifications through the configured relay endpoint.
import { URL } from "node:url";
import { resolveTimerTimeoutMs } from "@openclaw/normalization-core/number-coercion";
import {
parseStrictPositiveInteger,
resolveTimerTimeoutMs,
} from "@openclaw/normalization-core/number-coercion";
import {
normalizeLowercaseStringOrEmpty,
normalizeOptionalString,
@@ -83,7 +86,7 @@ function normalizeTimeoutMs(value: string | number | undefined): number {
if (raw === undefined || raw === "") {
return DEFAULT_APNS_RELAY_TIMEOUT_MS;
}
const parsed = Number(raw);
const parsed = typeof raw === "number" ? raw : parseStrictPositiveInteger(raw);
return resolveTimerTimeoutMs(parsed, DEFAULT_APNS_RELAY_TIMEOUT_MS, 1000);
}