@hogsend/engine 0.63.0 → 0.65.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +13 -12
- package/src/account-links/__fixtures__/fake-fetch.test.ts +57 -0
- package/src/account-links/__fixtures__/fake-fetch.ts +114 -0
- package/src/account-links/__fixtures__/steam.json +21 -0
- package/src/account-links/__fixtures__/twitch.json +22 -0
- package/src/account-links/index.ts +8 -0
- package/src/account-links/steam.test.ts +243 -0
- package/src/account-links/steam.ts +48 -0
- package/src/account-links/twitch.test.ts +157 -0
- package/src/account-links/twitch.ts +99 -0
- package/src/container.account-links.env.test.ts +65 -0
- package/src/container.account-links.halfenv.test.ts +48 -0
- package/src/container.account-links.test.ts +185 -0
- package/src/container.ts +120 -0
- package/src/env.ts +60 -0
- package/src/index.ts +104 -1
- package/src/journeys/journey-boundary.ts +8 -0
- package/src/lib/account-link-emit.ts +126 -0
- package/src/lib/account-link-events.ts +180 -0
- package/src/lib/account-link-hooks.test.ts +158 -0
- package/src/lib/account-link-hooks.ts +73 -0
- package/src/lib/account-link-ingest.ts +364 -0
- package/src/lib/account-link-nonce.test.ts +52 -0
- package/src/lib/account-link-nonce.ts +57 -0
- package/src/lib/account-link-origins.test.ts +72 -0
- package/src/lib/account-link-origins.ts +87 -0
- package/src/lib/account-link-pkce.test.ts +91 -0
- package/src/lib/account-link-pkce.ts +106 -0
- package/src/lib/account-link-provider-registry.test.ts +52 -0
- package/src/lib/account-link-provider-registry.ts +61 -0
- package/src/lib/account-link-throttle.test.ts +178 -0
- package/src/lib/account-link-throttle.ts +130 -0
- package/src/lib/account-link-url.ts +85 -0
- package/src/lib/account-links-emit.test.ts +525 -0
- package/src/lib/account-links-env.test.ts +40 -0
- package/src/lib/account-links-from-env.test.ts +187 -0
- package/src/lib/account-links-from-env.ts +126 -0
- package/src/lib/account-links.ts +1300 -0
- package/src/lib/app-secret.ts +34 -0
- package/src/lib/attachments.ts +81 -0
- package/src/lib/connector-actions.test.ts +13 -4
- package/src/lib/connector-state.account-link.test.ts +114 -0
- package/src/lib/connector-state.ts +48 -3
- package/src/lib/contacts.ts +320 -6
- package/src/lib/domain-status.return-path.test.ts +68 -0
- package/src/lib/domain-status.ts +19 -0
- package/src/lib/email-provider-boot.hogsend.test.ts +48 -0
- package/src/lib/email-provider-boot.test.ts +33 -0
- package/src/lib/email-providers-from-env.hogsend.test.ts +110 -0
- package/src/lib/email-providers-from-env.test.ts +52 -0
- package/src/lib/email-providers-from-env.ts +67 -0
- package/src/lib/email-service-types.ts +11 -0
- package/src/lib/email.ts +17 -0
- package/src/lib/mailer-bounce-idempotency.test.ts +469 -0
- package/src/lib/mailer-rejected.test.ts +229 -0
- package/src/lib/mailer-replied.test.ts +379 -0
- package/src/lib/mailer.ts +359 -24
- package/src/lib/outbound-account-payloads.test.ts +137 -0
- package/src/lib/outbound.ts +126 -0
- package/src/lib/provider-credentials.ts +19 -5
- package/src/lib/sending-domain-guidance.test.ts +99 -0
- package/src/lib/sending-domain-guidance.ts +84 -0
- package/src/lib/tracked-attachments.test.ts +376 -0
- package/src/lib/tracked-idempotency-header.test.ts +437 -0
- package/src/lib/tracked.ts +116 -4
- package/src/lib/tracking-event-names.ts +9 -0
- package/src/lib/webhook-catalog-sync.test.ts +24 -0
- package/src/lib/webhook-signing.ts +25 -1
- package/src/routes/accounts/callback.ts +597 -0
- package/src/routes/accounts/emit.ts +231 -0
- package/src/routes/accounts/import-links.ts +210 -0
- package/src/routes/accounts/index.ts +75 -0
- package/src/routes/accounts/lookup.ts +177 -0
- package/src/routes/accounts/me.ts +215 -0
- package/src/routes/accounts/mint.ts +279 -0
- package/src/routes/accounts/pages.ts +62 -0
- package/src/routes/accounts/resolve.ts +61 -0
- package/src/routes/accounts/serialize.ts +96 -0
- package/src/routes/accounts/shared.ts +107 -0
- package/src/routes/accounts/start.ts +229 -0
- package/src/routes/accounts/unlink.ts +98 -0
- package/src/routes/admin/agent.ts +2 -0
- package/src/routes/admin/api-keys.ts +7 -0
- package/src/routes/admin/contacts.ts +38 -2
- package/src/routes/admin/domain-conflict.test.ts +188 -0
- package/src/routes/admin/domain-return-path.test.ts +274 -0
- package/src/routes/admin/domain.ts +214 -1
- package/src/routes/connectors/index.ts +17 -0
- package/src/routes/contacts/index.ts +8 -0
- package/src/routes/index.ts +75 -0
- package/src/testing-barrel.test.ts +74 -0
- package/src/testing.ts +17 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, test } from "node:test";
|
|
3
|
+
import type {
|
|
4
|
+
DnsRecord,
|
|
5
|
+
DomainStatus,
|
|
6
|
+
DomainsCapability,
|
|
7
|
+
EmailProvider,
|
|
8
|
+
} from "@hogsend/core";
|
|
9
|
+
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
10
|
+
import type { AppEnv } from "../../app.js";
|
|
11
|
+
import { SENDING_DOMAIN_GUIDANCE } from "../../lib/sending-domain-guidance.js";
|
|
12
|
+
import { domainRouter } from "./domain.js";
|
|
13
|
+
|
|
14
|
+
// A provider refusal the OPERATOR can act on must reach them intact.
|
|
15
|
+
//
|
|
16
|
+
// The failure this pins: Hogsend Cloud answers `409 domain_not_owned` when a
|
|
17
|
+
// domain is already claimed by another account, and its message carries the
|
|
18
|
+
// remedy ("an operator must delete the identity in SES…"). Every catch in this
|
|
19
|
+
// router flattened that into a blanket 502 with "domains request to provider
|
|
20
|
+
// failed: …", so Studio rendered an opaque gateway error for a request that was
|
|
21
|
+
// well-formed, authenticated, and had a real answer waiting inside it.
|
|
22
|
+
//
|
|
23
|
+
// The engine cannot import a provider package to type-check a provider's error,
|
|
24
|
+
// so the refusal is recognised STRUCTURALLY. Which makes the second law here
|
|
25
|
+
// just as important as the first: everything that is NOT a 409 refusal must
|
|
26
|
+
// still be a 502, or an expired API key would start reading like the
|
|
27
|
+
// customer's fault.
|
|
28
|
+
|
|
29
|
+
const DOMAIN = "acme.test";
|
|
30
|
+
|
|
31
|
+
const DKIM: DnsRecord = {
|
|
32
|
+
type: "TXT",
|
|
33
|
+
name: `hogsend._domainkey.${DOMAIN}`,
|
|
34
|
+
value: "p=FAKE",
|
|
35
|
+
purpose: "dkim",
|
|
36
|
+
status: "verified",
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/** The shape `@hogsend/plugin-hogsend` throws — status + slug + sentence. */
|
|
40
|
+
class RelayError extends Error {
|
|
41
|
+
constructor(
|
|
42
|
+
readonly status: number,
|
|
43
|
+
readonly error: string,
|
|
44
|
+
message: string,
|
|
45
|
+
) {
|
|
46
|
+
super(message);
|
|
47
|
+
this.name = "HogsendRelayError";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const NOT_OWNED = () =>
|
|
52
|
+
new RelayError(
|
|
53
|
+
409,
|
|
54
|
+
"domain_not_owned",
|
|
55
|
+
`"${DOMAIN}" already exists as an email identity in Hogsend Email's shared AWS account, and it is not claimed by this account. The fix is MANUAL: an operator must delete the identity in SES.`,
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
function makeApp(throws: () => unknown) {
|
|
59
|
+
const status = (): DomainStatus => ({
|
|
60
|
+
domain: DOMAIN,
|
|
61
|
+
state: "verified",
|
|
62
|
+
records: [DKIM],
|
|
63
|
+
providerId: "hogsend",
|
|
64
|
+
checkedAt: "2026-08-12T00:00:00.000Z",
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const domains: DomainsCapability = {
|
|
68
|
+
create: async () => {
|
|
69
|
+
throw throws();
|
|
70
|
+
},
|
|
71
|
+
get: async () => status(),
|
|
72
|
+
records: async () => status().records,
|
|
73
|
+
verify: async () => {
|
|
74
|
+
throw throws();
|
|
75
|
+
},
|
|
76
|
+
setReturnPath: async () => {
|
|
77
|
+
throw throws();
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const emailProvider = {
|
|
82
|
+
meta: { id: "hogsend", name: "Hogsend Email" },
|
|
83
|
+
domains,
|
|
84
|
+
} as unknown as EmailProvider;
|
|
85
|
+
|
|
86
|
+
const domainStatus = {
|
|
87
|
+
getStatus: async () => ({
|
|
88
|
+
domain: DOMAIN,
|
|
89
|
+
providerId: "hogsend",
|
|
90
|
+
supported: true,
|
|
91
|
+
returnPathSupported: true,
|
|
92
|
+
status: status(),
|
|
93
|
+
testMode: {
|
|
94
|
+
active: false,
|
|
95
|
+
reason: null,
|
|
96
|
+
redirectTo: null,
|
|
97
|
+
fromOverride: null,
|
|
98
|
+
},
|
|
99
|
+
guidance: SENDING_DOMAIN_GUIDANCE,
|
|
100
|
+
}),
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const app = new OpenAPIHono<AppEnv>();
|
|
104
|
+
app.use("*", async (c, next) => {
|
|
105
|
+
c.set("container", { emailProvider, domainStatus } as never);
|
|
106
|
+
await next();
|
|
107
|
+
});
|
|
108
|
+
app.route("/", domainRouter);
|
|
109
|
+
return app;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The three POSTs that reach the provider, and how to call each. */
|
|
113
|
+
const ROUTES = [
|
|
114
|
+
{
|
|
115
|
+
name: "add",
|
|
116
|
+
call: (app: ReturnType<typeof makeApp>) =>
|
|
117
|
+
app.request("/", {
|
|
118
|
+
method: "POST",
|
|
119
|
+
headers: { "content-type": "application/json" },
|
|
120
|
+
body: JSON.stringify({ domain: DOMAIN }),
|
|
121
|
+
}),
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: "verify",
|
|
125
|
+
call: (app: ReturnType<typeof makeApp>) =>
|
|
126
|
+
app.request("/verify", { method: "POST" }),
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: "return-path",
|
|
130
|
+
call: (app: ReturnType<typeof makeApp>) =>
|
|
131
|
+
app.request("/return-path", {
|
|
132
|
+
method: "POST",
|
|
133
|
+
headers: { "content-type": "application/json" },
|
|
134
|
+
body: JSON.stringify({ enabled: true }),
|
|
135
|
+
}),
|
|
136
|
+
},
|
|
137
|
+
] as const;
|
|
138
|
+
|
|
139
|
+
describe("a provider conflict reaches the operator", () => {
|
|
140
|
+
for (const route of ROUTES) {
|
|
141
|
+
test(`${route.name} answers 409 with the provider's slug and sentence`, async () => {
|
|
142
|
+
const res = await route.call(makeApp(NOT_OWNED));
|
|
143
|
+
|
|
144
|
+
assert.equal(res.status, 409);
|
|
145
|
+
const body = (await res.json()) as { error: string; message: string };
|
|
146
|
+
// The machine-readable slug, so Studio and the CLI can branch on it.
|
|
147
|
+
assert.equal(body.error, "domain_not_owned");
|
|
148
|
+
// …and the REMEDY, which is the whole reason a 502 was wrong: the
|
|
149
|
+
// sentence tells the operator what to do, and a gateway error does not.
|
|
150
|
+
assert.match(body.message, /manual/i);
|
|
151
|
+
assert.match(body.message, /delete the identity/i);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
describe("everything else stays a 502", () => {
|
|
157
|
+
for (const route of ROUTES) {
|
|
158
|
+
test(`${route.name} keeps 502 for an opaque provider failure`, async () => {
|
|
159
|
+
const res = await route.call(makeApp(() => new Error("socket hang up")));
|
|
160
|
+
assert.equal(res.status, 502);
|
|
161
|
+
assert.match(
|
|
162
|
+
((await res.json()) as { error: string }).error,
|
|
163
|
+
/socket hang up/,
|
|
164
|
+
);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test(`${route.name} keeps 502 for a provider 401 — our key, not their request`, async () => {
|
|
168
|
+
// A revoked or send-only API key is OUR misconfiguration. Forwarding it
|
|
169
|
+
// would tell the customer their request was at fault for an outage they
|
|
170
|
+
// cannot do anything about.
|
|
171
|
+
const res = await route.call(
|
|
172
|
+
makeApp(() => new RelayError(401, "invalid_token", "bad token")),
|
|
173
|
+
);
|
|
174
|
+
assert.equal(res.status, 502);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test(`${route.name} keeps 502 for a 409 with no slug`, async () => {
|
|
178
|
+
// Structural matching has to be strict in BOTH directions: a bare object
|
|
179
|
+
// that happens to carry `status: 409` is not a typed refusal, and
|
|
180
|
+
// answering one with an empty `error` would hand Studio a code it cannot
|
|
181
|
+
// branch on and a message that says nothing.
|
|
182
|
+
const res = await route.call(
|
|
183
|
+
makeApp(() => Object.assign(new Error("conflict"), { status: 409 })),
|
|
184
|
+
);
|
|
185
|
+
assert.equal(res.status, 502);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
});
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, test } from "node:test";
|
|
3
|
+
import type {
|
|
4
|
+
DnsRecord,
|
|
5
|
+
DomainStatus,
|
|
6
|
+
DomainsCapability,
|
|
7
|
+
EmailProvider,
|
|
8
|
+
SetReturnPathInput,
|
|
9
|
+
} from "@hogsend/core";
|
|
10
|
+
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
11
|
+
import type { AppEnv } from "../../app.js";
|
|
12
|
+
import { SENDING_DOMAIN_GUIDANCE } from "../../lib/sending-domain-guidance.js";
|
|
13
|
+
import { domainRouter } from "./domain.js";
|
|
14
|
+
|
|
15
|
+
// PRD 20 task 3 — `POST /v1/admin/domain/return-path`. Everything here runs
|
|
16
|
+
// against the router with a fake container: no DB, no network, no env. The
|
|
17
|
+
// laws being held:
|
|
18
|
+
//
|
|
19
|
+
// - BOTH unsupported cases 501 (no `domains` at all; `domains` without
|
|
20
|
+
// `setReturnPath`) — capability gaps answer like capability gaps, never
|
|
21
|
+
// throw;
|
|
22
|
+
// - on reports the two extra records as `pending`; off stops reporting them
|
|
23
|
+
// and the domain stays fully verified (off is not a warning state);
|
|
24
|
+
// - an invalid label is refused BY NAME before any provider traffic;
|
|
25
|
+
// - no user-facing string drifts into claiming the return path affects where
|
|
26
|
+
// a customer's incoming mail lands (it carries bounces).
|
|
27
|
+
|
|
28
|
+
const DOMAIN = "acme.test";
|
|
29
|
+
|
|
30
|
+
const DKIM: DnsRecord = {
|
|
31
|
+
type: "TXT",
|
|
32
|
+
name: `hogsend._domainkey.${DOMAIN}`,
|
|
33
|
+
value: "p=FAKE",
|
|
34
|
+
purpose: "dkim",
|
|
35
|
+
status: "verified",
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
function returnPathRecords(label: string): DnsRecord[] {
|
|
39
|
+
return [
|
|
40
|
+
{
|
|
41
|
+
type: "MX",
|
|
42
|
+
name: `${label}.${DOMAIN}`,
|
|
43
|
+
value: "feedback-smtp.us-east-1.amazonses.com",
|
|
44
|
+
priority: 10,
|
|
45
|
+
purpose: "mx",
|
|
46
|
+
status: "pending",
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
type: "TXT",
|
|
50
|
+
name: `${label}.${DOMAIN}`,
|
|
51
|
+
value: "v=spf1 include:amazonses.com ~all",
|
|
52
|
+
purpose: "spf",
|
|
53
|
+
status: "pending",
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Stateful fake capability: a post-switch refresh reads the new truth back. */
|
|
59
|
+
function createFakeDomains() {
|
|
60
|
+
const calls: SetReturnPathInput[] = [];
|
|
61
|
+
let enabled = false;
|
|
62
|
+
let label = "send";
|
|
63
|
+
|
|
64
|
+
const status = (): DomainStatus => ({
|
|
65
|
+
domain: DOMAIN,
|
|
66
|
+
state: "verified",
|
|
67
|
+
records: enabled ? [DKIM, ...returnPathRecords(label)] : [DKIM],
|
|
68
|
+
providerId: "fake",
|
|
69
|
+
checkedAt: "2026-08-11T00:00:00.000Z",
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const capability: DomainsCapability = {
|
|
73
|
+
create: async () => status(),
|
|
74
|
+
get: async () => status(),
|
|
75
|
+
records: async () => status().records,
|
|
76
|
+
setReturnPath: async (input) => {
|
|
77
|
+
calls.push(input);
|
|
78
|
+
enabled = input.enabled;
|
|
79
|
+
label = input.label ?? "send";
|
|
80
|
+
return {
|
|
81
|
+
enabled,
|
|
82
|
+
mailFromDomain: enabled ? `${label}.${DOMAIN}` : null,
|
|
83
|
+
status: status(),
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
return { capability, calls };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Mount the real router behind a fake container. The fake status service
|
|
92
|
+
* mirrors the real one's contract: it answers the provider's CURRENT state,
|
|
93
|
+
* so the route's refresh-after-write is observable.
|
|
94
|
+
*/
|
|
95
|
+
function makeApp(opts: {
|
|
96
|
+
domains?: DomainsCapability;
|
|
97
|
+
domain?: string | null;
|
|
98
|
+
}) {
|
|
99
|
+
const emailProvider = {
|
|
100
|
+
meta: { id: "fake", name: "Fake" },
|
|
101
|
+
...(opts.domains ? { domains: opts.domains } : {}),
|
|
102
|
+
} as unknown as EmailProvider;
|
|
103
|
+
|
|
104
|
+
const domainStatus = {
|
|
105
|
+
getStatus: async () => ({
|
|
106
|
+
domain: opts.domain === undefined ? DOMAIN : opts.domain,
|
|
107
|
+
providerId: "fake",
|
|
108
|
+
supported: Boolean(emailProvider.domains),
|
|
109
|
+
returnPathSupported:
|
|
110
|
+
typeof emailProvider.domains?.setReturnPath === "function",
|
|
111
|
+
status: emailProvider.domains
|
|
112
|
+
? await emailProvider.domains.get(DOMAIN)
|
|
113
|
+
: null,
|
|
114
|
+
testMode: {
|
|
115
|
+
active: false,
|
|
116
|
+
reason: null,
|
|
117
|
+
redirectTo: null,
|
|
118
|
+
fromOverride: null,
|
|
119
|
+
},
|
|
120
|
+
guidance: SENDING_DOMAIN_GUIDANCE,
|
|
121
|
+
}),
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const app = new OpenAPIHono<AppEnv>();
|
|
125
|
+
app.use("*", async (c, next) => {
|
|
126
|
+
c.set("container", { emailProvider, domainStatus } as never);
|
|
127
|
+
await next();
|
|
128
|
+
});
|
|
129
|
+
app.route("/", domainRouter);
|
|
130
|
+
return app;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function post(app: ReturnType<typeof makeApp>, body: unknown) {
|
|
134
|
+
return app.request("/return-path", {
|
|
135
|
+
method: "POST",
|
|
136
|
+
headers: { "content-type": "application/json" },
|
|
137
|
+
body: JSON.stringify(body),
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
describe("the two unsupported cases", () => {
|
|
142
|
+
test("501 when the provider has no domains capability at all", async () => {
|
|
143
|
+
const app = makeApp({});
|
|
144
|
+
const res = await post(app, { enabled: true });
|
|
145
|
+
assert.equal(res.status, 501);
|
|
146
|
+
assert.deepEqual(await res.json(), { error: "provider_unsupported" });
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test("501 when domains exists but cannot manage the return path", async () => {
|
|
150
|
+
const { capability } = createFakeDomains();
|
|
151
|
+
const { setReturnPath: _dropped, ...withoutToggle } = capability;
|
|
152
|
+
const app = makeApp({ domains: withoutToggle as DomainsCapability });
|
|
153
|
+
const res = await post(app, { enabled: true });
|
|
154
|
+
assert.equal(res.status, 501);
|
|
155
|
+
assert.deepEqual(await res.json(), { error: "provider_unsupported" });
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
describe("switching", () => {
|
|
160
|
+
test("on answers the MX + SPF pair as pending, DKIM untouched", async () => {
|
|
161
|
+
const { capability } = createFakeDomains();
|
|
162
|
+
const app = makeApp({ domains: capability });
|
|
163
|
+
|
|
164
|
+
const res = await post(app, { enabled: true });
|
|
165
|
+
assert.equal(res.status, 200);
|
|
166
|
+
const body = (await res.json()) as {
|
|
167
|
+
returnPath: { enabled: boolean; mailFromDomain: string | null };
|
|
168
|
+
status: { status: { records: DnsRecord[] } };
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
assert.equal(body.returnPath.enabled, true);
|
|
172
|
+
assert.equal(body.returnPath.mailFromDomain, `send.${DOMAIN}`);
|
|
173
|
+
|
|
174
|
+
const byPurpose = new Map(
|
|
175
|
+
body.status.status.records.map((r) => [r.purpose, r]),
|
|
176
|
+
);
|
|
177
|
+
assert.equal(body.status.status.records.length, 3);
|
|
178
|
+
assert.equal(byPurpose.get("mx")?.status, "pending");
|
|
179
|
+
assert.equal(byPurpose.get("spf")?.status, "pending");
|
|
180
|
+
// The base record never regresses because of the upgrade.
|
|
181
|
+
assert.equal(byPurpose.get("dkim")?.status, "verified");
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test("off stops reporting them, and off is not a warning state", async () => {
|
|
185
|
+
const { capability } = createFakeDomains();
|
|
186
|
+
const app = makeApp({ domains: capability });
|
|
187
|
+
await post(app, { enabled: true });
|
|
188
|
+
|
|
189
|
+
const res = await post(app, { enabled: false });
|
|
190
|
+
assert.equal(res.status, 200);
|
|
191
|
+
const body = (await res.json()) as {
|
|
192
|
+
returnPath: { enabled: boolean; mailFromDomain: string | null };
|
|
193
|
+
status: { status: { state: string; records: DnsRecord[] } };
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
assert.equal(body.returnPath.enabled, false);
|
|
197
|
+
assert.equal(body.returnPath.mailFromDomain, null);
|
|
198
|
+
assert.deepEqual(
|
|
199
|
+
body.status.status.records.map((r) => r.purpose),
|
|
200
|
+
["dkim"],
|
|
201
|
+
);
|
|
202
|
+
// Fully verified on the one TXT record, with the upgrade off.
|
|
203
|
+
assert.equal(body.status.status.state, "verified");
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
describe("the label", () => {
|
|
208
|
+
test("an invalid label is refused BY NAME, and the provider is never called", async () => {
|
|
209
|
+
const { capability, calls } = createFakeDomains();
|
|
210
|
+
const app = makeApp({ domains: capability });
|
|
211
|
+
|
|
212
|
+
const res = await post(app, { enabled: true, label: "no.dots" });
|
|
213
|
+
assert.equal(res.status, 400);
|
|
214
|
+
const body = (await res.json()) as { error: string };
|
|
215
|
+
// The rejection names the offending label — a customer who typed it can
|
|
216
|
+
// see WHAT was refused, not just that something was.
|
|
217
|
+
assert.match(body.error, /"no\.dots"/);
|
|
218
|
+
assert.equal(calls.length, 0);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test("a label is normalized (trim + lowercase) before the provider sees it", async () => {
|
|
222
|
+
const { capability, calls } = createFakeDomains();
|
|
223
|
+
const app = makeApp({ domains: capability });
|
|
224
|
+
|
|
225
|
+
const res = await post(app, { enabled: true, label: " Notifications " });
|
|
226
|
+
assert.equal(res.status, 200);
|
|
227
|
+
assert.equal(calls[0]?.label, "notifications");
|
|
228
|
+
const body = (await res.json()) as {
|
|
229
|
+
returnPath: { mailFromDomain: string | null };
|
|
230
|
+
};
|
|
231
|
+
assert.equal(body.returnPath.mailFromDomain, `notifications.${DOMAIN}`);
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
test("400 no_domain_configured when no sending domain is derivable", async () => {
|
|
236
|
+
const { capability } = createFakeDomains();
|
|
237
|
+
const app = makeApp({ domains: capability, domain: null });
|
|
238
|
+
const res = await post(app, { enabled: true });
|
|
239
|
+
assert.equal(res.status, 400);
|
|
240
|
+
assert.deepEqual(await res.json(), { error: "no_domain_configured" });
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
describe("copy law — the return path carries bounces", () => {
|
|
244
|
+
// The misunderstanding PRD 20 exists to correct is "the return path brings
|
|
245
|
+
// customer answers back". No user-facing string this feature ships may
|
|
246
|
+
// contain the substring that starts that sentence.
|
|
247
|
+
const FORBIDDEN = /repl/i;
|
|
248
|
+
|
|
249
|
+
test("nothing in the router's OpenAPI surface contains it", () => {
|
|
250
|
+
const doc = domainRouter.getOpenAPIDocument({
|
|
251
|
+
openapi: "3.0.0",
|
|
252
|
+
info: { title: "test", version: "0" },
|
|
253
|
+
});
|
|
254
|
+
assert.doesNotMatch(JSON.stringify(doc.paths), FORBIDDEN);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
test("nothing in the runtime answers contains it either", async () => {
|
|
258
|
+
const { capability } = createFakeDomains();
|
|
259
|
+
const bodies: unknown[] = [];
|
|
260
|
+
|
|
261
|
+
for (const [app, body] of [
|
|
262
|
+
[makeApp({}), { enabled: true }],
|
|
263
|
+
[makeApp({ domains: capability }), { enabled: true, label: "no.dots" }],
|
|
264
|
+
[makeApp({ domains: capability, domain: null }), { enabled: true }],
|
|
265
|
+
[makeApp({ domains: capability }), { enabled: true }],
|
|
266
|
+
[makeApp({ domains: capability }), { enabled: false }],
|
|
267
|
+
] as const) {
|
|
268
|
+
const res = await post(app, body);
|
|
269
|
+
bodies.push(await res.json());
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
assert.doesNotMatch(JSON.stringify(bodies), FORBIDDEN);
|
|
273
|
+
});
|
|
274
|
+
});
|