From a88178c2ce4bc7031c76ccb28f6df0c74bcc5c7a Mon Sep 17 00:00:00 2001 From: Julien Oculi Date: Mon, 15 Jul 2024 14:07:09 +0200 Subject: [PATCH] feat: check domain name of `account.json` against dkim config --- src/contact.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/contact.ts b/src/contact.ts index 7fd422b..4caef4d 100644 --- a/src/contact.ts +++ b/src/contact.ts @@ -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 { #name: string @@ -15,11 +16,11 @@ export class Contact { } static expand(shortName: string): Contact { - if (!(shortName in custom)) { + if (!(shortName in accounts)) { 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') { throw new SyntaxError( @@ -31,7 +32,9 @@ export class Contact { `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( `invalid "address" in contact short name config for "${shortName}"`, )