mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 20:41:24 +00:00
fix(pairing): support legacy telegram allowFrom migration
This commit is contained in:
@@ -178,6 +178,42 @@ describe("doctor legacy state migrations", () => {
|
||||
expect(fs.existsSync(path.join(oauthDir, "creds.json"))).toBe(false);
|
||||
});
|
||||
|
||||
it("migrates legacy Telegram pairing allowFrom store to account-scoped default file", async () => {
|
||||
const root = await makeTempRoot();
|
||||
const cfg: OpenClawConfig = {};
|
||||
|
||||
const oauthDir = path.join(root, "credentials");
|
||||
fs.mkdirSync(oauthDir, { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(oauthDir, "telegram-allowFrom.json"),
|
||||
JSON.stringify(
|
||||
{
|
||||
version: 1,
|
||||
allowFrom: ["123456"],
|
||||
},
|
||||
null,
|
||||
2,
|
||||
) + "\n",
|
||||
"utf-8",
|
||||
);
|
||||
|
||||
const detected = await detectLegacyStateMigrations({
|
||||
cfg,
|
||||
env: { OPENCLAW_STATE_DIR: root } as NodeJS.ProcessEnv,
|
||||
});
|
||||
expect(detected.pairingAllowFrom.hasLegacyTelegram).toBe(true);
|
||||
|
||||
const result = await runLegacyStateMigrations({ detected, now: () => 123 });
|
||||
expect(result.warnings).toEqual([]);
|
||||
|
||||
const target = path.join(oauthDir, "telegram-default-allowFrom.json");
|
||||
expect(fs.existsSync(target)).toBe(true);
|
||||
expect(JSON.parse(fs.readFileSync(target, "utf-8"))).toEqual({
|
||||
version: 1,
|
||||
allowFrom: ["123456"],
|
||||
});
|
||||
});
|
||||
|
||||
it("no-ops when nothing detected", async () => {
|
||||
const root = await makeTempRoot();
|
||||
const cfg: OpenClawConfig = {};
|
||||
|
||||
@@ -116,6 +116,11 @@ export const detectLegacyStateMigrations = vi.fn().mockResolvedValue({
|
||||
targetDir: "/tmp/oauth/whatsapp/default",
|
||||
hasLegacy: false,
|
||||
},
|
||||
pairingAllowFrom: {
|
||||
legacyTelegramPath: "/tmp/oauth/telegram-allowFrom.json",
|
||||
targetTelegramPath: "/tmp/oauth/telegram-default-allowFrom.json",
|
||||
hasLegacyTelegram: false,
|
||||
},
|
||||
preview: [],
|
||||
}) as unknown as MockFn;
|
||||
|
||||
@@ -306,6 +311,11 @@ export async function arrangeLegacyStateMigrationTest(): Promise<{
|
||||
targetDir: "/tmp/oauth/whatsapp/default",
|
||||
hasLegacy: false,
|
||||
},
|
||||
pairingAllowFrom: {
|
||||
legacyTelegramPath: "/tmp/oauth/telegram-allowFrom.json",
|
||||
targetTelegramPath: "/tmp/oauth/telegram-default-allowFrom.json",
|
||||
hasLegacyTelegram: false,
|
||||
},
|
||||
preview: ["- Legacy sessions detected"],
|
||||
});
|
||||
runLegacyStateMigrations.mockResolvedValueOnce({
|
||||
|
||||
Reference in New Issue
Block a user