fix: serialize delegations and repair verification

This commit is contained in:
bryanpedini committed 2026-11-19 15:46:12 +01:00
1 parent 99fa5de747
commit 5f17aab6ca
8 files changed
+99 -43

No files matched your search

+49
View File
@@ -443,3 +443,52 @@ func TestIntegrationZoneAPIAuthorizationRace(t *testing.T) {
}
}
}
func TestIntegrationDelegationZoneLock(t *testing.T) {
for _, operation := range []string{opDelegationGrant, opDelegationRevoke} {
t.Run(operation, func(t *testing.T) {
it := newITZoneAPI(t)
it.server.store = newSQLWebStore(it.server.db, it.server.tables)
it.call(t, it.admin, "zone_create", "", "", zoneAPITestCreate, 201)
if operation == opDelegationRevoke {
it.grant(t, zoneAPITestName)
}
c := it.request(it.admin, operation, "", "", "")
c.Vars["username"] = it.user.Username
result := make(chan error, 1)
err := withZoneLock(t.Context(), it.server.db, it.server.tables, zoneAPITestName, it.server.log, func(conn *sql.Conn) error {
go func() {
var err error
if operation == opDelegationGrant {
_, err = handleDelegationGrant(t.Context(), c)
} else {
_, err = handleDelegationRevoke(t.Context(), c)
}
result <- err
}()
select {
case err := <-result:
return fmt.Errorf("delegation did not wait for zone lock: %v", err)
case <-time.After(200 * time.Millisecond):
}
return runInTx(t.Context(), conn, func(tx *sql.Tx) error {
if _, err := newDelegationStore(tx, it.server.tables).DeleteZoneDelegations(t.Context(), zoneAPITestName); err != nil {
return err
}
_, err := newRecordStore(tx, it.server.tables).DeleteZoneRecords(t.Context(), zoneAPITestName)
return err
})
})
if err != nil {
t.Fatal(err)
}
var apiErr *apiError
if err := <-result; !errors.As(err, &apiErr) || apiErr.Status != http.StatusNotFound {
t.Fatalf("delegation after delete: %v", err)
}
if exists, err := it.delegations.HasDelegation(t.Context(), zoneAPITestName, it.user.ID); err != nil || exists {
t.Fatalf("orphan delegation: %v, %v", exists, err)
}
})
}
}