DNS setup: a domain's own valid DMARC or SPF counts as done (#239) #240
No files matched your search
@@ -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<ZoneRecord, LiveState> }) {
|
||||
function RecordTable({ records, states }: { records: ZoneRecord[]; states?: Map<ZoneRecord, RecordState> }) {
|
||||
return (
|
||||
<div className="mt-3 overflow-x-auto rounded-xl border">
|
||||
<table className="w-full table-fixed text-left text-xs">
|
||||
@@ -1062,6 +1064,15 @@ function LiveStep({
|
||||
</div>
|
||||
)}
|
||||
{!nothingToPublish && <RecordTable records={records} states={states} />}
|
||||
{records.some((r) => states.get(r) === 'valid') && (
|
||||
<p className="text-xs text-muted-foreground">
|
||||
<BadgeCheck className="mr-1 inline h-3.5 w-3.5 text-emerald-500" />
|
||||
{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.',
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
{records.some((r) => states.get(r) === 'different') && (
|
||||
<p className="text-xs text-muted-foreground">
|
||||
<AlertTriangle className="mr-1 inline h-3.5 w-3.5 text-highlight" />
|
||||
|
||||
@@ -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') && (
|
||||
<p className="text-xs text-muted-foreground">
|
||||
<BadgeCheck className="mr-1 inline h-3.5 w-3.5 text-emerald-500" />
|
||||
{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.',
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
{records.some((r) => states.get(r) === 'different') && (
|
||||
<p className="text-xs text-muted-foreground">
|
||||
<AlertTriangle className="mr-1 inline h-3.5 w-3.5 text-highlight" />
|
||||
|
||||
@@ -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 <CheckCircle2 className="h-4 w-4 text-emerald-500 animate-in zoom-in" />;
|
||||
case 'valid': {
|
||||
const label = t('dnsWizard.ownValid', 'Your own record, valid');
|
||||
return (
|
||||
<span role="img" aria-label={label} title={label}>
|
||||
<BadgeCheck className="h-4 w-4 text-emerald-500" />
|
||||
</span>
|
||||
);
|
||||
}
|
||||
case 'different':
|
||||
return <AlertTriangle className="h-4 w-4 text-highlight" />;
|
||||
case 'error':
|
||||
|
||||
@@ -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:[email protected]');
|
||||
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:[email protected]'] }]]);
|
||||
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:[email protected]'] }],
|
||||
]);
|
||||
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');
|
||||
});
|
||||
});
|
||||
@@ -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<ZoneRecord, LiveResult>): Map<ZoneRecord, RecordState> {
|
||||
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';
|
||||
}
|
||||
@@ -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<Map<ZoneRecord, LiveState>>(new Map());
|
||||
const [states, setStates] = useState<Map<ZoneRecord, RecordState>>(new Map());
|
||||
const [task, setTask] = useState<DnsTask | null | undefined>(undefined);
|
||||
const [checking, setChecking] = useState(false);
|
||||
const [lastChecked, setLastChecked] = useState<Date | null>(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,
|
||||
|
||||
+3
-1
@@ -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",
|
||||
|
||||
Reference in new issue
Block a user