feat: 接通后台渲染异常上报与响应契约校验
This commit is contained in:
1 parent
330d67adc1
commit
adcaa12970
22 files changed
+845
-33
No files matched your search
@@ -1892,6 +1892,42 @@ async function request(url, options = {}) {
|
||||
});
|
||||
}
|
||||
|
||||
test("admin client error reports are authenticated, validated, and deduplicated", async () => {
|
||||
await assertProtectedRouteBoundary("/admin/client-errors", {
|
||||
method: "POST",
|
||||
payload: { errorId: "admin-boundary-check", message: "boom", route: "/admin/publication" },
|
||||
});
|
||||
|
||||
const login = await request("/admin/session/login", {
|
||||
method: "POST",
|
||||
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||
});
|
||||
assert.equal(login.statusCode, 201);
|
||||
const headers = { authorization: `Bearer ${sessionToken(login)}` };
|
||||
const errorId = `admin-it-${Date.now().toString(36)}`;
|
||||
const payload = {
|
||||
errorId,
|
||||
message: "Cannot read properties of null (reading 'type')",
|
||||
route: "/admin/trust?tab=1",
|
||||
componentStack: "at TrustContentPage",
|
||||
};
|
||||
|
||||
const first = await request("/admin/client-errors", { method: "POST", headers, payload });
|
||||
assert.equal(first.statusCode, 201);
|
||||
assert.deepEqual(JSON.parse(first.body), { received: true, duplicate: false });
|
||||
|
||||
const duplicate = await request("/admin/client-errors", { method: "POST", headers, payload });
|
||||
assert.equal(duplicate.statusCode, 201);
|
||||
assert.deepEqual(JSON.parse(duplicate.body), { received: true, duplicate: true });
|
||||
|
||||
const invalid = await request("/admin/client-errors", {
|
||||
method: "POST",
|
||||
headers,
|
||||
payload: { errorId: "bad", message: "", route: "no-slash" },
|
||||
});
|
||||
assert.equal(invalid.statusCode, 400);
|
||||
});
|
||||
|
||||
async function assertProtectedRouteBoundary(url, options = {}) {
|
||||
const { method = "GET", payload, forbiddenRole = "customer", headers = {} } = options;
|
||||
const requestOptions = payload === undefined ? { method, headers } : { method, headers, payload };
|
||||
|
||||
Reference in new issue
Block a user