[grade=C urn:ump:meylbfvzagdtgff4oapeyqkvjmletbb6q7iul5suvwcw5gq66wxa] fix(ux): invalid explicit DNS ports are REJECTED, not silently defaulted

Deploy judge r1 (dc-prod-deploy-dns2-full, grade C) blocked on the
serialiser silently replacing an invalid explicit port (9090junk/0/-1/
70000) with the provider default — pointing the adapter at the wrong
service instead of reporting the user's typo. Now: empty field →
provider default (legitimate); invalid EXPLICIT value → buildDnsConfig
throws with an actionable message; the wizard surfaces it via
showNotification and aborts the save. Tests flipped to pin the
reject-not-fallback contract (throw + empty-field default preserved).
This commit is contained in:
Hermes committed 2026-11-19 13:21:25 -08:00
1 parent 9cff937e7c
commit 3d6856a795
5 files changed
+146 -129

No files matched your search

+13 -10
View File
@@ -17,23 +17,26 @@
function normalizePort(rawPort) {
var s = String(rawPort == null ? '' : rawPort).trim();
if (!/^\d{1,5}$/.test(s)) return null; // full-string digits only (no "9090junk")
if (s === '') return null; // empty → caller applies provider default
if (!/^\d{1,5}$/.test(s)) return { error: true };
var n = parseInt(s, 10);
return n >= 1 && n <= 65535 ? n : null; // valid TCP/UDP range
if (!(n >= 1 && n <= 65535)) return { error: true };
return n;
}
/**
* Build the config.dns object from the wizard's DNS provider step.
*
* @param {string} selectedProvider - technitium|cloudflare|powerdns|rfc2136|manual
* @param {string} ip - server IP from the form
* @param {string} rawPort - raw port field (may be empty/whitespace)
* @param {string} token - API key / TSIG-adjacent secret from the form
* @param {number} defaultDnsPort - legacy generic default (Technitium API, 5380)
* @returns {Object} config.dns — generic fields PLUS provider-specific aliases
* Throws on an INVALID EXPLICIT port — a typo like "9090junk" must be
* reported to the user, never silently swapped for a default (the default
* would point the adapter at the wrong service).
*/
function buildDnsConfig(selectedProvider, ip, rawPort, token, defaultDnsPort) {
var portRaw = normalizePort(rawPort);
var resolved = normalizePort(rawPort);
if (resolved && resolved.error) {
throw new Error('Invalid port "' + String(rawPort).trim() + '" for the ' +
selectedProvider + ' provider — enter a whole number between 1 and 65535.');
}
var portRaw = resolved; // null = field left empty
var providerDefault = PROVIDER_PORT_DEFAULTS[selectedProvider] || null;
// explicit input > provider default > legacy generic default
var port = portRaw != null ? portRaw : (providerDefault || defaultDnsPort);
+28 -15
View File
@@ -77,13 +77,19 @@ window.populateTimezoneSelect = function(selectEl, selectedTz) {
const tld = document.getElementById('setup-tld')?.value?.trim() || '.home';
const caName = document.getElementById('setup-ca-name')?.value?.trim() || '';
const dnsIP = document.getElementById('setup-dns-ip')?.value?.trim() || '';
const dnsPort = DnsProviderConfig.buildDnsConfig(
document.getElementById('setup-dns-provider')?.value || 'technitium',
dnsIP,
document.getElementById('setup-dns-port')?.value?.trim() || '',
'',
DC.DEFAULTS.DNS_PORT,
).port;
const dnsPort = (() => {
try {
return DnsProviderConfig.buildDnsConfig(
document.getElementById('setup-dns-provider')?.value || 'technitium',
dnsIP,
document.getElementById('setup-dns-port')?.value?.trim() || '',
'',
DC.DEFAULTS.DNS_PORT,
).port;
} catch (e) {
return document.getElementById('setup-dns-port')?.value?.trim() || DC.DEFAULTS.DNS_PORT;
}
})();
html += `
<div>
@@ -184,14 +190,21 @@ window.populateTimezoneSelect = function(selectEl, selectedTz) {
// Serialisation extracted to js/dns-provider-config.js (shared with
// the backend parity tests) so the wizard→builder mapping is the
// exact code the tests exercise: per-provider port defaults and
// provider-specific field aliases live there.
config.dns = DnsProviderConfig.buildDnsConfig(
selectedProvider,
document.getElementById('setup-dns-ip')?.value?.trim() || '',
document.getElementById('setup-dns-port')?.value?.trim() || '',
document.getElementById('setup-dns-token')?.value?.trim() || '',
DC.DEFAULTS.DNS_PORT,
);
// provider-specific field aliases live there. An invalid explicit
// port THROWS — surface it and abort the save (never silently
// substitute a default that would point at the wrong service).
try {
config.dns = DnsProviderConfig.buildDnsConfig(
selectedProvider,
document.getElementById('setup-dns-ip')?.value?.trim() || '',
document.getElementById('setup-dns-port')?.value?.trim() || '',
document.getElementById('setup-dns-token')?.value?.trim() || '',
DC.DEFAULTS.DNS_PORT,
);
} catch (e) {
showNotification(e.message, 'error', 6000);
return;
}
config.defaults = {
dnsType: 'private',
sslType: 'internal',