From 3623006f25c0ace44dd7514cbc70a3dd3a3b20ab Mon Sep 17 00:00:00 2001 From: Bryan Joshua Pedini Date: Thu, 19 Nov 2026 15:44:25 +0100 Subject: [PATCH] fix: repair malformed SOA and expand release verification --- .gitea/workflows/image.yaml | 7 +++++++ .gitea/workflows/test.yaml | 7 +++++++ PLAN.md | 3 ++- README.md | 2 +- e2e/compose.yaml | 2 +- e2e/dockerfile | 1 + e2e/tests/power.spec.ts | 20 ++++++++++++++++++++ integration_zone_api_test.go | 34 ++++++++++++++++++++++++++++++++++ rules.go | 13 ++++++++++++- rules_test.go | 20 ++++++++++++++++++++ scripts/test-e2e.sh | 1 + 11 files changed, 106 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/image.yaml b/.gitea/workflows/image.yaml index 4ac7a22..37ca9fe 100644 --- a/.gitea/workflows/image.yaml +++ b/.gitea/workflows/image.yaml @@ -45,6 +45,13 @@ jobs: printf 'image_id=%s\n' "$(docker image inspect --format '{{.Id}}' "$CI_IMAGE")" >> "$GITHUB_OUTPUT" scripts/test-image.sh "$CI_IMAGE" "$VERSION" "$commit" scripts/test-e2e.sh "$CI_IMAGE" + - name: Save accessibility screenshots + if: always() + uses: actions/upload-artifact@v3 + with: + name: accessibility-screenshots + path: e2e/reports/**/screenshots/*.png + if-no-files-found: warn - name: Publish image env: GIT_HOST: ${{ vars.GIT_HOST }} diff --git a/.gitea/workflows/test.yaml b/.gitea/workflows/test.yaml index dd6b641..f585e0c 100644 --- a/.gitea/workflows/test.yaml +++ b/.gitea/workflows/test.yaml @@ -40,3 +40,10 @@ jobs: trap 'docker image rm "$image" >/dev/null' EXIT scripts/test-image.sh "$image" "$version" "$commit" scripts/test-e2e.sh "$image" + - name: Save accessibility screenshots + if: always() + uses: actions/upload-artifact@v3 + with: + name: accessibility-screenshots + path: e2e/reports/**/screenshots/*.png + if-no-files-found: warn diff --git a/PLAN.md b/PLAN.md index 06e2c68..0c8f5b3 100644 --- a/PLAN.md +++ b/PLAN.md @@ -336,7 +336,7 @@ Errors refuse the write with HTTP 422. Warnings let the write through and are re Errors: -- A zone has exactly one SOA, at the apex. The SOA cannot be created when one exists and cannot be deleted on its own; it goes away only with the zone. +- A zone has exactly one SOA, at the apex. The SOA cannot be created when one exists and the last SOA can only be deleted with the zone. Repair may move a misplaced SOA, correct its content, or remove an extra SOA. - The last NS at the apex cannot be deleted. - A name with a CNAME has no other record, and has only one CNAME. - No two records with the same name, type and canonical content. @@ -444,6 +444,7 @@ Operations: | Delegation | `delegation_list` | `delegation_grant`, `delegation_revoke` | | Users | `user_list`, `user_read` | `user_create`, `user_role`, `user_password`, `user_delete` | | Audit | `audit_read` | | +| Unknown API request | `api_unknown` | | Each API route maps to exactly one operation (section 11). CLI rows use `user_create`, `user_password`, `user_role` and `user_delete`. diff --git a/README.md b/README.md index bd46ace..0b9646d 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ After field validation every record is converted to the `miekg/dns` RR the plugi Errors refuse a write with HTTP `422`: a zone has exactly one SOA, at the apex, which cannot be created twice or deleted on its own; the last apex NS cannot be deleted; a name with a CNAME has no other record and only one CNAME; no two records share name, type and canonical content. Warnings let the write through and are returned with the response: records of one name and type with different TTLs, `NS`, `MX` or `SRV` targets that are CNAME owners or have no address record in the zone, names below a zone cut, `TXT` text longer than 255 bytes (served as several strings). -The zone page can repair an existing broken SOA set by editing a misplaced SOA or deleting an extra SOA. If a conflicting CNAME blocks the repair, delete that CNAME first. To restore a missing SOA, use a merge import containing an apex SOA. +The zone page can repair an existing broken SOA set by editing a misplaced SOA or deleting an extra SOA. If a conflicting CNAME blocks a structural repair, delete that CNAME first. If the sole SOA has malformed content and conflicts with a CNAME, correct the SOA content first, then remove the CNAME. To restore a missing SOA, use a merge import containing an apex SOA. The zone check (API, UI and `check` command) reports every row the plugin cannot serve correctly. diff --git a/e2e/compose.yaml b/e2e/compose.yaml index 7ebd05c..e45417e 100644 --- a/e2e/compose.yaml +++ b/e2e/compose.yaml @@ -267,4 +267,4 @@ services: E2E_FUZZ_RECORDS: ${E2E_FUZZ_RECORDS:-} E2E_OPERATOR_ACTIONS: ${E2E_OPERATOR_ACTIONS:-} E2E_ARGS: ${E2E_ARGS:-} - command: ["sh", "-c", "npx tsc --noEmit && exec npx playwright test $$E2E_ARGS"] + command: ["sh", "-c", "node --test unit/*.test.mjs && npx tsc --noEmit && exec npx playwright test $$E2E_ARGS"] diff --git a/e2e/dockerfile b/e2e/dockerfile index e50317e..e8f9f20 100644 --- a/e2e/dockerfile +++ b/e2e/dockerfile @@ -18,4 +18,5 @@ ENV CI=1 NODE_ENV=test COPY package.json package-lock.json ./ RUN npm ci --no-audit --no-fund COPY . . +COPY --from=app-static /js /static/js CMD ["npx", "playwright", "test"] diff --git a/e2e/tests/power.spec.ts b/e2e/tests/power.spec.ts index 7a8331f..1c4883e 100644 --- a/e2e/tests/power.spec.ts +++ b/e2e/tests/power.spec.ts @@ -35,6 +35,8 @@ test('a power user operates a large installation, with restart and edit conflict await first.page.goto('/'); await expect(first.page.getByRole('link', { name: large, exact: true })).toBeVisible(); const zonesMs = performance.now() - startZones; + await first.page.locator('#zone-search').fill(large); + await expect(first.page.getByRole('link', { name: zones[1], exact: true })).toHaveCount(0); const startZone = performance.now(); await first.page.getByRole('link', { name: large, exact: true }).click(); await expect(first.page.getByRole('rowheader', { name: 'seed-0000', exact: true })).toBeVisible(); @@ -48,6 +50,24 @@ test('a power user operates a large installation, with restart and edit conflict }); expect(zonesMs, 'zones page renders its links within 2 seconds').toBeLessThan(2000); expect(editMs, '10,000-record zone is interactive within 2 seconds').toBeLessThan(2000); + const dialog = first.page.locator('#record-dialog'); + const close = dialog.getByRole('button', { name: 'Close' }); + const save = dialog.locator('#rec-submit'); + await save.focus(); + await first.page.keyboard.press('Tab'); + await expect(close).toBeFocused(); + await first.page.keyboard.press('Shift+Tab'); + await expect(save).toBeFocused(); + await first.page.keyboard.press('Escape'); + await first.page.locator('#filter-type').selectOption('A'); + await first.page.locator('#page-next').click(); + await expect(first.page.getByRole('rowheader', { name: 'seed-0000', exact: true })).toHaveCount(0); + await first.page.locator('#filter-text').fill('seed-9997'); + await expect(first.page.getByRole('rowheader', { name: 'seed-9997', exact: true })).toBeVisible(); + await first.page.locator('#filter-type').selectOption('SOA'); + await expect(first.page.getByRole('rowheader', { name: 'seed-9997', exact: true })).toHaveCount(0); + await first.openZone(large); + await first.openEdit({ name: 'seed-0000', type: 'A' }); await second.openZone(large); await second.openEdit({ name: 'seed-0000', type: 'A' }); await restartWithSessions(world, first, second); diff --git a/integration_zone_api_test.go b/integration_zone_api_test.go index f40cbc4..d3843ad 100644 --- a/integration_zone_api_test.go +++ b/integration_zone_api_test.go @@ -733,3 +733,37 @@ func TestIntegrationDelegationZoneLock(t *testing.T) { }) } } + +func TestIntegrationConcurrentWritesInDistinctZones(t *testing.T) { + it := newITZoneAPI(t) + zones := []string{zoneAPITestName, "other.example."} + for _, zone := range zones { + body := strings.Replace(zoneAPITestCreate, "Example.ORG", strings.TrimSuffix(zone, "."), 1) + zoneAPITestStatus(t, t.Context(), zoneAPITestRequest(it.server, it.admin, "zone_create", "", "", "", body), 201) + } + ctx, cancel := context.WithTimeout(t.Context(), 10*time.Second) + defer cancel() + start := make(chan struct{}) + results := make(chan itZoneResult, len(zones)) + for _, zone := range zones { + request := zoneAPITestRequest(it.server, it.admin, "record_create", zone, "", "", zoneAPITestRecord) + go func() { + <-start + response, err := zoneAPITestCall(ctx, request) + results <- itZoneResult{response, err} + }() + } + close(start) + for range zones { + if result := <-results; result.err != nil || result.response.Status != 201 { + t.Fatalf("concurrent write failed: %+v", result) + } + } + it.audit(t, "record_create", len(zones)) + for _, zone := range zones { + rows, err := it.records.ZoneRows(ctx, zone) + if err != nil || len(rows) != 4 { + t.Fatalf("zone %s: found %d rows, error %v", zone, len(rows), err) + } + } +} diff --git a/rules.go b/rules.go index 2ea7609..62f62cd 100644 --- a/rules.go +++ b/rules.go @@ -197,7 +197,10 @@ func validateZoneChanges(zone string, current []recordRow, changes zoneChanges) after := summarizeZone(result) problems, warnings = zoneRuleProblems(zone, result, after, true) soaRepair := len(after.soa) != 0 && soaDefects(after.soa) < soaDefects(before.soa) - soaOnlyRepair := soaRepair && slices.Equal(nonSOARows(current), nonSOARows(result)) + soaContentRepair := len(before.soa) == 1 && len(after.soa) == 1 && + before.soa[0].ID == after.soa[0].ID && + !validSOAContent(before.soa[0]) && validSOAContent(after.soa[0]) + soaOnlyRepair := (soaRepair || soaContentRepair) && slices.Equal(nonSOARows(current), nonSOARows(result)) cnameRepair := soaDefects(after.soa) != 0 && changes.deletesOnly() if len(problems) != 0 && (soaOnlyRepair || cnameRepair) { beforeProblems, _ := zoneRuleProblems(zone, current, before, true) @@ -260,6 +263,14 @@ func deletesOnlyConflictingCNAMEs(ids []int64, problems []zoneProblem) bool { return true } +func validSOAContent(row recordRow) bool { + if !row.Content.Valid { + return false + } + _, err := decodeRecord("SOA", row.Content.String) + return err == nil +} + func soaDefects(soa []recordRow) int { defects := len(soa) - 1 for _, row := range soa { diff --git a/rules_test.go b/rules_test.go index bc2acf4..7438aaa 100644 --- a/rules_test.go +++ b/rules_test.go @@ -227,3 +227,23 @@ func TestValidateZoneChangePairs(t *testing.T) { }) } } + +func TestRepairMalformedSOAWithConflictingCNAME(t *testing.T) { + base := modelBaseZone() + broken := base[0] + broken.Content.String = strings.Replace(broken.Content.String, `"refresh":3600`, `"refresh":"invalid"`, 1) + if validSOAContent(broken) { + t.Fatal("test SOA must have invalid content") + } + cname := modelRawRow(3, "", "CNAME", 3600, `{"host":"target.example."}`) + current := []recordRow{broken, base[1], cname} + repair := zoneChanges{SOAUpdate: &base[0]} + if problems, _ := validateZoneChanges(base[0].Zone, current, repair); len(problems) != 0 { + t.Fatalf("SOA repair rejected: %+v", problems) + } + current = repair.finalRows(current) + remove := zoneChanges{Deletes: []int64{cname.ID}} + if problems, _ := validateZoneChanges(base[0].Zone, current, remove); len(problems) != 0 { + t.Fatalf("CNAME removal rejected after SOA repair: %+v", problems) + } +} diff --git a/scripts/test-e2e.sh b/scripts/test-e2e.sh index 1e12584..392272c 100755 --- a/scripts/test-e2e.sh +++ b/scripts/test-e2e.sh @@ -121,6 +121,7 @@ done echo "test-e2e: run ${project} against ${image}" docker build --quiet \ --build-arg "PLAYWRIGHT_IMAGE=${playwright_image}" \ + --build-context app-static=static \ --label "cdwu.e2e.run=${project}" \ --file e2e/dockerfile \ --tag "$runner_image" \