From 0e04c5bd9dcfee3c7c002d21af56b8572e0f6d8f Mon Sep 17 00:00:00 2001 From: John Coffey Date: Wed, 18 Nov 2026 11:33:19 -0700 Subject: [PATCH] DNS setup: a domain's own valid DMARC or SPF counts as done (#239) The DNS setup pages marked every published record that wasn't exactly the suggested one as different, in amber, with a note about old records in caches, and never reached "All set". A DMARC with the domain's own report addresses, or an SPF with an extra include, is neither: the admin chose it and it's valid. The pages now judge DMARC and SPF with coreState from #237. A single well-formed record of the domain's own gets a green badge ("Your own record, valid"), counts toward the progress and "All set", and a note says it can stay. The amber mark and its caching note stay for records that really differ: two SPF records, a DMARC with no policy, an MX or DKIM key elsewhere. --- src/features/dns/ConnectDnsPage.tsx | 15 ++++++- src/features/dns/CopyStep.tsx | 11 ++++- src/features/dns/parts.tsx | 16 +++++-- src/features/dns/recordState.test.ts | 65 ++++++++++++++++++++++++++++ src/features/dns/recordState.ts | 34 +++++++++++++++ src/features/dns/useRecordChecks.ts | 10 +++-- src/i18n/en.json | 4 +- 7 files changed, 144 insertions(+), 11 deletions(-) create mode 100644 src/features/dns/recordState.test.ts create mode 100644 src/features/dns/recordState.ts diff --git a/src/features/dns/ConnectDnsPage.tsx b/src/features/dns/ConnectDnsPage.tsx index 5ef0c06..81b80e6 100644 --- a/src/features/dns/ConnectDnsPage.tsx +++ b/src/features/dns/ConnectDnsPage.tsx @@ -9,6 +9,7 @@ import { useNavigate } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { AlertTriangle, + BadgeCheck, ChevronDown, ClipboardCopy, ClipboardList, @@ -37,7 +38,8 @@ import type { JmapSetError, JmapSetResponse } from '@/types/jmap'; import { ADVANCED_FIELDS, FEATURED, HIDDEN_VARIANTS, type ProviderGuide } from './providers'; import { DEFAULT_KINDS, RECORD_GROUPS } from './records'; import { parseZone, summarizeFailure, type RecordKind, type ZoneRecord } from './zone'; -import { RESOLVER_NAME, type LiveState } from './liveCheck'; +import { RESOLVER_NAME } from './liveCheck'; +import type { RecordState } from './recordState'; import { detectHosting, type DnsHosting } from './detect'; import { useRecordChecks } from './useRecordChecks'; import { CopyStep } from './CopyStep'; @@ -917,7 +919,7 @@ function CredentialField({ ); } -function RecordTable({ records, states }: { records: ZoneRecord[]; states?: Map }) { +function RecordTable({ records, states }: { records: ZoneRecord[]; states?: Map }) { return (
@@ -1062,6 +1064,15 @@ function LiveStep({ )} {!nothingToPublish && } + {records.some((r) => states.get(r) === 'valid') && ( +

+ + {t( + 'dnsWizard.ownValidHelp', + 'A green badge means the domain already has a valid record of its own there, so it counts as done. Use the value shown only if you want to change it.', + )} +

+ )} {records.some((r) => states.get(r) === 'different') && (

diff --git a/src/features/dns/CopyStep.tsx b/src/features/dns/CopyStep.tsx index 7c031e5..b186959 100644 --- a/src/features/dns/CopyStep.tsx +++ b/src/features/dns/CopyStep.tsx @@ -6,7 +6,7 @@ import { useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { AlertTriangle, Check, Copy, RefreshCw } from 'lucide-react'; +import { AlertTriangle, BadgeCheck, Check, Copy, RefreshCw } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'; import { WizardNote, WizardShell } from '@/components/wizard/WizardShell'; @@ -190,6 +190,15 @@ export function CopyStep({ ); })} + {records.some((r) => states.get(r) === 'valid') && ( +

+ + {t( + 'dnsWizard.ownValidHelp', + 'A green badge means the domain already has a valid record of its own there, so it counts as done. Use the value shown only if you want to change it.', + )} +

+ )} {records.some((r) => states.get(r) === 'different') && (

diff --git a/src/features/dns/parts.tsx b/src/features/dns/parts.tsx index d27ab7e..49e04da 100644 --- a/src/features/dns/parts.tsx +++ b/src/features/dns/parts.tsx @@ -4,15 +4,25 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -import { AlertTriangle, CheckCircle2, CircleDashed, Loader2, XCircle } from 'lucide-react'; +import { AlertTriangle, BadgeCheck, CheckCircle2, CircleDashed, Loader2, XCircle } from 'lucide-react'; import { cn } from '@/lib/utils'; -import type { LiveState } from './liveCheck'; +import { useTranslation } from 'react-i18next'; +import type { RecordState } from './recordState'; /** One record's state in public DNS, as an icon. */ -export function StateIcon({ state }: { state?: LiveState }) { +export function StateIcon({ state }: { state?: RecordState }) { + const { t } = useTranslation(); switch (state) { case 'live': return ; + case 'valid': { + const label = t('dnsWizard.ownValid', 'Your own record, valid'); + return ( + + + + ); + } case 'different': return ; case 'error': diff --git a/src/features/dns/recordState.test.ts b/src/features/dns/recordState.test.ts new file mode 100644 index 0000000..01a8494 --- /dev/null +++ b/src/features/dns/recordState.test.ts @@ -0,0 +1,65 @@ +/* + * SPDX-FileCopyrightText: 2026 Coffey Labs LLC + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import { describe, expect, it } from 'vitest'; +import type { LiveResult } from './liveCheck'; +import { isDone, recordStates } from './recordState'; +import type { ZoneRecord } from './zone'; + +const rec = (kind: ZoneRecord['kind'], name: string, type: string, value: string) => + ({ kind, name, type, value }) as ZoneRecord; + +const dmarc = rec('dmarc', '_dmarc.example.com.', 'TXT', 'v=DMARC1; p=reject; rua=mailto:postmaster@example.com'); +const spf = rec('spf', 'example.com.', 'TXT', 'v=spf1 mx -all'); +const mx = rec('mx', 'example.com.', 'MX', '10 mail.example.com.'); + +const states = (pairs: [ZoneRecord, LiveResult][]) => + recordStates( + pairs.map(([r]) => r), + new Map(pairs), + ); + +describe('recordStates (#239)', () => { + it('a DMARC of the domain’s own, with its own report addresses, is valid and counts as done', () => { + const s = states([[dmarc, { state: 'different', found: ['v=DMARC1; p=quarantine; rua=mailto:dmarc@example.org'] }]]); + expect(s.get(dmarc)).toBe('valid'); + expect(isDone(s.get(dmarc))).toBe(true); + }); + + it('an SPF with an extra include, next to a site verification, is valid', () => { + const s = states([ + [spf, { state: 'different', found: ['google-site-verification=abc', 'v=spf1 mx include:_spf.example.net -all'] }], + ]); + expect(s.get(spf)).toBe('valid'); + }); + + it('two SPF records, or a DMARC with no policy, still differ', () => { + const s = states([ + [spf, { state: 'different', found: ['v=spf1 mx -all', 'v=spf1 a ~all'] }], + [dmarc, { state: 'different', found: ['v=DMARC1; rua=mailto:dmarc@example.org'] }], + ]); + expect(s.get(spf)).toBe('different'); + expect(s.get(dmarc)).toBe('different'); + expect(isDone(s.get(spf))).toBe(false); + }); + + it('a name with only other TXT records still differs, as a live check says', () => { + const s = states([[spf, { state: 'different', found: ['google-site-verification=abc'] }]]); + expect(s.get(spf)).toBe('different'); + }); + + it('an MX elsewhere differs; live, missing and error pass through', () => { + const s = states([ + [mx, { state: 'different', found: ['10 mx.elsewhere.example.'] }], + [dmarc, { state: 'live', found: [] }], + [spf, { state: 'missing', found: [] }], + ]); + expect(s.get(mx)).toBe('different'); + expect(s.get(dmarc)).toBe('live'); + expect(s.get(spf)).toBe('missing'); + expect(recordStates([mx], new Map()).get(mx)).toBe('error'); + }); +}); diff --git a/src/features/dns/recordState.ts b/src/features/dns/recordState.ts new file mode 100644 index 0000000..4a58b7d --- /dev/null +++ b/src/features/dns/recordState.ts @@ -0,0 +1,34 @@ +/* + * SPDX-FileCopyrightText: 2026 Coffey Labs LLC + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +/** + * Where each record on the DNS setup pages stands. Like a live check, except + * that a DMARC or SPF record of the domain's own, which is well formed, is + * `valid` instead of `different` (#239): the admin chose it, it works, and it + * counts as done. + */ +import { coreState } from '@/features/hovercards/facts'; +import type { LiveResult, LiveState } from './liveCheck'; +import type { ZoneRecord } from './zone'; + +export type RecordState = LiveState | 'valid'; + +export function recordStates(records: ZoneRecord[], results: Map): Map { + return new Map( + records.map((r): [ZoneRecord, RecordState] => { + const result = results.get(r) ?? { state: 'error', found: [] }; + if (result.state === 'different' && (r.kind === 'dmarc' || r.kind === 'spf')) { + if (coreState(r.kind, [result]) === 'valid') return [r, 'valid']; + } + return [r, result.state]; + }), + ); +} + +/** Published and usable: the suggested value, or a valid record of the domain's own. */ +export function isDone(state: RecordState | undefined): boolean { + return state === 'live' || state === 'valid'; +} diff --git a/src/features/dns/useRecordChecks.ts b/src/features/dns/useRecordChecks.ts index 941c1f2..5c00674 100644 --- a/src/features/dns/useRecordChecks.ts +++ b/src/features/dns/useRecordChecks.ts @@ -6,7 +6,8 @@ import { useCallback, useEffect, useRef, useState } from 'react'; import { getAccountId, jmapQueryAndGet } from '@/services/jmap/client'; -import { checkRecords, type LiveState } from './liveCheck'; +import { checkRecordValues } from './liveCheck'; +import { isDone, recordStates, type RecordState } from './recordState'; import type { ZoneRecord } from './zone'; export interface DnsTask { @@ -25,7 +26,7 @@ const GIVE_UP_MS = 10 * 60_000; * domain. `task` is undefined until first read, null when none is queued. */ export function useRecordChecks(records: ZoneRecord[], domainId: string, watchTask: boolean) { - const [states, setStates] = useState>(new Map()); + const [states, setStates] = useState>(new Map()); const [task, setTask] = useState(undefined); const [checking, setChecking] = useState(false); const [lastChecked, setLastChecked] = useState(null); @@ -44,7 +45,7 @@ export function useRecordChecks(records: ZoneRecord[], domainId: string, watchTa setTask(null); } } - setStates(await checkRecords(records)); + setStates(recordStates(records, await checkRecordValues(records))); setLastChecked(new Date()); setChecking(false); }, [domainId, records, watchTask]); @@ -66,7 +67,8 @@ export function useRecordChecks(records: ZoneRecord[], domainId: string, watchTa }; }, [check]); - const liveCount = records.filter((r) => states.get(r) === 'live').length; + // A valid DMARC or SPF of the domain's own counts as done (#239). + const liveCount = records.filter((r) => isDone(states.get(r))).length; return { states, task, diff --git a/src/i18n/en.json b/src/i18n/en.json index 542f0db..1e5071e 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -1080,7 +1080,9 @@ "connectedOnly": "{{domain}} is connected.", "nothingPublished": "No records are written. The server uses your DNS host only to answer DNS-01 challenges when it orders a certificate.", "connectOnlyButton": "Connect", - "happensNoRecords": "{{domain}} switches to automatic DNS, and nothing is written. The server uses the connection only for DNS-01 certificate orders." + "happensNoRecords": "{{domain}} switches to automatic DNS, and nothing is written. The server uses the connection only for DNS-01 certificate orders.", + "ownValidHelp": "A green badge means the domain already has a valid record of its own there, so it counts as done. Use the value shown only if you want to change it.", + "ownValid": "Your own record, valid" }, "dnsCopy": { "copied": "Copied", -- 2.54.0