Fix editing and deleting DNS records from the cached list
The records endpoint returned raw cache rows, whose `id` is this app's own row number (12, 13, ...). The DNS page sends `r.id` back when a record is edited or deleted, so the provider was handed a row number instead of its record id. That only worked straight after a manual Sync, whose response carries the provider's ids; after any save or delete the page reloads from the cache and the problem came back. The ID check added for connected systems now refuses such an id with "That isn't a valid record ID". The list now returns records shaped like a sync's: `id` is the provider's record id. Editing and deleting work from the cached list for every DNS provider. The test checks the list hands out the provider's id, and that deleting with it reaches Cloudflare at the right address; with the old shape it fails. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2dac273b1d
commit
f71756b119
2 files changed
+29
-1
No files matched your search
@@ -378,6 +378,23 @@ describe("routes", () => {
|
||||
assert.deepEqual(calls, [{ method: "DELETE", url: `https://api.cloudflare.com/client/v4/zones/${ZONE}/dns_records/${RECORD}` }]);
|
||||
});
|
||||
|
||||
test("the cached record list hands out the provider's record id, and that id works for a delete", async () => {
|
||||
// A row as a sync leaves it: this app's own row number (`id`) next to the provider's record id (`recordId`).
|
||||
const { db } = await import("../src/db/client.js");
|
||||
const { dnsRecordsCache } = await import("../src/db/schema.js");
|
||||
await db.insert(dnsRecordsCache).values({ providerId: 1, zoneId: ZONE, recordId: RECORD, type: "A", name: "a.example.com", content: "1.2.3.4", ttl: 300 });
|
||||
|
||||
assert.equal(await send(operator, "GET", `/api/dns/providers/1/zones/${ZONE}/records`), 200);
|
||||
const { records } = JSON.parse(lastBody.text) as { records: Record<string, unknown>[] };
|
||||
const shown = records.find((r) => r.name === "a.example.com")!;
|
||||
assert.equal(shown.id, RECORD, "the page would send the database row number to the provider instead of its record id");
|
||||
assert.deepEqual(Object.keys(shown).sort(), ["content", "id", "name", "priority", "proxied", "ttl", "type"]);
|
||||
|
||||
calls = [];
|
||||
assert.equal(await send(operator, "DELETE", `/api/dns/providers/1/zones/${ZONE}/records/${encodeURIComponent(String(shown.id))}`), 204, lastBody.text);
|
||||
assert.deepEqual(calls, [{ method: "DELETE", url: `https://api.cloudflare.com/client/v4/zones/${ZONE}/dns_records/${RECORD}` }]);
|
||||
});
|
||||
|
||||
test("Azure DNS: crafted IDs are a 400, nothing reaches Azure's management API", async () => {
|
||||
for (const bad of ["x/../..", "..", "a?b"]) {
|
||||
calls = [];
|
||||
|
||||
Reference in new issue
Block a user