Merge cookie normalization into QQ session renewal

This commit is contained in:
TIANYAO ZHANG committed 2026-11-18 16:43:49 +08:00
commit 9928035282
13 files changed
+342 -20

No files matched your search

+8
View File
@@ -124,6 +124,14 @@ describe("managed QQ authentication routes", () => {
expect(refresh).not.toHaveBeenCalled();
});
it("keeps the current QQ login when an import contains only response attributes", async () => {
const { app, qq } = mount(true);
await request(app).post("/api/auth/cookie")
.send({ platform: "qq", cookie: "Path=/; HttpOnly" })
.expect(400);
expect(qq.setCookie).not.toHaveBeenCalled();
});
it("continues persisting the legacy cookie when the feature is disabled", async () => {
const { app, legacyStore } = mount(false);
await request(app).get("/api/auth/qrcode/status").query({ platform: "qq", key: "legacy" }).expect(200);
+4 -2
View File
@@ -2,6 +2,7 @@ import { Router } from "express";
import type { ParamsDictionary } from "express-serve-static-core";
import type { MusicProvider } from "../../music/provider.js";
import type { QQMusicProvider } from "../../music/qq.js";
import { normalizeCookie } from "../../music/cookie-normalize.js";
import { YouTubeProvider } from "../../music/youtube.js";
import type { CookieStore } from "../../music/auth.js";
import type { Logger } from "../../logger.js";
@@ -190,8 +191,9 @@ export function createAuthRouter(
});
router.post("/cookie", requirePermission("platform.auth"), (req, res) => {
const { platform, cookie } = req.body;
if (typeof cookie !== "string" || !cookie.trim()) {
const { platform, cookie: raw } = req.body;
const cookie = typeof raw === "string" ? normalizeCookie(raw) : "";
if (!cookie) {
res.status(400).json({ error: "cookie is required" });
return;
}