Skip to content

Commit 3779054

Browse files
committed
test: add test cases for idn-email validation
Signed-off-by: Pasi Eronen <pe@iki.fi>
1 parent 4d3ab6f commit 3779054

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

tests/functional/internals/OpPlug.node.jsonValidator.spec.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)