fix(testing): use UUIDs for Telegram credential leases

This commit is contained in:
Vincent Koc
2026-06-17 15:46:44 +02:00
parent d98394a865
commit aaa73a5ba2
2 changed files with 21 additions and 2 deletions

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env -S node --import tsx
// Telegram User Credential script supports OpenClaw repository automation.
import { createHash } from "node:crypto";
import { createHash, randomUUID } from "node:crypto";
import { copyFile, mkdir, mkdtemp, readFile, rm, unlink, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
@@ -224,6 +224,10 @@ async function postBroker(params: {
return payload;
}
export function buildTelegramUserCredentialOwnerId() {
return `telegram-user-${randomUUID()}`;
}
async function resolveConvexLeaseConfig(opts: Map<string, string>) {
const envFile = opts.get("env-file") || DEFAULT_CONVEX_ENV_FILE;
const fileEnv = await readEnvFile(envFile);
@@ -259,7 +263,7 @@ async function resolveConvexLeaseConfig(opts: Map<string, string>) {
ownerId:
opts.get("owner-id") ||
process.env.OPENCLAW_QA_CREDENTIAL_OWNER_ID?.trim() ||
`telegram-user-${Date.now()}-${Math.random().toString(16).slice(2, 10)}`,
buildTelegramUserCredentialOwnerId(),
};
}

View File

@@ -118,6 +118,21 @@ describe("telegram user credential path handling", () => {
});
describe("telegram user credential IO", () => {
it("uses collision-resistant generated credential lease owner IDs", async () => {
const credentialModule = (await import(
`${new URL("../../scripts/e2e/telegram-user-credential.ts", import.meta.url).href}?case=owner-id-${Date.now()}`
)) as {
buildTelegramUserCredentialOwnerId(): string;
};
expect(credentialModule.buildTelegramUserCredentialOwnerId()).toMatch(
/^telegram-user-[0-9a-f-]{36}$/u,
);
expect(readFileSync("scripts/e2e/telegram-user-credential.ts", "utf8")).not.toContain(
"telegram-user-${Date.now()}-${Math.random()",
);
});
it("rejects oversized chunked lease payload markers before hydration", async () => {
const credentialModule = (await import(
`${new URL("../../scripts/e2e/telegram-user-credential.ts", import.meta.url).href}?case=chunk-marker-${Date.now()}`