fix: 修复 API 前缀下的管理端鉴权绕过
This commit is contained in:
1 parent
3ae7b462f5
commit
476e3d93dd
2 files changed
+37
-6
No files matched your search
@@ -21,6 +21,32 @@ before(async () => {
|
||||
await app.init();
|
||||
});
|
||||
|
||||
test("admin routes remain guarded when an API prefix is configured", async () => {
|
||||
process.env.API_PREFIX = "api";
|
||||
try {
|
||||
const prefixedApp = await createApp();
|
||||
await prefixedApp.init();
|
||||
const injected = prefixedApp.getHttpAdapter().getInstance();
|
||||
const missingAuth = await injected.inject({ method: "GET", url: "/api/admin/bookings" });
|
||||
assert.equal(missingAuth.statusCode, 401);
|
||||
const customerAuth = await injected.inject({
|
||||
method: "GET",
|
||||
url: "/api/admin/bookings",
|
||||
headers: { authorization: `Bearer ${customerToken}` },
|
||||
});
|
||||
assert.equal(customerAuth.statusCode, 403);
|
||||
const login = await injected.inject({
|
||||
method: "POST",
|
||||
url: "/api/admin/session/login",
|
||||
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
|
||||
});
|
||||
assert.equal(login.statusCode, 201);
|
||||
await prefixedApp.close();
|
||||
} finally {
|
||||
process.env.API_PREFIX = "";
|
||||
}
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await app.close();
|
||||
await prisma.brandRelease.deleteMany({ where: { brandId } });
|
||||
|
||||
Reference in new issue
Block a user