2021-07-22 21:59:10 +02:00
|
|
|
|
using Bit.Core.Utilities;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace Bit.Core.Test.Utilities;
|
2022-08-29 22:06:55 +02:00
|
|
|
|
|
2021-07-22 21:59:10 +02:00
|
|
|
|
public class StrictEmailAttributeTests
|
|
|
|
|
{
|
2022-08-29 22:06:55 +02:00
|
|
|
|
[Theory]
|
2021-07-22 21:59:10 +02:00
|
|
|
|
[InlineData("hello@world.com")] // regular email address
|
|
|
|
|
[InlineData("hello@world.planet.com")] // subdomain
|
|
|
|
|
[InlineData("hello+1@world.com")] // alias
|
|
|
|
|
[InlineData("hello.there@world.com")] // period in local-part
|
|
|
|
|
[InlineData("hello@wörldé.com")] // unicode domain
|
2021-08-31 05:49:11 +02:00
|
|
|
|
[InlineData("hello@world.cömé")] // unicode top-level domain
|
2021-07-22 21:59:10 +02:00
|
|
|
|
public void IsValid_ReturnsTrueWhenValid(string email)
|
|
|
|
|
{
|
|
|
|
|
var sut = new StrictEmailAddressAttribute();
|
|
|
|
|
|
|
|
|
|
var actual = sut.IsValid(email);
|
2021-12-16 15:35:09 +01:00
|
|
|
|
|
2021-07-22 21:59:10 +02:00
|
|
|
|
Assert.True(actual);
|
|
|
|
|
}
|
2021-12-16 15:35:09 +01:00
|
|
|
|
|
2021-07-22 21:59:10 +02:00
|
|
|
|
[Theory]
|
2021-08-10 18:16:10 +02:00
|
|
|
|
[InlineData(null)] // null
|
|
|
|
|
[InlineData("hello@world.com\t")] // trailing tab char
|
|
|
|
|
[InlineData("\thello@world.com")] // leading tab char
|
|
|
|
|
[InlineData("hel\tlo@world.com")] // local-part tab char
|
|
|
|
|
[InlineData("hello@world.com\b")] // trailing backspace char
|
|
|
|
|
[InlineData("\" \"hello@world.com")] // leading spaces in quotes
|
|
|
|
|
[InlineData("hello@world.com\" \"")] // trailing spaces in quotes
|
|
|
|
|
[InlineData("hel\" \"lo@world.com")] // local-part spaces in quotes
|
|
|
|
|
[InlineData("hello there@world.com")] // unescaped unquoted spaces
|
|
|
|
|
[InlineData("Hello <hello@world.com>")] // friendly from
|
|
|
|
|
[InlineData("<hello@world.com>")] // wrapped angle brackets
|
|
|
|
|
[InlineData("hello(com)there@world.com")] // comment
|
|
|
|
|
[InlineData("hello@world.com.")] // trailing period
|
|
|
|
|
[InlineData(".hello@world.com")] // leading period
|
|
|
|
|
[InlineData("hello@world.com;")] // trailing semicolon
|
|
|
|
|
[InlineData(";hello@world.com")] // leading semicolon
|
2021-07-22 21:59:10 +02:00
|
|
|
|
[InlineData("hello@world.com; hello@world.com")] // semicolon separated list
|
|
|
|
|
[InlineData("hello@world.com, hello@world.com")] // comma separated list
|
2021-08-10 18:16:10 +02:00
|
|
|
|
[InlineData("hellothere@worldcom")] // dotless domain
|
|
|
|
|
[InlineData("hello.there@worldcom")] // dotless domain
|
|
|
|
|
[InlineData("hellothere@.worldcom")] // domain beginning with dot
|
|
|
|
|
[InlineData("hellothere@worldcom.")] // domain ending in dot
|
|
|
|
|
[InlineData("hellothere@world.com-")] // domain ending in hyphen
|
2022-06-23 00:51:16 +02:00
|
|
|
|
[InlineData("hellö@world.com")] // unicode at end of local-part
|
|
|
|
|
[InlineData("héllo@world.com")] // unicode in middle of local-part
|
2021-07-22 21:59:10 +02:00
|
|
|
|
public void IsValid_ReturnsFalseWhenInvalid(string email)
|
|
|
|
|
{
|
|
|
|
|
var sut = new StrictEmailAddressAttribute();
|
|
|
|
|
|
|
|
|
|
var actual = sut.IsValid(email);
|
2021-12-16 15:35:09 +01:00
|
|
|
|
|
2021-07-22 21:59:10 +02:00
|
|
|
|
Assert.False(actual);
|
|
|
|
|
}
|
|
|
|
|
}
|