@@ -67,4 +67,43 @@ 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+
74+ suite ( 'accepts valid emails' , ( ) =>
75+ [
76+ 'joe.bloggs@example.com' ,
77+ 'te~st@example.com' ,
78+ '~test@example.com' ,
79+ 'test~@example.com' ,
80+ 'te.s.t@example.com' ,
81+ '실례@실례.테스트'
82+ ] . forEach ( validEmail => test ( validEmail , async ( ) => {
83+ const validator = await makeValidator ( schemaPath , schemaMap )
84+ const validJson = JSON . stringify ( {
85+ bomFormat : 'CycloneDX' ,
86+ specVersion : '1.7' ,
87+ metadata : { authors : [ { email : validEmail } ] }
88+ } )
89+ assert . strictEqual ( validator ( validJson ) , null )
90+ } ) )
91+ )
92+
93+ suite ( 'rejects invalid emails' , ( ) =>
94+ [
95+ '2962' ,
96+ '.test@example.com' ,
97+ 'test.@example.com' ,
98+ 'te..st@example.com' ,
99+ ] . forEach ( invalidEmail => test ( invalidEmail , async ( ) => {
100+ const validator = await makeValidator ( schemaPath , schemaMap )
101+ const invalidJson = JSON . stringify ( {
102+ bomFormat : 'CycloneDX' ,
103+ specVersion : '1.7' ,
104+ metadata : { authors : [ { email : invalidEmail } ] }
105+ } )
106+ assert . notEqual ( validator ( invalidJson ) , null )
107+ } ) )
108+ )
70109} )
0 commit comments