mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-07 18:42:25 +00:00
fix(testing): use UUIDs for Telegram credential leases
This commit is contained in:
@@ -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(),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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()}`
|
||||
|
||||
Reference in New Issue
Block a user