Support a separate database for Web UI tables

This commit is contained in:
bryanpedini committed 2026-11-21 20:36:03 +01:00
1 parent a2f8e59d9b
commit f464dc0af9
38 files changed
+880 -302

No files matched your search

+9 -9
View File
@@ -53,13 +53,13 @@ func TestZoneAPIFailurePaths(t *testing.T) {
{name: "create malformed body", operation: "zone_create", body: "{", status: 400},
{name: "create stale grant lookup", operation: "zone_create", body: zoneAPITestCreate, setup: rowsWithStale, failOn: []string{"ORDER BY username FOR UPDATE"}},
{name: "create after removing stale grants", operation: "zone_create", body: zoneAPITestCreate, setup: rowsWithStale,
failOn: []string{"INSERT INTO `coredns_records`"}, ran: "DELETE FROM `coredns_webui_zone_delegations`"},
{name: "create written rows", operation: "zone_create", body: zoneAPITestCreate, setup: rowsWithStale, failOn: zoneRead, ran: "INSERT INTO `coredns_records`"},
failOn: []string{"INSERT INTO `coredns`.`coredns_records`"}, ran: "DELETE FROM `webui`.`coredns_webui_zone_delegations`"},
{name: "create written rows", operation: "zone_create", body: zoneAPITestCreate, setup: rowsWithStale, failOn: zoneRead, ran: "INSERT INTO `coredns`.`coredns_records`"},
{name: "delete malformed body", operation: "zone_delete", body: `{"confirm":`, status: 400},
{name: "delete grants", operation: "zone_delete", body: `{"confirm":"example.org"}`, setup: func(f *zoneAPITestDB, _ *apiContext) { f.stale = true },
failOn: []string{"DELETE FROM `coredns_webui_zone_delegations`"}},
failOn: []string{"DELETE FROM `webui`.`coredns_webui_zone_delegations`"}},
{name: "delete after removing grants", operation: "zone_delete", body: `{"confirm":"example.org"}`, setup: func(f *zoneAPITestDB, _ *apiContext) { f.stale = true },
failOn: []string{"DELETE FROM `coredns_records`"}, ran: "DELETE FROM `coredns_webui_zone_delegations`"},
failOn: []string{"DELETE FROM `coredns`.`coredns_records`"}, ran: "DELETE FROM `webui`.`coredns_webui_zone_delegations`"},
{name: "record lookup outside the zone", operation: "record_update", id: "99", etag: `"x"`, body: zoneAPITestRecord, failOn: []string{"WHERE `id` = ?", "SELECT"}},
{name: "update malformed replacement", operation: "record_update", id: "3", etag: recordETag(rows[2]), body: `{"name":`, status: 400},
{name: "update unknown field", operation: "record_update", id: "3", etag: recordETag(rows[2]), body: `{"name":"first","bogus":1}`, status: 400},
@@ -68,10 +68,10 @@ func TestZoneAPIFailurePaths(t *testing.T) {
{name: "update into a second SOA", operation: "record_update", id: "3", etag: recordETag(rows[2]), body: zoneAPITestSOARecord("@"), status: 422, field: "type"},
{name: "update content not an object", operation: "record_update", id: "3", etag: recordETag(rows[2]),
body: `{"name":"first","type":"A","ttl":60,"data":"192.0.2.1"}`, status: 422, field: "data"},
{name: "update write", operation: "record_update", id: "3", etag: recordETag(rows[2]), body: zoneAPITestRecord, failOn: []string{"UPDATE `coredns_records`", "!`id` = 1"}},
{name: "update write", operation: "record_update", id: "3", etag: recordETag(rows[2]), body: zoneAPITestRecord, failOn: []string{"UPDATE `coredns`.`coredns_records`", "!`id` = 1"}},
{name: "update written rows", operation: "record_update", id: "3", etag: recordETag(rows[2]), body: zoneAPITestRecord, failOn: zoneRead},
{name: "delete invalid id", operation: "record_delete", id: "x", etag: recordETag(rows[2]), status: 400},
{name: "delete write", operation: "record_delete", id: "3", etag: recordETag(rows[2]), failOn: []string{"DELETE FROM `coredns_records`"}},
{name: "delete write", operation: "record_delete", id: "3", etag: recordETag(rows[2]), failOn: []string{"DELETE FROM `coredns`.`coredns_records`"}},
{name: "bulk malformed body", operation: "record_bulk_delete", body: `{"records":[`, status: 400},
{name: "bulk SOA in the batch", operation: "record_bulk_delete",
body: `{"records":[{"id":3,"etag":` + zoneAPITestJSON(t, recordETag(rows[2])) + `},{"id":1,"etag":` + zoneAPITestJSON(t, recordETag(rows[0])) + `}]}`,
@@ -84,10 +84,10 @@ func TestZoneAPIFailurePaths(t *testing.T) {
status: 422, field: "records"},
{name: "bulk write", operation: "record_bulk_delete",
body: `{"records":[{"id":3,"etag":` + zoneAPITestJSON(t, recordETag(rows[2])) + `},{"id":4,"etag":` + zoneAPITestJSON(t, recordETag(rows[3])) + `}]}`,
failOn: []string{"DELETE FROM `coredns_records`"}},
failOn: []string{"DELETE FROM `coredns`.`coredns_records`"}},
{name: "SOA malformed body", operation: "soa_update", etag: recordETag(rows[0]), body: "[", status: 400},
{name: "SOA write", operation: "soa_update", etag: recordETag(rows[0]), body: strings.Replace(zoneAPITestSOA, `"retry":600`, `"retry":700`, 1),
failOn: []string{"UPDATE `coredns_records`"}},
failOn: []string{"UPDATE `coredns`.`coredns_records`"}},
{name: "SOA relative primary name server", operation: "soa_update", etag: recordETag(rows[0]),
body: strings.Replace(zoneAPITestSOA, "ns.example.net", "ns..example.net", 1), status: 422, field: "ns"},
{name: "import malformed body", operation: "zone_import", body: `{"mode":"merge",`, status: 400},
@@ -95,7 +95,7 @@ func TestZoneAPIFailurePaths(t *testing.T) {
{name: "import missing content preview", operation: "zone_import_preview", body: `{"mode":"replace"}`, status: 422, field: "content"},
{name: "import write", operation: "zone_import",
body: `{"mode":"merge","content":"new 60 A 192.0.2.9\n","fingerprint":"` + zoneFingerprint(rows) + `"}`,
failOn: []string{"INSERT INTO `coredns_records`"}},
failOn: []string{"INSERT INTO `coredns`.`coredns_records`"}},
} {
t.Run(tc.name, func(t *testing.T) {
f := zoneAPITestDBFor(t, rows)