Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): drop a typed password when saving a built-in container

Yudhi Armyndharis2f045dd5c07c
diff --git a/dashboard/src/hooks/useInfraConfigForm.ts b/dashboard/src/hooks/useInfraConfigForm.ts
index 407797a26..273473ce2 100644
--- a/dashboard/src/hooks/useInfraConfigForm.ts
+++ b/dashboard/src/hooks/useInfraConfigForm.ts
@@ -243,7 +243,9 @@ export function useInfraConfigForm(
const setRedisConnected = (connected: boolean) => setRedisConfig(prev => ({ ...prev, connected }));
const buildSavePayload = (): SaveConfigPayload => ({
- database: { ...dbConfig },
+ // A bundled container never receives a typed password (the field is hidden once built-in is on,
+ // but a value typed before the toggle survives in state). '' means "unchanged" on the backend.
+ database: dbConfig.builtIn ? { ...dbConfig, password: '' } : { ...dbConfig },
// `connected` is runtime-only status, not persisted configuration. Keep it out of the
// whitelisted backend DTO so a valid dashboard save cannot be rejected as an unknown field.
redis: {
@@ -251,7 +253,7 @@ export function useInfraConfigForm(
builtIn: redisConfig.builtIn,
host: redisConfig.host,
port: redisConfig.port,
- password: redisConfig.password,
+ password: redisConfig.builtIn ? '' : redisConfig.password,
},
queue: { enabled: queueEnabled },
storage: { ...storageConfig },
diff --git a/dashboard/src/pages/Infrastructure.test.ts b/dashboard/src/pages/Infrastructure.test.ts
index 5b7e18f60..0d7b55f68 100644
--- a/dashboard/src/pages/Infrastructure.test.ts
+++ b/dashboard/src/pages/Infrastructure.test.ts
@@ -355,6 +355,39 @@ test('editing a database field and saving PUTs the edited value in the request b
});
});
+test('a password typed before switching to a built-in container is not saved', async () => {
+ const { screen, waitFor, fireEvent } = rtl;
+ resetFetchCalls();
+ const { container } = renderInfrastructure();
+
+ await screen.findByText('Database Configuration');
+ await waitFor(() => assert.equal(fieldInput(container, 'Username').value, 'openwa_admin'));
+
+ // Typed while external, then the field is hidden by the built-in toggle but its state survives.
+ fireEvent.change(container.querySelector('#infra-4')!, { target: { value: 'typed-db-secret' } });
+ fireEvent.click(toggleInput(container, 'Use Built-in PostgreSQL Container'));
+
+ fireEvent.click(toggleInput(container, 'Enable Redis'));
+ fireEvent.change(container.querySelector('#infra-12')!, { target: { value: 'typed-redis-secret' } });
+ fireEvent.click(toggleInput(container, 'Use Built-in Redis Container'));
+
+ fireEvent.click(screen.getByRole('button', { name: 'Save Configuration' }));
+
+ // The bundled containers never receive a typed password, so '' (unchanged) is what must be sent.
+ await waitFor(() => {
+ const call = findFetchCall('PUT', '/api/infra/config');
+ assert.ok(call, 'expected a PUT to /infra/config');
+ const body = call!.body as {
+ database?: { builtIn?: boolean; password?: string };
+ redis?: { builtIn?: boolean; password?: string };
+ };
+ assert.equal(body.database?.builtIn, true);
+ assert.equal(body.database?.password, '');
+ assert.equal(body.redis?.builtIn, true);
+ assert.equal(body.redis?.password, '');
+ });
+});
+
test('a successful save opens the restart modal', async () => {
const { screen, waitFor, fireEvent, within } = rtl;
resetFetchCalls();