mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 21:45:31 +09:00
fix(api): allow disabling named Postgres prepared statements (#2251)
This commit is contained in:
1 parent
9025e03422
commit
5036ac3efa
10 files changed
+143
-74
No files matched your search
@@ -71,6 +71,7 @@ function defaultConfig(): MasterConfig {
|
||||
ssl_ca: '',
|
||||
max_connections: 20,
|
||||
kv_table: 'fluxer_kv',
|
||||
prepared_statements: true,
|
||||
},
|
||||
},
|
||||
s3: {
|
||||
@@ -356,6 +357,7 @@ function validatePostgresConfig(config: MasterConfig): void {
|
||||
assertIntegerInRange(postgres.max_connections, 'FLUXER_POSTGRES_MAX_CONNECTIONS', 1, 1000);
|
||||
assertBoolean(postgres.ssl, 'FLUXER_POSTGRES_SSL');
|
||||
assertIdentifier(postgres.kv_table, 'FLUXER_POSTGRES_KV_TABLE');
|
||||
assertBoolean(postgres.prepared_statements, 'FLUXER_POSTGRES_PREPARED_STATEMENTS');
|
||||
if (config.env !== 'production' || config.database.backend !== 'postgres') {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ export interface MasterConfig {
|
||||
ssl_ca: string;
|
||||
max_connections: number;
|
||||
kv_table: string;
|
||||
prepared_statements: boolean;
|
||||
};
|
||||
};
|
||||
s3?: {
|
||||
|
||||
@@ -110,6 +110,7 @@ describe('ConfigLoader', () => {
|
||||
FLUXER_POSTGRES_PORT: '5544',
|
||||
FLUXER_POSTGRES_MAX_CONNECTIONS: '7',
|
||||
FLUXER_POSTGRES_SSL_CA: '-----BEGIN CERTIFICATE-----\\n-----END CERTIFICATE-----',
|
||||
FLUXER_POSTGRES_PREPARED_STATEMENTS: 'false',
|
||||
FLUXER_API_WORKER_MODE: 'single_task',
|
||||
FLUXER_API_WORKER_TASK: 'processStripeWebhook',
|
||||
FLUXER_GATEWAY_PUSH_ENABLED: 'false',
|
||||
@@ -127,6 +128,7 @@ describe('ConfigLoader', () => {
|
||||
expect(config.database.postgres.port).toBe(5544);
|
||||
expect(config.database.postgres.max_connections).toBe(7);
|
||||
expect(config.database.postgres.ssl_ca).toBe('-----BEGIN CERTIFICATE-----\\n-----END CERTIFICATE-----');
|
||||
expect(config.database.postgres.prepared_statements).toBe(false);
|
||||
expect(config.services.api.worker?.mode).toBe('single_task');
|
||||
expect(config.services.api.worker?.task).toBe('processStripeWebhook');
|
||||
expect(config.services.gateway.push_enabled).toBe(false);
|
||||
@@ -148,6 +150,16 @@ describe('ConfigLoader', () => {
|
||||
await expect(loadConfig()).rejects.toThrow('FLUXER_POSTGRES_PORT');
|
||||
});
|
||||
|
||||
test('keeps Postgres prepared statements on by default', async () => {
|
||||
stubMinimalEnv();
|
||||
expect((await loadConfig()).database.postgres.prepared_statements).toBe(true);
|
||||
});
|
||||
|
||||
test('rejects a non-boolean Postgres prepared statements value', async () => {
|
||||
stubMinimalEnv({FLUXER_POSTGRES_PREPARED_STATEMENTS: 'maybe'});
|
||||
await expect(loadConfig()).rejects.toThrow('FLUXER_POSTGRES_PREPARED_STATEMENTS');
|
||||
});
|
||||
|
||||
test('rejects unsafe production Postgres defaults', async () => {
|
||||
stubMinimalEnv({FLUXER_ENV: 'production'});
|
||||
await expect(loadConfig()).rejects.toThrow('FLUXER_POSTGRES_HOST');
|
||||
|
||||
@@ -47,6 +47,7 @@ const NAMED_FLUXER_ENV_OVERRIDES: Record<string, NamedEnvOverride> = {
|
||||
FLUXER_POSTGRES_SSL_CA: {path: ['database', 'postgres', 'ssl_ca']},
|
||||
FLUXER_POSTGRES_MAX_CONNECTIONS: {path: ['database', 'postgres', 'max_connections'], parse: parseEnvValue},
|
||||
FLUXER_POSTGRES_KV_TABLE: {path: ['database', 'postgres', 'kv_table']},
|
||||
FLUXER_POSTGRES_PREPARED_STATEMENTS: {path: ['database', 'postgres', 'prepared_statements'], parse: parseEnvValue},
|
||||
FLUXER_DATABASE_BACKEND: {path: ['database', 'backend']},
|
||||
FLUXER_KV_URL: {path: ['internal', 'kv']},
|
||||
FLUXER_INTERNAL_API_ENDPOINT: {path: ['internal', 'api']},
|
||||
|
||||
Reference in new issue
Block a user