Fix DuckDNS domains field colliding with DnsProvider's own relation (#127)
Reported error when adding a DuckDNS provider:
TypeError: this.domains.map is not a function
at Proxy.updateDomains (models/dns_provider.js:185:37)
DnsProvider.__intraModel merges `{...DnsProvider._keyMap,
...Provider._keyMap}`, so a provider-defined field with the same name
as one of DnsProvider's own (created_by, updated_by, name,
dnsProvider, domains, id) silently overwrites it. DuckDNS defined a
`domains` field (the operator-supplied comma-separated subdomain
list), which replaced DnsProvider's `domains` relation (rel: 'many' to
Domain, populated by updateDomains()) — so `this.domains` stopped
being the array relation and became DuckDNS's raw string instead.
Rename the field to `subdomains` throughout (model, docs, tests). Add
a comment on __intraModel documenting the collision risk for future
providers, and a regression test asserting no registered provider's
_keyMap redefines one of DnsProvider's reserved field names.
This commit is contained in:
@@ -93,6 +93,13 @@ class DnsProvider extends Table{
|
||||
}
|
||||
|
||||
let Provider = providers[provider];
|
||||
// Provider._keyMap is spread last, so a provider-defined field with the
|
||||
// same name as one of ours (created_by, updated_by, name, dnsProvider,
|
||||
// domains, id — see this._keyMap above) silently overwrites it. This bit
|
||||
// a DuckDNS field named `domains`: it replaced the `domains` relation
|
||||
// (rel: 'many' to Domain), so `this.domains` stopped being an array and
|
||||
// `updateDomains()` broke with "this.domains.map is not a function".
|
||||
// New providers must avoid these names.
|
||||
let _keyMap = {...this._keyMap, ...Provider._keyMap};
|
||||
|
||||
return ({
|
||||
|
||||
Reference in New Issue
Block a user