Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,19 @@ pages.forEach(({ path, template, titleKey }) => {
} catch { extraLocals.pools = []; extraLocals.gatewayPeers = []; }
}

// Settings page: gw-down-threshold is the only server-rendered settings
// value (template reads `settings.gateway_down_threshold_s`). The `settings`
// template var is otherwise never injected, so the slider always showed the
// hardcoded default 90. Inject just that one key (not getAll(), to avoid
// exposing secrets) so the slider reflects the persisted value.
if (template === 'settings') {
try {
extraLocals.settings = {
gateway_down_threshold_s: require('../services/settings').get('gateway_down_threshold_s'),
};
} catch { extraLocals.settings = {}; }
}

// Dashboard-only: gateways that need re-pairing after master-key rotation
if (template === 'dashboard') {
try {
Expand Down
28 changes: 28 additions & 0 deletions tests/gateway_failover_render.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

// The gateway-failover slider is the only server-rendered settings value
// (`value="{{ settings.gateway_down_threshold_s or 90 }}"`). The settings
// template var was never injected into the page render, so the slider always
// showed the hardcoded default 90 regardless of the persisted value — the save
// round-trip looked broken in the UI. This verifies the render reflects the DB.
const crypto = require('crypto');
process.env.GC_ENCRYPTION_KEY = process.env.GC_ENCRYPTION_KEY || crypto.randomBytes(32).toString('hex');
const { test, beforeEach, afterEach } = require('node:test');
const assert = require('node:assert/strict');
const { setup, teardown, getAgent, getCsrf } = require('./helpers/setup');

beforeEach(async () => { await setup(); });
afterEach(teardown);

test('settings page renders the persisted gateway_down_threshold_s on the slider', async () => {
const agent = getAgent();
const csrf = getCsrf();
await agent.put('/api/v1/settings/gateway-failover')
.set('X-CSRF-Token', csrf)
.send({ gateway_down_threshold_s: 150 })
.expect(200);
const page = await agent.get('/settings').expect(200);
// slider must reflect the saved value, not the hardcoded default 90
assert.match(page.text, /id="gw-down-threshold"[^>]*value="150"/);
assert.doesNotMatch(page.text, /id="gw-down-threshold"[^>]*value="90"/);
});
Loading