Refuse test env fallback to prod when test credentials not configured

Previously, requesting x-environment: test would silently execute on prod
if test credentials weren't set up — risking accidental prod data changes.
Now throws explicit error asking to configure test creds or use prod.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-27 00:11:08 +03:00
parent e9032001bd
commit bd09d7b055
2 changed files with 15 additions and 5 deletions

View File

@@ -86,12 +86,14 @@ export class AqlExecutor {
throw new Error(`AQL database with id ${databaseId} not found or not configured`);
}
// Use test credentials when environment is test and test env is configured
let baseUrl = dbConfig.aql_base_url;
let authValue = dbConfig.aql_auth_value;
let headers_config = dbConfig.aql_headers;
if (environment === 'test' && dbConfig.has_test_env) {
if (environment === 'test') {
if (!dbConfig.has_test_env) {
throw new Error(`Test environment not configured for AQL database ${databaseId}. Configure test credentials or use prod environment.`);
}
if (dbConfig.test_aql_base_url) baseUrl = dbConfig.test_aql_base_url;
if (dbConfig.test_aql_auth_value) authValue = dbConfig.test_aql_auth_value;
if (dbConfig.test_aql_headers) headers_config = dbConfig.test_aql_headers;
@@ -255,8 +257,11 @@ export class AqlExecutor {
}
let testUrl = dbConfig.aql_base_url;
if (environment === 'test' && dbConfig.has_test_env && dbConfig.test_aql_base_url) {
testUrl = dbConfig.test_aql_base_url;
if (environment === 'test') {
if (!dbConfig.has_test_env) {
return { success: false, error: 'Test environment not configured for this AQL database' };
}
if (dbConfig.test_aql_base_url) testUrl = dbConfig.test_aql_base_url;
}
if (!testUrl) {

View File

@@ -125,7 +125,12 @@ class DatabasePoolManager {
getPool(databaseId: string, environment: Environment = 'prod'): Pool | undefined {
const entry = this.pools.get(databaseId);
if (!entry) return undefined;
if (environment === 'test' && entry.test) return entry.test;
if (environment === 'test') {
if (!entry.test) {
throw new Error(`Test environment not configured for database ${databaseId}. Configure test credentials or use prod environment.`);
}
return entry.test;
}
return entry.prod;
}