fix: trust proxy headers and align proxy file mysql indexes
This commit is contained in:
@@ -85,4 +85,25 @@ describe('buildConfig', () => {
|
|||||||
expect(response.json()).toEqual({ textLength: largeText.length });
|
expect(response.json()).toEqual({ textLength: largeText.length });
|
||||||
await app.close();
|
await app.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('trusts forwarded client IP headers for reverse-proxy deployments', async () => {
|
||||||
|
const app = Fastify(buildFastifyOptions(buildConfig({})));
|
||||||
|
|
||||||
|
app.get('/ip', async (request) => ({
|
||||||
|
ip: request.ip,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const response = await app.inject({
|
||||||
|
method: 'GET',
|
||||||
|
url: '/ip',
|
||||||
|
remoteAddress: '10.0.0.8',
|
||||||
|
headers: {
|
||||||
|
'x-forwarded-for': '203.0.113.5, 10.0.0.8',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(response.statusCode).toBe(200);
|
||||||
|
expect(response.json()).toEqual({ ip: '203.0.113.5' });
|
||||||
|
await app.close();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -137,6 +137,7 @@ export function buildFastifyOptions(
|
|||||||
): FastifyServerOptions {
|
): FastifyServerOptions {
|
||||||
return {
|
return {
|
||||||
logger: true,
|
logger: true,
|
||||||
|
trustProxy: true,
|
||||||
bodyLimit: appConfig.requestBodyLimit,
|
bodyLimit: appConfig.requestBodyLimit,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,19 @@ describe('ensureProxyFileSchemaCompatibility', () => {
|
|||||||
expect(executedSql.some((sqlText) => ownerIndexPattern.test(sqlText))).toBe(true);
|
expect(executedSql.some((sqlText) => ownerIndexPattern.test(sqlText))).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('emits MySQL indexes compatible with generated bootstrap SQL', async () => {
|
||||||
|
const { inspector, executedSql } = createInspector('mysql');
|
||||||
|
|
||||||
|
await ensureProxyFileSchemaCompatibility(inspector);
|
||||||
|
|
||||||
|
expect(executedSql).toContain(
|
||||||
|
'CREATE UNIQUE INDEX `proxy_files_public_id_unique` ON `proxy_files` (`public_id`(191))',
|
||||||
|
);
|
||||||
|
expect(executedSql).toContain(
|
||||||
|
'CREATE INDEX `proxy_files_owner_lookup_idx` ON `proxy_files` (`owner_type`(191), `owner_id`(191), `deleted_at`)',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('adds missing columns on existing table before ensuring indexes', async () => {
|
it('adds missing columns on existing table before ensuring indexes', async () => {
|
||||||
const { inspector, executedSql } = createInspector('postgres', {
|
const { inspector, executedSql } = createInspector('postgres', {
|
||||||
hasTable: true,
|
hasTable: true,
|
||||||
|
|||||||
@@ -127,8 +127,8 @@ const CREATE_INDEX_SQL: Record<ProxyFileSchemaDialect, string[]> = {
|
|||||||
'CREATE INDEX IF NOT EXISTS "proxy_files_owner_lookup_idx" ON "proxy_files" ("owner_type", "owner_id", "deleted_at")',
|
'CREATE INDEX IF NOT EXISTS "proxy_files_owner_lookup_idx" ON "proxy_files" ("owner_type", "owner_id", "deleted_at")',
|
||||||
],
|
],
|
||||||
mysql: [
|
mysql: [
|
||||||
'CREATE UNIQUE INDEX `proxy_files_public_id_unique` ON `proxy_files` (`public_id`)',
|
'CREATE UNIQUE INDEX `proxy_files_public_id_unique` ON `proxy_files` (`public_id`(191))',
|
||||||
'CREATE INDEX `proxy_files_owner_lookup_idx` ON `proxy_files` (`owner_type`, `owner_id`)',
|
'CREATE INDEX `proxy_files_owner_lookup_idx` ON `proxy_files` (`owner_type`(191), `owner_id`(191), `deleted_at`)',
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user