feat: check domain name of account.json
against dkim config
This commit is contained in:
parent
09f84fc493
commit
a88178c2ce
|
@ -1,4 +1,5 @@
|
||||||
import custom from '../config/account.json' with { type: 'json' }
|
import accounts from '../config/account.json' with { type: 'json' }
|
||||||
|
import dkim from '../config/dkim.json' with { type: 'json' }
|
||||||
|
|
||||||
export class Contact {
|
export class Contact {
|
||||||
#name: string
|
#name: string
|
||||||
|
@ -15,11 +16,11 @@ export class Contact {
|
||||||
}
|
}
|
||||||
|
|
||||||
static expand(shortName: string): Contact {
|
static expand(shortName: string): Contact {
|
||||||
if (!(shortName in custom)) {
|
if (!(shortName in accounts)) {
|
||||||
throw new Error('unknown short name contact')
|
throw new Error('unknown short name contact')
|
||||||
}
|
}
|
||||||
|
|
||||||
const { name, address } = custom[shortName as keyof typeof custom]
|
const { name, address } = accounts[shortName as keyof typeof accounts]
|
||||||
|
|
||||||
if (typeof name !== 'string') {
|
if (typeof name !== 'string') {
|
||||||
throw new SyntaxError(
|
throw new SyntaxError(
|
||||||
|
@ -31,7 +32,9 @@ export class Contact {
|
||||||
`missing key "address" in contact short name config for "${shortName}"`,
|
`missing key "address" in contact short name config for "${shortName}"`,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (!(/\w+@(\w+\.)?cohabit\.fr/.test(address))) {
|
|
||||||
|
const addressRegExp = new RegExp(String.raw`\w+@(\w+\.)?${dkim.domainName}`)
|
||||||
|
if (!(addressRegExp.test(address))) {
|
||||||
throw new SyntaxError(
|
throw new SyntaxError(
|
||||||
`invalid "address" in contact short name config for "${shortName}"`,
|
`invalid "address" in contact short name config for "${shortName}"`,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue