mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 23:18:28 +00:00
test(web): dedupe logout fixture setup and cover non-legacy oauth removal
This commit is contained in:
@@ -30,6 +30,16 @@ describe("web logout", () => {
|
|||||||
return dir;
|
return dir;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const createAuthCase = async (files: Record<string, string>) => {
|
||||||
|
const authDir = await makeCaseDir();
|
||||||
|
await Promise.all(
|
||||||
|
Object.entries(files).map(async ([name, contents]) => {
|
||||||
|
await fsPromises.writeFile(path.join(authDir, name), contents, "utf-8");
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
return authDir;
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
});
|
});
|
||||||
@@ -39,8 +49,18 @@ describe("web logout", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("deletes cached credentials when present", { timeout: 60_000 }, async () => {
|
it("deletes cached credentials when present", { timeout: 60_000 }, async () => {
|
||||||
const authDir = await makeCaseDir();
|
const authDir = await createAuthCase({ "creds.json": "{}" });
|
||||||
fs.writeFileSync(path.join(authDir, "creds.json"), "{}");
|
const result = await logoutWeb({ authDir, runtime: runtime as never });
|
||||||
|
expect(result).toBe(true);
|
||||||
|
expect(fs.existsSync(authDir)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("removes oauth.json too when not using legacy auth dir", async () => {
|
||||||
|
const authDir = await createAuthCase({
|
||||||
|
"creds.json": "{}",
|
||||||
|
"oauth.json": '{"token":true}',
|
||||||
|
"session-abc.json": "{}",
|
||||||
|
});
|
||||||
const result = await logoutWeb({ authDir, runtime: runtime as never });
|
const result = await logoutWeb({ authDir, runtime: runtime as never });
|
||||||
expect(result).toBe(true);
|
expect(result).toBe(true);
|
||||||
expect(fs.existsSync(authDir)).toBe(false);
|
expect(fs.existsSync(authDir)).toBe(false);
|
||||||
@@ -54,10 +74,11 @@ describe("web logout", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("keeps shared oauth.json when using legacy auth dir", async () => {
|
it("keeps shared oauth.json when using legacy auth dir", async () => {
|
||||||
const credsDir = await makeCaseDir();
|
const credsDir = await createAuthCase({
|
||||||
fs.writeFileSync(path.join(credsDir, "creds.json"), "{}");
|
"creds.json": "{}",
|
||||||
fs.writeFileSync(path.join(credsDir, "oauth.json"), '{"token":true}');
|
"oauth.json": '{"token":true}',
|
||||||
fs.writeFileSync(path.join(credsDir, "session-abc.json"), "{}");
|
"session-abc.json": "{}",
|
||||||
|
});
|
||||||
|
|
||||||
const result = await logoutWeb({
|
const result = await logoutWeb({
|
||||||
authDir: credsDir,
|
authDir: credsDir,
|
||||||
|
|||||||
Reference in New Issue
Block a user