fix(imports): keep imported products IMVU hides behind a 401
Checked against the live API: the product fields imports use are right, but anonymous callers get 401 alike for Access Pass products, deleted ones and IDs that never existed. The daily recheck treated that as gone, so a product that became AP would have been taken away. A 401 now keeps what was last seen; only a 404 means gone. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
7d708aebdb
commit
b53fb564b4
4 files changed
+44
-9
No files matched your search
@@ -6,17 +6,20 @@ import { openDatabase, type Database } from "@t5de/db";
|
||||
import { createApp } from "../src/app";
|
||||
import { createAuth } from "../src/auth";
|
||||
import { ImvuClient, type ImvuUser } from "../src/imvu";
|
||||
import type { Imports } from "../src/imports";
|
||||
import { twoFactorOn } from "./two-factor";
|
||||
|
||||
const webURL = "http://web.test";
|
||||
const apiURL = "http://api.test";
|
||||
const accounts = new Map<number, ImvuUser>();
|
||||
const imvuProducts = new Map<number, Record<string, unknown>>();
|
||||
const hiddenProducts = new Set<number>(); // answered 401, as IMVU does for Access Pass products
|
||||
const fakeIMVU = (async (input: RequestInfo | URL) => {
|
||||
const url = new URL(String(input));
|
||||
const pm = url.pathname.match(/^\/product\/product-(\d+)$/);
|
||||
if (pm) {
|
||||
const p = imvuProducts.get(Number(pm[1]));
|
||||
if (hiddenProducts.has(Number(pm[1]))) return Response.json({ status: "failure", error: "AUTHENTICATION-005" }, { status: 401 });
|
||||
if (!p) return Response.json({ status: "failure" }, { status: 404 });
|
||||
return Response.json({ denormalized: { [`https://api.imvu.com/product/product-${pm[1]}`]: { data: p } } });
|
||||
}
|
||||
@@ -30,6 +33,7 @@ const fakeIMVU = (async (input: RequestInfo | URL) => {
|
||||
});
|
||||
}) as unknown as typeof fetch;
|
||||
|
||||
let imports: Imports;
|
||||
let db: Database;
|
||||
let close: () => Promise<void>;
|
||||
let base: string;
|
||||
@@ -39,6 +43,7 @@ beforeAll(async () => {
|
||||
({ db, close } = await openDatabase("memory"));
|
||||
const auth = createAuth(db, { apiURL, webURL, secret: "test-secret-test-secret-test-secret-1234", rateLimit: false });
|
||||
const hub = createApp({ db, auth, imvu: new ImvuClient("http://imvu.test", fakeIMVU), apiURL, webURL, catalogHealthy: async () => true });
|
||||
imports = hub.imports;
|
||||
hub.app.listen({ port: 0, hostname: "127.0.0.1" });
|
||||
const server = hub.app.server as unknown as { port: number; stop: () => void };
|
||||
stop = () => server.stop();
|
||||
@@ -200,3 +205,15 @@ test("grants, requests, the importer's jobs, and withdrawal", async () => {
|
||||
expect((await call(maker, "DELETE", "/api/v1/account/links/501")).status).toBe(204);
|
||||
expect((await call(maker, "GET", "/api/v1/imports/grants")).json.grants[0]).toMatchObject({ id: again.json.grant.id, status: "suspended" });
|
||||
});
|
||||
|
||||
test("IMVU's 401 keeps what was last seen; 404 is gone", async () => {
|
||||
imvuProducts.set(9500, imvuProduct("Turned AP", 501));
|
||||
expect(await imports.info(9500, true)).toMatchObject({ found: true, creatorId: 501 });
|
||||
hiddenProducts.add(9500);
|
||||
expect(await imports.info(9500, true)).toMatchObject({ found: true, creatorId: 501, name: "Turned AP" });
|
||||
hiddenProducts.add(9501); // never seen: nothing to keep
|
||||
expect(await imports.info(9501, true)).toBeUndefined();
|
||||
hiddenProducts.delete(9500);
|
||||
imvuProducts.delete(9500);
|
||||
expect(await imports.info(9500, true)).toBeUndefined();
|
||||
});
|
||||
Reference in new issue
Block a user