@@ -67,4 +67,49 @@ suite('functional: internals: OpPlug.node.jsonValidator auto', () => {
6767 const validator = await makeValidator ( schemaPath , schemaMap )
6868 assert . throws ( ( ) => { validator ( brokenJson ) } )
6969 } )
70+
71+ // list of valid/invalid emails is from https://github.com/json-schema-org/JSON-Schema-Test-Suite
72+ // (tests/draft2019-09/optional/format/email.json and idn-email.json)
73+ // and https://github.com/luzlab/ajv-formats-draft2019 (index.test.js)
74+
75+ suite ( 'accepts valid emails' , ( ) =>
76+ [
77+ 'joe.bloggs@example.com' ,
78+ 'te~st@example.com' ,
79+ '~test@example.com' ,
80+ 'test~@example.com' ,
81+ 'te.s.t@example.com' ,
82+ '실례@실례.테스트' ,
83+ 'квіточка@пошта.укр' ,
84+ 'Dörte@Sörensen.example.com'
85+ ] . forEach ( validEmail => test ( validEmail , async ( ) => {
86+ const validator = await makeValidator ( schemaPath , schemaMap )
87+ const validJson = JSON . stringify ( {
88+ bomFormat : 'CycloneDX' ,
89+ specVersion : '1.7' ,
90+ metadata : { authors : [ { email : validEmail } ] }
91+ } )
92+ assert . strictEqual ( validator ( validJson ) , null )
93+ } ) )
94+ )
95+
96+ suite ( 'rejects invalid emails' , ( ) =>
97+ [
98+ '2962' ,
99+ '.test@example.com' ,
100+ 'test.@example.com' ,
101+ 'te..st@example.com' ,
102+ '' ,
103+ 'johndoe' ,
104+ 'valid@example.com?asdf'
105+ ] . forEach ( invalidEmail => test ( invalidEmail , async ( ) => {
106+ const validator = await makeValidator ( schemaPath , schemaMap )
107+ const invalidJson = JSON . stringify ( {
108+ bomFormat : 'CycloneDX' ,
109+ specVersion : '1.7' ,
110+ metadata : { authors : [ { email : invalidEmail } ] }
111+ } )
112+ assert . notEqual ( validator ( invalidJson ) , null )
113+ } ) )
114+ )
70115} )
0 commit comments