Skip to content

Instantly share code, notes, and snippets.

@chilts
Last active August 29, 2015 13:57
Show Gist options
  • Save chilts/9676982 to your computer and use it in GitHub Desktop.
Save chilts/9676982 to your computer and use it in GitHub Desktop.
test(
'/account/create with a variety of malformed email addresses',
function (t) {
var pwd = '123456'
// See: http://en.wikipedia.org/wiki/Email_address#Valid_email_addresses
var emails = [
'notAnEmailAddress',
'\[email protected]',
'me@hello world.com',
'me@hello+world.com',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'A@b@[email protected]',
'a"b(c)d,e:f;g<h>i[j\k][email protected]',
'just"not"[email protected]',
'this is"not\[email protected]',
'this\ still\"not\\[email protected]',
// '[email protected]',
// '[email protected]',
]
emails.forEach(function(email, i) {
emails[i] = Client.create(config.publicUrl, email, pwd)
.then(
t.fail,
function (err) {
t.equal(err.code, 400, 'http 400 : malformed email is rejected')
}
)
})
return P.all(emails)
}
)
test(
'/account/create with a variety of unusual but valid email addresses',
function (t) {
var pwd = '123456'
// See: http://en.wikipedia.org/wiki/Email_address#Valid_email_addresses
var emails = [
'[email protected]',
'#[email protected]',
String.fromCharCode(1234) + '@example.com',
'test@' + String.fromCharCode(5678) + '.com',
'[email protected]',
'[email protected]',
'[email protected]',
// '"simple"@example.com',
// '"much.more unusual"@example.com',
// '"[email protected]"@example.com',
// '"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com',
'postbox@com',
'admin@mailserver1',
// ' !#$%&\'*+-/=?^_`{}|[email protected]',
// '"()<>[]:,;@\\\"!#$%&\'*+-/=?^_`{}| ~.a"@example.org',
// '" "@example.org',
'üñîçøðé@example.com',
'üñîçøðé@üñîçøðé.com',
]
emails.forEach(function(email, i) {
emails[i] = Client.create(config.publicUrl, email, pwd)
.then(
function(c) {
t.pass('Email ' + email + ' is valid')
return c.destroyAccount()
},
function (err) {
t.fail('Email address ' + email + " should have been allowed, but it wasn't")
}
)
})
return P.all(emails)
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment